浏览代码

clear code

Marino Faggiana 7 年之前
父节点
当前提交
cb25e18865

+ 6 - 6
Nextcloud.xcodeproj/project.pbxproj

@@ -98,9 +98,6 @@
 		F70A630B1D5B3467004E2AA5 /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F70A63061D5B3467004E2AA5 /* libcrypto.a */; };
 		F70A630F1D5B3467004E2AA5 /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F70A63071D5B3467004E2AA5 /* libssl.a */; };
 		F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
-		F70CAE3B1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
-		F70CAE3C1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
-		F70CAE3D1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
 		F710E8101EF95C9C00DC2427 /* CCIntro.m in Sources */ = {isa = PBXBuildFile; fileRef = F710E80E1EF95C9C00DC2427 /* CCIntro.m */; };
 		F710E8111EF95C9C00DC2427 /* ImagesIntro.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F710E80F1EF95C9C00DC2427 /* ImagesIntro.xcassets */; };
 		F71459B81D12E3B700CAFEEC /* CCError.m in Sources */ = {isa = PBXBuildFile; fileRef = F76C3B881C638A4C00DC4301 /* CCError.m */; };
@@ -358,6 +355,9 @@
 		F780710A1EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */; };
 		F780710B1EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */; };
 		F78071211EDB135100EAFFF6 /* CCPhotos.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071201EDB135100EAFFF6 /* CCPhotos.m */; };
+		F782952F1F962EF900A572F5 /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
+		F78295301F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
+		F78295311F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
 		F78964AD1EBB576C00403E13 /* JDStatusBarNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = F78964A81EBB576C00403E13 /* JDStatusBarNotification.m */; };
 		F78964AE1EBB576C00403E13 /* JDStatusBarStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = F78964AA1EBB576C00403E13 /* JDStatusBarStyle.m */; };
 		F78964AF1EBB576C00403E13 /* JDStatusBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = F78964AC1EBB576C00403E13 /* JDStatusBarView.m */; };
@@ -3437,6 +3437,7 @@
 				F70022B71EC4C9100080073F /* OCCapabilities.m in Sources */,
 				F734E5891F019D860060CB77 /* UIScrollView+EmptyDataSet.m in Sources */,
 				F70022FF1EC4C9100080073F /* UtilsFramework.m in Sources */,
+				F78295311F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */,
 				F70022BA1EC4C9100080073F /* OCCommunication.m in Sources */,
 				F70022ED1EC4C9100080073F /* OCXMLSharedParser.m in Sources */,
 				F70022D51EC4C9100080073F /* NSDate+ISO8601.m in Sources */,
@@ -3479,7 +3480,6 @@
 				F76B3CCF1EAE01BD00921AC9 /* NCBrand.swift in Sources */,
 				F73CC0761E813DFF006E3047 /* BKPasscodeViewController.m in Sources */,
 				F70022D21EC4C9100080073F /* OCUserProfile.m in Sources */,
-				F70CAE3B1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				F70022C61EC4C9100080073F /* OCNotificationsAction.m in Sources */,
 				F7BAADCC1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */,
 				F70022DE1EC4C9100080073F /* OCWebDAVClient.m in Sources */,
@@ -3528,6 +3528,7 @@
 				F77EB6291EC08037003F814F /* CCExifGeo.m in Sources */,
 				F70022CD1EC4C9100080073F /* OCSharedDto.m in Sources */,
 				F70022AC1EC4C9100080073F /* AFURLRequestSerialization.m in Sources */,
+				F78295301F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */,
 				F780710B1EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */,
 				F70022FD1EC4C9100080073F /* NSString+Encode.m in Sources */,
 				F70022B51EC4C9100080073F /* OCActivity.m in Sources */,
@@ -3541,7 +3542,6 @@
 				F74344881E127F9C001CC831 /* UIImage+animatedGIF.m in Sources */,
 				F73CC0771E813DFF006E3047 /* BKPasscodeViewController.m in Sources */,
 				F70022DF1EC4C9100080073F /* OCWebDAVClient.m in Sources */,
