Răsfoiți Sursa

add use_database_encryption for Brand

Marino Faggiana 6 ani în urmă
părinte
comite
454b4e7d64

+ 1 - 1
iOSClient/Brand/File_Provider_Extension.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<string>2.22.9</string>
 	<key>CFBundleVersion</key>
-	<string>4</string>
+	<string>5</string>
 	<key>NSExtension</key>
 	<dict>
 		<key>NSExtensionFileProviderDocumentGroup</key>

+ 6 - 1
iOSClient/Brand/NCBrand.swift

@@ -90,6 +90,10 @@ class NCBrandColor: NSObject {
     // Capabilities Group
     @objc public let capabilitiesGroups:                String = "group.it.twsweb.Crypto-Cloud"
     
+    // Database key encryption key 64byte AES-256+SHA2
+    @objc public var databaseEncryptionKey:             String = "LdFNb00N+ywBuNGJRjCUuDt1zIXK/PX82ZNHWochfu1is8TorIERQi1aJsAMLC3rK2BB0uMjh2kNZ9Dcwx/G5Q=="
+
+    
     // Options
     @objc public let use_login_web_personalized:        Bool = false                                                // Don't touch me !!
     @objc public let use_default_auto_upload:           Bool = false
@@ -98,7 +102,8 @@ class NCBrandColor: NSObject {
     @objc public let use_themingLogo:                   Bool = false     
     @objc public let use_middlewarePing:                Bool = false
     @objc public let use_storeLocalAutoUploadAll:       Bool = false
-    
+    @objc public let use_database_encryption:           Bool = false
+
     @objc public let disable_intro:                     Bool = false
     @objc public let disable_request_login_url:         Bool = false
     @objc public let disable_multiaccount:              Bool = false

+ 1 - 1
iOSClient/Brand/Notification_Service_Extension.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<string>2.22.9</string>
 	<key>CFBundleVersion</key>
-	<string>4</string>
+	<string>5</string>
 	<key>NSExtension</key>
 	<dict>
 		<key>NSExtensionPointIdentifier</key>

+ 1 - 1
iOSClient/Brand/Share.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<string>2.22.9</string>
 	<key>CFBundleVersion</key>
-	<string>4</string>
+	<string>5</string>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>

+ 1 - 1
iOSClient/Brand/iOSClient.plist

@@ -50,7 +50,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>4</string>
+	<string>5</string>
 	<key>FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED</key>
 	<true/>
 	<key>Fabric</key>

+ 17 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -34,7 +34,7 @@ class NCManageDatabase: NSObject {
         
         let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.sharedInstance.capabilitiesGroups)
         
-        let configCompact = Realm.Configuration(
+        var configCompact = Realm.Configuration(
             
             fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
             
@@ -47,6 +47,13 @@ class NCManageDatabase: NSObject {
             return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5
         })
         
+        // Encrypting the database file on disk with AES-256+SHA2 by supplying a 64-byte encryption key
+        if NCBrandOptions.sharedInstance.use_database_encryption {
+            if let keyData = Data(base64Encoded: NCBrandOptions.sharedInstance.databaseEncryptionKey) {
+                configCompact.encryptionKey = keyData
+            }
+        }
+        
         do {
             // Realm is compacted on the first open if the configuration block conditions were met.
             _ = try Realm(configuration: configCompact)
@@ -54,7 +61,7 @@ class NCManageDatabase: NSObject {
             // handle error compacting or opening Realm
         }
         
-        let config = Realm.Configuration(
+        var config = Realm.Configuration(
         
             fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
             schemaVersion: 41,
@@ -113,6 +120,14 @@ class NCManageDatabase: NSObject {
                 */
         })
 
+        
+        // Encrypting the database file on disk with AES-256+SHA2 by supplying a 64-byte encryption key
+        if NCBrandOptions.sharedInstance.use_database_encryption {
+            if let keyData = Data(base64Encoded: NCBrandOptions.sharedInstance.databaseEncryptionKey) {
+                config.encryptionKey = keyData
+            }
+        }
+        
         Realm.Configuration.defaultConfiguration = config
         _ = try! Realm()
     }