Browse Source

E2EE improvements

marinofaggiana 3 years ago
parent
commit
12da0d674e

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -2889,7 +2889,7 @@
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
 				kind = revision;
-				revision = 27566a376916cb75b93d48b35cca0462d190555a;
+				revision = b9c53399cda1adcdcbfb3318af7f89d2941f95ac;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 1 - 1
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -105,7 +105,7 @@
         "repositoryURL": "https://github.com/nextcloud/ios-communication-library/",
         "state": {
           "branch": null,
-          "revision": "27566a376916cb75b93d48b35cca0462d190555a",
+          "revision": "b9c53399cda1adcdcbfb3318af7f89d2941f95ac",
           "version": null
         }
       },

+ 6 - 6
iOSClient/Settings/NCEndToEndInitialize.swift

@@ -156,15 +156,15 @@ class NCEndToEndInitialize : NSObject  {
                     CCUtility.setEndToEndPrivateKey(self.appDelegate.account, privateKey: privateKey)
                     CCUtility.setEndToEndPassphrase(self.appDelegate.account, passphrase:passphrase)
                     
-                    // request publicKey Server()
-                    NCCommunication.shared.getE2EEServerPublicKey { (account, publicKey, errorCode, errorDescription) in
+                    // request server publicKey
+                    NCCommunication.shared.getE2EEPublicKey { (account, publicKey, errorCode, errorDescription) in
                         
                         if (errorCode == 0 && account == self.appDelegate.account) {
                             
                             //TODO: verifi if publicKey == NCCommunication.shared.getE2EEPublicKey
                             // + (NSString *)getEndToEndCertificate:(NSString *)account;
                             
-                            CCUtility.setEndToEndPublicKeyServer(account, publicKey: publicKey)
+                            CCUtility.setEndToEndPublicKey(account, publicKey: publicKey)
                             
                             // Clear Table
                             NCManageDatabase.shared.clearTable(tableDirectory.self, account: account)
@@ -239,15 +239,15 @@ class NCEndToEndInitialize : NSObject  {
                                 CCUtility.setEndToEndPrivateKey(account, privateKey: privateKeyString! as String)
                                 CCUtility.setEndToEndPassphrase(account, passphrase: e2ePassphrase)
                                 
-                                // request publicKey Server()
-                                NCCommunication.shared.getE2EEServerPublicKey { (account, publicKey, errorCode, errorDescription) in
+                                // request server publicKey
+                                NCCommunication.shared.getE2EEPublicKey { (account, publicKey, errorCode, errorDescription) in
                                     
                                     if (errorCode == 0 && account == self.appDelegate.account) {
                                         
                                         //TODO: verifi if publicKey == NCCommunication.shared.getE2EEPublicKey
                                         // + (NSString *)getEndToEndCertificate:(NSString *)account;
                                         
-                                        CCUtility.setEndToEndPublicKeyServer(account, publicKey: publicKey)
+                                        CCUtility.setEndToEndPublicKey(account, publicKey: publicKey)
                                         
                                         // Clear Table
                                         NCManageDatabase.shared.clearTable(tableDirectory.self, account: account)

+ 7 - 3
iOSClient/Utility/CCUtility.h

@@ -94,20 +94,24 @@
 + (BOOL)getFormatCompatibility;
 + (void)setFormatCompatibility:(BOOL)set;
 
+// E2EE
+
 + (NSString *)getEndToEndCertificate:(NSString *)account;
 + (void)setEndToEndCertificate:(NSString *)account certificate:(NSString *)certificate;
 
 + (NSString *)getEndToEndPrivateKey:(NSString *)account;
 + (void)setEndToEndPrivateKey:(NSString *)account privateKey:(NSString *)privateKey;
 
++ (NSString *)getEndToEndPublicKey:(NSString *)account;
++ (void)setEndToEndPublicKey:(NSString *)account publicKey:(NSString *)publicKey;
+
 + (NSString *)getEndToEndPassphrase:(NSString *)account;
 + (void)setEndToEndPassphrase:(NSString *)account passphrase:(NSString *)passphrase;
 
-+ (NSString *)getEndToEndPublicKeyServer:(NSString *)account;
-+ (void)setEndToEndPublicKeyServer:(NSString *)account publicKey:(NSString *)publicKey;
-
 + (BOOL)isEndToEndEnabled:(NSString *)account;
 
+// E2EE
+
 + (void)clearAllKeysEndToEnd:(NSString *)account;
 
 + (BOOL)getDisableFilesApp;

+ 14 - 14
iOSClient/Utility/CCUtility.m

@@ -320,28 +320,28 @@
     [UICKeyChainStore setString:privateKey forKey:key service:NCGlobal.shared.serviceShareKeyChain];
 }
 
-+ (NSString *)getEndToEndPassphrase:(NSString *)account
++ (NSString *)getEndToEndPublicKey:(NSString *)account
 {
-    NSString *key = [E2E_Passphrase stringByAppendingString:account];
+    NSString *key = [E2E_PublicKeyServer stringByAppendingString:account];
     return [UICKeyChainStore stringForKey:key service:NCGlobal.shared.serviceShareKeyChain];
 }
 
-+ (void)setEndToEndPassphrase:(NSString *)account passphrase:(NSString *)passphrase
++ (void)setEndToEndPublicKey:(NSString *)account publicKey:(NSString *)publicKey
 {
-    NSString *key = [E2E_Passphrase stringByAppendingString:account];
-    [UICKeyChainStore setString:passphrase forKey:key service:NCGlobal.shared.serviceShareKeyChain];
+    NSString *key = [E2E_PublicKeyServer stringByAppendingString:account];
+    [UICKeyChainStore setString:publicKey forKey:key service:NCGlobal.shared.serviceShareKeyChain];
 }
 
-+ (NSString *)getEndToEndPublicKeyServer:(NSString *)account
++ (NSString *)getEndToEndPassphrase:(NSString *)account
 {
-    NSString *key = [E2E_PublicKeyServer stringByAppendingString:account];
+    NSString *key = [E2E_Passphrase stringByAppendingString:account];
     return [UICKeyChainStore stringForKey:key service:NCGlobal.shared.serviceShareKeyChain];
 }
 
-+ (void)setEndToEndPublicKeyServer:(NSString *)account publicKey:(NSString *)publicKey
++ (void)setEndToEndPassphrase:(NSString *)account passphrase:(NSString *)passphrase
 {
-    NSString *key = [E2E_PublicKeyServer stringByAppendingString:account];
-    [UICKeyChainStore setString:publicKey forKey:key service:NCGlobal.shared.serviceShareKeyChain];
+    NSString *key = [E2E_Passphrase stringByAppendingString:account];
+    [UICKeyChainStore setString:passphrase forKey:key service:NCGlobal.shared.serviceShareKeyChain];
 }
 
 + (BOOL)isEndToEndEnabled:(NSString *)account
@@ -349,12 +349,12 @@
     BOOL isE2EEEnabled = [[NCManageDatabase shared] getCapabilitiesServerBoolWithAccount:account elements:NCElementsJSON.shared.capabilitiesE2EEEnabled exists:false];
     NSString* versionE2EE = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:account elements:NCElementsJSON.shared.capabilitiesE2EEApiVersion];
     
-    NSString *publicKey = [self getEndToEndCertificate:account];
+    NSString *certificate = [self getEndToEndCertificate:account];
+    NSString *publicKey = [self getEndToEndPublicKey:account];
     NSString *privateKey = [self getEndToEndPrivateKey:account];
     NSString *passphrase = [self getEndToEndPassphrase:account];
-    NSString *publicKeyServer = [self getEndToEndPublicKeyServer:account];    
             
-    if (passphrase.length > 0 && privateKey.length > 0 && publicKey.length > 0 && publicKeyServer.length > 0 && isE2EEEnabled && [versionE2EE isEqual:[[NCGlobal shared] e2eeVersion]]) {
+    if (passphrase.length > 0 && privateKey.length > 0 && certificate.length > 0 && publicKey.length > 0 && isE2EEEnabled && [versionE2EE isEqual:[[NCGlobal shared] e2eeVersion]]) {
        
         return YES;
         
@@ -368,8 +368,8 @@
 {
     [self setEndToEndCertificate:account certificate:nil];
     [self setEndToEndPrivateKey:account privateKey:nil];
+    [self setEndToEndPublicKey:account publicKey:nil];
     [self setEndToEndPassphrase:account passphrase:nil];
-    [self setEndToEndPublicKeyServer:account publicKey:nil];
 }
 
 + (BOOL)getDisableFilesApp