-				F70CAE3C1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				F743448A1E127FF2001CC831 /* CCHud.m in Sources */,
 				F734E5921F019D870060CB77 /* UIScrollView+EmptyDataSet.m in Sources */,
 				F73CC06B1E813DFF006E3047 /* BKPasscodeDummyViewController.m in Sources */,
@@ -3559,7 +3559,6 @@
 			files = (
 				F7BB50D91F2238A300C47094 /* OCXMLParser.m in Sources */,
 				F7BB50D11F22388900C47094 /* OCSharedDto.m in Sources */,
-				F70CAE3D1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				F7BB50CB1F22386900C47094 /* OCCommunication.m in Sources */,
 				F7BB50D31F22388E00C47094 /* OCUserProfile.m in Sources */,
 				F7BB50BF1F22378800C47094 /* CCExifGeo.m in Sources */,
@@ -3608,6 +3607,7 @@
 				F7BB50F41F2239B600C47094 /* BKPasscodeDummyViewController.m in Sources */,
 				F7BB50C41F22379800C47094 /* NSString+TruncateToWidth.m in Sources */,
 				F7BB50E31F2238D200C47094 /* AFURLResponseSerialization.m in Sources */,
+				F782952F1F962EF900A572F5 /* NCEndToEndEncryption.m in Sources */,
 				F7BB50EB1F22391000C47094 /* MBProgressHUD.m in Sources */,
 				F7BB50D21F22388B00C47094 /* OCShareUser.m in Sources */,
 				F7BB50F31F22396300C47094 /* UIImage+animatedGIF.m in Sources */,

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.h

@@ -904,7 +904,7 @@ typedef enum {
 
 - (void)getEndToEndPublicKeys:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *publicKey, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
-- (void)getEndToEndPrivateKeyCipher:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *privateKey, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+- (void)getEndToEndPrivateKeyCipher:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *privateKeyChiper, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
 - (void)getEndToEndServerPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *publicKey, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 

+ 4 - 4
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -2012,7 +2012,7 @@
     }];
 }
 
-- (void)getEndToEndPrivateKeyCipher:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *privateKey, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+- (void)getEndToEndPrivateKeyCipher:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *privateKeyChiper, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
     
     serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
     serverPath = [serverPath stringByAppendingString:@"/private-key"];
@@ -2024,7 +2024,7 @@
     [request getEndToEndPrivateKeyCipher:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
         
         NSData *responseData = (NSData*) responseObject;
-        NSString *privateKey;
+        NSString *privateKeyChiper;
         
         //Parse
         NSError *error;
@@ -2042,7 +2042,7 @@
             if (statusCode == kOCUserProfileAPISuccessful) {
                 
                 if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]])
-                    privateKey = [data valueForKey:@"private-key"];
+                    privateKeyChiper = [data valueForKey:@"private-key"];
                 
             } else {
                 
@@ -2058,7 +2058,7 @@
         }
         
         //Return success
-        successRequest(response, privateKey, request.redirectedServer);
+        successRequest(response, privateKeyChiper, request.redirectedServer);
         
     } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
         

+ 16 - 44
iOSClient/Main/CCMain.m

@@ -88,9 +88,6 @@
     CCLogin *_loginVC;
     
     BOOL _loadingFolder;
-    
-    //E2E
-    NSString *publicKey, *privateKeyChiper, *publicKeyServer, *mnemonic;
 }
 @end
 
