Browse Source

add e2ePassphrase

Marino Faggiana 7 years ago
parent
commit
7fa0890973

+ 3 - 0
iOSClient/AppDelegate.h

@@ -124,6 +124,9 @@
 @property (nonatomic, strong) NSMutableDictionary *listMainVC;
 @property (nonatomic, strong) NSMutableDictionary *listProgressMetadata;
 
+// E2E Encryption passphrase
+@property (nonatomic, strong) NSString *e2ePassphrase;
+
 // Maintenance Mode
 @property BOOL maintenanceMode;
 

+ 2 - 1
iOSClient/AppDelegate.m

@@ -222,7 +222,8 @@
     UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
     [application registerUserNotificationSettings:notificationSettings];
     
-    // NCEntoToEndInterface
+    // E2E Encryption
+    self.e2ePassphrase = nil;
     self.endToEndInterface = [NCEntoToEndInterface new];
     
     // Fabric

+ 4 - 6
iOSClient/Security/NCEntoToEndInterface.swift

@@ -158,7 +158,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
     
     func getEndToEndPrivateKeyCipherSuccess(_ metadataNet: CCMetadataNet!) {
         
-        guard let privateKey = NCEndToEndEncryption.sharedManager().decryptPrivateKeyCipher(metadataNet.key, passphrase: k_passphrase_test) else {
+        guard let privateKey = NCEndToEndEncryption.sharedManager().decryptPrivateKeyCipher(metadataNet.key, passphrase: appDelegate.e2ePassphrase) else {
             
             appDelegate.messageNotification("E2E decrypt private key", description: "E2E Error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             
@@ -171,7 +171,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
         CCUtility.setEndToEndPrivateKey(appDelegate.activeAccount, privateKey: privateKey)
             
         // Save passphrase to keychain
-        CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase:k_passphrase_test)
+        CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase:appDelegate.e2ePassphrase)
 
         NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E PrivateKey present on Server and stored to keychain", type: k_activityTypeSuccess, verbose: false, activeUrl: "")
     }
@@ -192,10 +192,8 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
             // remove keychain
             CCUtility.setEndToEndPrivateKey(appDelegate.activeAccount, privateKey: nil)
             CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase: nil)
-
-            let passphrase = k_passphrase_test;
             
-            guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().createEnd(toEndPrivateKey: appDelegate.activeUserID, directoryUser: appDelegate.directoryUser, passphrase: passphrase) else {
+            guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().createEnd(toEndPrivateKey: appDelegate.activeUserID, directoryUser: appDelegate.directoryUser, passphrase: appDelegate.e2ePassphrase) else {
                 
                 appDelegate.messageNotification("E2E private keys", description: "E2E Error to create PublicKey chiper", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
                 
@@ -208,7 +206,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
                     
             metadataNet.action = actionStoreEndToEndPrivateKeyCipher
             metadataNet.key = privateKeyChiper
-            metadataNet.password = passphrase
+            metadataNet.password = appDelegate.e2ePassphrase
                     
             appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
             

+ 8 - 2
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -112,10 +112,16 @@
  
     [self deselectFormRow:sender];
 
+    // select Passphrase
+    app.e2ePassphrase = k_passphrase_test;
+    
     if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
-        message = NSLocalizedString(@"_e2e_settings_encryption_initialize_already_request_", nil);
+        
+        message = [NSString stringWithFormat:@"%@\n\n%@\n\n%@", NSLocalizedString(@"_e2e_settings_encryption_initialize_already_request_", nil), NSLocalizedString(@"_e2e_settings_encryption_view_passphrase_", nil), app.e2ePassphrase];
+
     } else {
-        message = NSLocalizedString(@"_e2e_settings_encryption_initialize_request_", nil);
+
+        message = [NSString stringWithFormat:@"%@\n\n%@\n\n%@", NSLocalizedString(@"_e2e_settings_encryption_initialize_request_", nil), NSLocalizedString(@"_e2e_settings_encryption_view_passphrase_", nil), app.e2ePassphrase];
     }
         
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_initialization_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];