@@ -1243,11 +1240,6 @@
 
 - (void)initEndToEnd
 {
-    // clear keys
-    publicKey = nil;
-    privateKeyChiper = nil;
-    publicKeyServer = nil;
-    
     // request keys to server
     CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
 
@@ -1265,13 +1257,6 @@
 
 - (void)getEndToEndPublicKeysSuccess:(CCMetadataNet *)metadataNet
 {
-    // Remove CSR to Disk
-    [[NCEndToEndEncryption sharedManager] removeCSRToDisk:app.directoryUser];
-    
-    // Verify KeyPair on server
-    publicKey = metadataNet.options;
-    [[NCEndToEndEncryption sharedManager] verifyKeyPairOnServerWithPublicKey:publicKey privateKeyCipher:privateKeyChiper publicKeyServer:publicKeyServer viewController:self];
-    
     // Activity
     [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionEndToEndEncryption selector:metadataNet.selector note:@"EndToEndPublicKeys present on Server" type:k_activityTypeSuccess verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
 }
@@ -1285,16 +1270,16 @@
             break;
         case 404: {
             // remove keychain
-            [CCUtility setEndToEndPublicKeySign:app.activeAccount set:NO];
+            [CCUtility setEndToEndPublicKeySign:app.activeAccount publicKey:nil];
             
             CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
             
-            NSString *publicKeyEncoded = [[NCEndToEndEncryption sharedManager] createEndToEndPublicKey:app.activeUserID directoryUser:app.directoryUser];
+            NSString *publicKey = [[NCEndToEndEncryption sharedManager] createEndToEndPublicKey:app.activeUserID directoryUser:app.directoryUser];
             
-            if (publicKeyEncoded) {
+            if (publicKey) {
                 
                 metadataNet.action = actionSignEndToEndPublicKey;
-                metadataNet.options = publicKeyEncoded;
+                metadataNet.key = publicKey;
                 
                 [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
                 
@@ -1321,11 +1306,11 @@
 
 - (void)signEndToEndPublicKeySuccess:(CCMetadataNet *)metadataNet
 {
-    // Remove CSR
-    [[NCEndToEndEncryption sharedManager] removeCSRToDisk:app.directoryUser];
+    // Insert CSR To Cheychain end delete
+    NSString *publicKey = [[NCEndToEndEncryption sharedManager] getCSRFromDisk:app.directoryUser delete:YES];
     
     // OK signed key locally keychain
-    [CCUtility setEndToEndPublicKeySign:app.activeAccount set:YES];
+    [CCUtility setEndToEndPublicKeySign:app.activeAccount publicKey:publicKey];
     
     // Activity
     [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionEndToEndEncryption selector:metadataNet.selector note:@"EndToEndPublicKey sign on Server and stored locally" type:k_activityTypeSuccess verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
@@ -1345,9 +1330,6 @@
 
 - (void)deleteEndToEndPublicKeySuccess:(CCMetadataNet *)metadataNet
 {
-    // Remove CSR
-    [[NCEndToEndEncryption sharedManager] removeCSRToDisk:app.directoryUser];
-    
     [app messageNotification:@"E2E delete public key" description:@"Public key was deleted" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:0];
 }
 
@@ -1360,12 +1342,8 @@
 
 - (void)getEndToEndPrivateKeyCipherSuccess:(CCMetadataNet *)metadataNet
 {
-    // Remove PrivateKey to Disk
-    [[NCEndToEndEncryption sharedManager] removePrivateKeyToDisk:app.directoryUser];
-    
     // Verify KeyPair on server
-    privateKeyChiper = metadataNet.options;
-    [[NCEndToEndEncryption sharedManager] verifyKeyPairOnServerWithPublicKey:publicKey privateKeyCipher:privateKeyChiper publicKeyServer:publicKeyServer viewController:self];
+    NSString *privateKey = [[NCEndToEndEncryption sharedManager] decryptPrivateKeyCipher:metadataNet.key viewController:self];
 
     // Activity
     [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionEndToEndEncryption selector:metadataNet.selector note:@"EndToEndPrivateKey present on Server" type:k_activityTypeSuccess verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
@@ -1380,20 +1358,20 @@
             break;
         case 404: {
             // remove keychain
-            [CCUtility setEndToEndPrivateKeyCipher:app.activeAccount set:NO];
+            [CCUtility setEndToEndPrivateKey:app.activeAccount privateKey:nil];
             [CCUtility setEndToEndMnemonic:app.activeAccount mnemonic:nil];
             
             NSString *mnemonic = [[NYMnemonic generateMnemonicString:@128 language:@"english"] stringByReplacingOccurrencesOfString:@" " withString:@""];
             mnemonic = k_Mnemonic_test;
             
-            NSString *privateKeyCipher = [[NCEndToEndEncryption sharedManager] createEndToEndPrivateKey:app.activeUserID directoryUser:app.directoryUser mnemonic:mnemonic];
+            NSString *privateKeyChiper = [[NCEndToEndEncryption sharedManager] createEndToEndPrivateKey:app.activeUserID directoryUser:app.directoryUser mnemonic:mnemonic];
             
-            if (privateKeyCipher) {
+            if (privateKeyChiper) {
                 
                 CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
 
                 metadataNet.action = actionStoreEndToEndPrivateKeyCipher;
-                metadataNet.options = privateKeyCipher;
+                metadataNet.key = privateKeyChiper;
                 metadataNet.password = mnemonic;
                 
                 [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
@@ -1421,11 +1399,12 @@
 
 - (void)storeEndToEndPrivateKeyCipherSuccess:(CCMetadataNet *)metadataNet
 {
-    // Remove PrivateKey
-    [[NCEndToEndEncryption sharedManager] removePrivateKeyToDisk:app.directoryUser];
+    // Insert PrivateKey To Cheychain end delete
+    NSString *privateKey = [[NCEndToEndEncryption sharedManager] getPrivateKeyFromDisk:app.directoryUser delete:YES];
     
     // OK privatekey locally keychain
-    [CCUtility setEndToEndPrivateKeyCipher:app.activeAccount set:YES];
+    [CCUtility setEndToEndPrivateKey:app.activeAccount privateKey:privateKey];
+    
     // Strore mnemonic locally keychain
     [CCUtility setEndToEndMnemonic:app.activeAccount mnemonic:metadataNet.password];
     
@@ -1447,9 +1426,6 @@
 
 - (void)deleteEndToEndPrivateKeySuccess:(CCMetadataNet *)metadataNet
 {
-    // Remove PrivateKey
-    [[NCEndToEndEncryption sharedManager] removePrivateKeyToDisk:app.directoryUser];
-    
     [app messageNotification:@"E2E delete private key" description:@"Private key was deleted" visible:YES delay:1 type:TWMessageBarMessageTypeSuccess errorCode:0];
 }
 
@@ -1462,10 +1438,6 @@
 
 - (void)getEndToEndServerPublicKeySuccess:(CCMetadataNet *)metadataNet
 {
-    // Verify KeyPair on server
-    publicKeyServer = metadataNet.options;
-    [[NCEndToEndEncryption sharedManager] verifyKeyPairOnServerWithPublicKey:publicKey privateKeyCipher:privateKeyChiper publicKeyServer:publicKeyServer viewController:self];
-
     // Activity
     [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionEndToEndEncryption selector:metadataNet.selector note:@"EndToEndServerPublicKey present on Server" type:k_activityTypeSuccess verbose:k_activityVerboseHigh activeUrl:app.activeUrl];
 }

+ 2 - 1
iOSClient/Networking/CCNetworking.h

@@ -93,6 +93,7 @@
 
 @property (nonatomic, strong) NSString *account;
 @property (nonatomic, strong) NSString *action;
+@property (nonatomic, strong) NSString *assetLocalIdentifier;
 @property (nonatomic, strong) NSDate *date;
 @property (nonatomic, weak) id delegate;
 @property (nonatomic, strong) NSString *depth;
@@ -106,7 +107,7 @@
 @property (nonatomic, strong) NSString *fileID;
 @property (nonatomic, strong) NSString *fileName;
 @property (nonatomic, strong) NSString *fileNameTo;
-@property (nonatomic, strong) NSString *assetLocalIdentifier;
+@property (nonatomic, strong) NSString *key;
 @property (nonatomic, strong) id options;
 @property (nonatomic, strong) NSString *password;
 @property (nonatomic, strong) NSString *pathFolder;

+ 1 - 0
iOSClient/Networking/CCNetworking.m

@@ -1548,6 +1548,7 @@
     [metadataNet setFileID: self.fileID];
     [metadataNet setFileName: self.fileName];
     [metadataNet setFileNameTo: self.fileNameTo];
+    [metadataNet setKey: self.key];
     [metadataNet setOptions: self.options];
     [metadataNet setPassword: self.password];
     [metadataNet setPathFolder: self.pathFolder];

+ 6 - 6
iOSClient/Networking/OCNetworking.m

@@ -1680,7 +1680,7 @@
     [communication getEndToEndPublicKeys:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *publicKey, NSString *redirectedServer) {
         
         // 200 ok: body contain the public key
-        _metadataNet.options = publicKey;
+        _metadataNet.key = publicKey;
 
         if ([self.delegate respondsToSelector:@selector(getEndToEndPublicKeysSuccess:)])
             [self.delegate getEndToEndPublicKeysSuccess:_metadataNet];
@@ -1712,10 +1712,10 @@
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    [communication getEndToEndPrivateKeyCipher:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *privateKey, NSString *redirectedServer) {
+    [communication getEndToEndPrivateKeyCipher:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *privateKeyChiper, NSString *redirectedServer) {
         
         // 200 ok: body contain the private key
-        _metadataNet.options = privateKey;
+        _metadataNet.key = privateKeyChiper;
         
         if ([self.delegate respondsToSelector:@selector(getEndToEndPrivateKeyCipherSuccess:)])
             [self.delegate getEndToEndPrivateKeyCipherSuccess:_metadataNet];
@@ -1745,7 +1745,7 @@
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
     // URL Encode
-    NSString *publicKey = [CCUtility URLEncodeStringFromString:_metadataNet.options];
+    NSString *publicKey = [CCUtility URLEncodeStringFromString:_metadataNet.key];
 
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
@@ -1782,7 +1782,7 @@
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
     // URL Encode
-    NSString *privateKeyChiper = [CCUtility URLEncodeStringFromString:_metadataNet.options];
+    NSString *privateKeyChiper = [CCUtility URLEncodeStringFromString:_metadataNet.key];
     
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
@@ -1892,7 +1892,7 @@
     [communication getEndToEndServerPublicKey:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *publicKey, NSString *redirectedServer) {
         
         // 200 ok: body contain the public key
-        _metadataNet.options = publicKey;
+        _metadataNet.key = publicKey;
         
         if ([self.delegate respondsToSelector:@selector(getEndToEndServerPublicKeySuccess:)])
             [self.delegate getEndToEndServerPublicKeySuccess:_metadataNet];

+ 4 - 3
iOSClient/Security/NCEndToEndEncryption.h

@@ -36,9 +36,10 @@
 
 - (NSString *)createEndToEndPublicKey:(NSString *)userID directoryUser:(NSString *)directoryUser;
 - (NSString *)createEndToEndPrivateKey:(NSString *)userID directoryUser: (NSString *)directoryUser mnemonic:(NSString *)mnemonic;
-- (void)verifyKeyPairOnServerWithPublicKey:(NSString *)publicKey privateKeyCipher:(NSString *)privateKeyCipher publicKeyServer:(NSString *)publicKeyServer viewController:(UIViewController *)viewController;
 
-- (void)removeCSRToDisk:(NSString *)directoryUser;
-- (void)removePrivateKeyToDisk:(NSString *)directoryUser;
+- (NSString *)decryptPrivateKeyCipher:(NSString *)privateKeyCipher viewController:(UIViewController *)viewController;
+
+- (NSString *)getCSRFromDisk:(NSString *)directoryUser delete:(BOOL)delete;
+- (NSString *)getPrivateKeyFromDisk:(NSString *)directoryUser delete:(BOOL)delete;
 
 @end

+ 44 - 43
iOSClient/Security/NCEndToEndEncryption.m

@@ -255,9 +255,6 @@ cleanup:
 
 - (NSString *)createEndToEndPublicKey:(NSString *)userID directoryUser:(NSString *)directoryUser
 {
-    NSString *csr;
-    NSError *error;
-
     // Create Certificate, if do not exists
     if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNameCSR]]) {
         
@@ -265,19 +262,14 @@ cleanup:
             return nil;
     }
     
-    csr = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNameCSR] encoding:NSUTF8StringEncoding error:&error];
-
-    if (error)
-        return nil;
+    NSString *publicKey = [self getCSRFromDisk:directoryUser delete:NO];
     
-    return csr;
+    return publicKey;
 }
 
 - (NSString *)createEndToEndPrivateKey:(NSString *)userID directoryUser: (NSString *)directoryUser mnemonic:(NSString *)mnemonic
 {
-    NSMutableData *privateKeyCipherData;
-    NSString *privateKeyCipherBase64;
-    NSString *privateKeyCipherWithInitVector;
+    NSMutableData *privateKeyCipherData = [NSMutableData new];
 
     // Create Certificate, if do not exists
     if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNamePrivateKey]]) {
@@ -296,62 +288,66 @@ cleanup:
 
     BOOL result = [self aes256gcmEncrypt:privateKeyData cipherData:&privateKeyCipherData keyData:keyData initVectorData:initVectorData tagData:nil];
     
-    // TEST
-    NSMutableData *plainData;
-    result = [self aes256gcmDecrypt:privateKeyCipherData plainData:&plainData keyData:keyData initVectorData:initVectorData tag:nil];
-    NSString *privateKeyPlainData = [[NSString alloc] initWithData:plainData encoding:NSUTF8StringEncoding];
-    NSLog(@"%@", privateKeyPlainData);
-    // TEST
-    
     if (result && privateKeyCipherData) {
         
+        NSString *privateKeyCipherBase64;
+        NSString *initVectorBase64;
+        NSString *privateKeyCipherWithInitVectorBase64;
+
         privateKeyCipherBase64 = [privateKeyCipherData base64EncodedStringWithOptions:0];
-        NSString *initVectorBase64 = [initVectorData base64EncodedStringWithOptions:0];
-        privateKeyCipherWithInitVector = [NSString stringWithFormat:@"%@%@%@", privateKeyCipherBase64, IV_DELIMITER_ENCODED, initVectorBase64];
+        initVectorBase64 = [initVectorData base64EncodedStringWithOptions:0];
+        privateKeyCipherWithInitVectorBase64 = [NSString stringWithFormat:@"%@%@%@", privateKeyCipherBase64, IV_DELIMITER_ENCODED, initVectorBase64];
         
-        // TEST
-        NSMutableData *plainData;
-        NSData *privateKeyCipherData = [[NSData alloc] initWithBase64EncodedString:privateKeyCipherBase64 options:0];
-        NSData *initVectorData = [[NSData alloc] initWithBase64EncodedString:initVectorBase64 options:0];
-        result = [self aes256gcmDecrypt:privateKeyCipherData plainData:&plainData keyData:keyData initVectorData:initVectorData tag:nil];
-        NSLog(@"%@", privateKeyPlainData);
-        // TEST
+        return privateKeyCipherWithInitVectorBase64;
         
     } else {
         
         return nil;
     }
-    
-    return privateKeyCipherWithInitVector;
 }
 
-- (void)removeCSRToDisk:(NSString *)directoryUser
+- (NSString *)getCSRFromDisk:(NSString *)directoryUser delete:(BOOL)delete
 {
-    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNameCSR] error:nil];
+    NSError *error;
+
+    NSString *publicKey = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNameCSR] encoding:NSUTF8StringEncoding error:&error];
+
+    if (delete)
+        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNameCSR] error:nil];
+    
+    if (error)
+        return nil;
+    else
+        return publicKey;
 }
 
-- (void)removePrivateKeyToDisk:(NSString *)directoryUser
+- (NSString *)getPrivateKeyFromDisk:(NSString *)directoryUser delete:(BOOL)delete
 {
-    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNamePrivateKey] error:nil];
+    NSError *error;
+    
+    NSString *privateKey = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNamePrivateKey] encoding:NSUTF8StringEncoding error:&error];
+    
+    if (delete)
+        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileNamePrivateKey] error:nil];
+    
+    if (error)
+        return nil;
+    else
+        return privateKey;
 }
 
 #
 #pragma mark - Register client for Server with exists Key pair
 #
 
-- (void)verifyKeyPairOnServerWithPublicKey:(NSString *)publicKey privateKeyCipher:(NSString *)privateKeyCipher publicKeyServer:(NSString *)publicKeyServer viewController:(UIViewController *)viewController
+- (NSString *)decryptPrivateKeyCipher:(NSString *)privateKeyCipher viewController:(UIViewController *)viewController
 {
-    // verify is all the keys and mnemonic are available
-    if (publicKey.length == 0 || privateKeyCipher.length == 0 || publicKeyServer.length == 0)
-        return;
-    
     NSMutableData *privateKeyData = [NSMutableData new];
-    NSString *privateKeyCipherBase64;
     
     // mnemonic
     NSString *mnemonic = k_Mnemonic_test;
     
-    // Key
+    // Key (data)
     NSMutableData *keyData = [NSMutableData dataWithLength:PBKDF2_KEY_LENGTH];
     NSData *saltData = [PBKDF2_SALT dataUsingEncoding:NSUTF8StringEncoding];
     CCKeyDerivationPBKDF(kCCPBKDF2, mnemonic.UTF8String, mnemonic.length, saltData.bytes, saltData.length, kCCPRFHmacAlgSHA1, PBKDF2_INTERACTION_COUNT, keyData.mutableBytes, keyData.length);
@@ -361,7 +357,7 @@ cleanup:
     NSInteger idx = range.location + range.length;
     
     // PrivateKey
-    privateKeyCipherBase64 = [privateKeyCipher substringToIndex:range.location];
+    NSString *privateKeyCipherBase64 = [privateKeyCipher substringToIndex:range.location];
     NSData *privateKeyCipherData = [[NSData alloc] initWithBase64EncodedString:privateKeyCipherBase64 options:0];
 
     // Init Vector
@@ -371,8 +367,13 @@ cleanup:
     BOOL result = [self aes256gcmDecrypt:privateKeyCipherData plainData:&privateKeyData keyData:keyData initVectorData:initVectorData tag:nil];
     
     if (result && privateKeyData) {
-        NSString *convertedString = [[NSString alloc] initWithData:privateKeyData encoding:NSUTF8StringEncoding];
-        NSLog(@"%@", convertedString);
+        
+        NSString *privateKey = [[NSString alloc] initWithData:privateKeyData encoding:NSUTF8StringEncoding];
+        return privateKey;
+        
+    } else {
+        
+        return nil;
     }
 }
 

+ 4 - 4
iOSClient/Utility/CCUtility.h

@@ -91,8 +91,8 @@
 
 + (void)setShowHiddenFiles:(BOOL)show;
 
-+ (void)setEndToEndPublicKeySign:(NSString *)account set:(BOOL)set;
-+ (void)setEndToEndPrivateKeyCipher:(NSString *)account set:(BOOL)set;
++ (void)setEndToEndPublicKeySign:(NSString *)account publicKey:(NSString *)publicKey;
++ (void)setEndToEndPrivateKey:(NSString *)account privateKey:(NSString *)privateKey;
 + (void)setEndToEndMnemonic:(NSString *)account mnemonic:(NSString *)mnemonic;
 + (void)initEndToEnd:(NSString *)account;
 
@@ -141,8 +141,8 @@
 
 + (BOOL)getShowHiddenFiles;
 
-+ (BOOL)getEndToEndPublicKeySign:(NSString *)account;
-+ (BOOL)getEndToEndPrivateKeyCipher:(NSString *)account;
++ (NSString *)getEndToEndPublicKeySign:(NSString *)account;
++ (NSString *)getEndToEndPrivateKey:(NSString *)account;
 + (NSString *)getEndToEndMnemonic:(NSString *)account;
 + (BOOL)isEndToEndEnabled:(NSString *)account;
 

+ 13 - 17
iOSClient/Utility/CCUtility.m

@@ -231,20 +231,16 @@
     [UICKeyChainStore setString:sShow forKey:@"showHiddenFiles" service:k_serviceShareKeyChain];
 }
 
-+ (void)setEndToEndPublicKeySign:(NSString *)account set:(BOOL)set
++ (void)setEndToEndPublicKeySign:(NSString *)account publicKey:(NSString *)publicKey
 {
     NSString *key = [E2E_PublicKeySign stringByAppendingString:account];
-    NSString *sSet = (set) ? @"true" : @"false";
-
-    [UICKeyChainStore setString:sSet forKey:key service:k_serviceShareKeyChain];
+    [UICKeyChainStore setString:publicKey forKey:key service:k_serviceShareKeyChain];
 }
 
-+ (void)setEndToEndPrivateKeyCipher:(NSString *)account set:(BOOL)set
++ (void)setEndToEndPrivateKey:(NSString *)account privateKey:(NSString *)privateKey
 {
     NSString *key = [E2E_PrivateKeyCipher stringByAppendingString:account];
-    NSString *sSet = (set) ? @"true" : @"false";
-    
-    [UICKeyChainStore setString:sSet forKey:key service:k_serviceShareKeyChain];
+    [UICKeyChainStore setString:privateKey forKey:key service:k_serviceShareKeyChain];
 }
 
 + (void)setEndToEndMnemonic:(NSString *)account mnemonic:(NSString *)mnemonic
@@ -255,8 +251,8 @@
 
 + (void)initEndToEnd:(NSString *)account
 {
-    [self setEndToEndPublicKeySign:account set:NO];
-    [self setEndToEndPrivateKeyCipher:account set:NO];
+    [self setEndToEndPublicKeySign:account publicKey:nil];
+    [self setEndToEndPrivateKey:account privateKey:nil];
     [self setEndToEndMnemonic:account mnemonic:nil];
 }
 
@@ -456,16 +452,16 @@
     return [[UICKeyChainStore stringForKey:@"showHiddenFiles" service:k_serviceShareKeyChain] boolValue];
 }
 
-+ (BOOL)getEndToEndPublicKeySign:(NSString *)account
++ (NSString *)getEndToEndPublicKeySign:(NSString *)account
 {
     NSString *key = [E2E_PublicKeySign stringByAppendingString:account];
-    return [[UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain] boolValue];
+    return [UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain];
 }
 
-+ (BOOL)getEndToEndPrivateKeyCipher:(NSString *)account
++ (NSString *)getEndToEndPrivateKey:(NSString *)account
 {
     NSString *key = [E2E_PrivateKeyCipher stringByAppendingString:account];
-    return [[UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain] boolValue];
+    return [UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain];
 }
 
 + (NSString *)getEndToEndMnemonic:(NSString *)account
@@ -476,11 +472,11 @@
 
 + (BOOL)isEndToEndEnabled:(NSString *)account
 {
-    BOOL publicKeySign = [self getEndToEndPublicKeySign:account];
+    NSString *publicKeySign = [self getEndToEndPublicKeySign:account];
+    NSString *privateKey = [self getEndToEndPrivateKey:account];
     NSString *mnemonic = [self getEndToEndMnemonic:account];
-    BOOL privateKeyChiper = [self getEndToEndPrivateKeyCipher:account];
     
-    if (mnemonic.length > 0 && privateKeyChiper && publicKeySign) {
+    if (mnemonic.length > 0 && privateKey.length > 0 && publicKeySign.length > 0) {
         
         return YES;