Marino Faggiana 7 years ago
parent
commit
1846448335

+ 33 - 11
iOSClient/Security/NCEntoToEndInterface.swift

@@ -158,22 +158,44 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
     
     func getEndToEndPrivateKeyCipherSuccess(_ metadataNet: CCMetadataNet!) {
         
-        guard let privateKey = NCEndToEndEncryption.sharedManager().decryptPrivateKeyCipher(metadataNet.key, passphrase: appDelegate.e2ePassphrase) else {
+        // request Passphrase
+        
+        var passphraseTextField: UITextField?
+        
+        let alertController = UIAlertController(title: "UIAlertController", message: "UIAlertController With TextField", preferredStyle: .alert)
+        
+        let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
             
-            appDelegate.messageNotification("E2E decrypt private key", description: "E2E Error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
+            let passphrase = passphraseTextField?.text
+
+            guard let privateKey = NCEndToEndEncryption.sharedManager().decryptPrivateKeyCipher(metadataNet.key, passphrase: passphrase) else {
+                
+                self.appDelegate.messageNotification("E2E decrypt private key", description: "E2E Error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
+                
+                NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Error to decrypt Private Key", type: k_activityTypeFailure, verbose: false, activeUrl: "")
+                
+                return
+            }
             
-            NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Error to decrypt Private Key", type: k_activityTypeFailure, verbose: false, activeUrl: "")
+            // Save to keychain
+            CCUtility.setEndToEndPrivateKey(self.appDelegate.activeAccount, privateKey: privateKey)
             
-            return
+            // Save passphrase to keychain
+            CCUtility.setEndToEndPassphrase(self.appDelegate.activeAccount, passphrase:passphrase)
+            
+            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: "")
+        })
+        let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
         }
         
-        // Save to keychain
-        CCUtility.setEndToEndPrivateKey(appDelegate.activeAccount, privateKey: privateKey)
-            
-        // Save passphrase to keychain
-        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: "")
+        alertController.addAction(ok)
+        alertController.addAction(cancel)
+        alertController.addTextField { (textField) -> Void in
+            passphraseTextField = textField
+            passphraseTextField?.placeholder = "Enter passphrase (12 words)"
+        }
+        
+        appDelegate.activeMain.present(alertController, animated: true)
     }
     
     func getEndToEndPrivateKeyCipherFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {

+ 20 - 46
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -55,22 +55,21 @@
         return [super initWithForm:form];
     }
     
-    
-    // Section INITIALIZE -------------------------------------------------
+    if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
+   
+        // Section START E2E -------------------------------------------------
 
-    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
-    [form addFormSection:section];
+        section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_start_", nil)];
+        [form addFormSection:section];
     
-    // Inizializze e2e
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"initE2E" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
-    [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
-    [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
-    [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
-    row.action.formSelector = @selector(initE2E:);
-    [section addFormRow:row];
+        // Start e2e
+        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"startE2E" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_start_", nil)];
+        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
+        [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
+        [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
+        row.action.formSelector = @selector(startE2E:);
+        [section addFormRow:row];
    
-    if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
-        
         // Section PASSPHRASE -------------------------------------------------
     
         section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_read_passphrase_", nil)];
@@ -83,6 +82,11 @@
         [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
         row.action.formSelector = @selector(readPassphrase:);
         [section addFormRow:row];
+        
+    } else {
+        
+        section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_started_", nil)];
+        [form addFormSection:section];
     }
     
 #ifdef DEBUG
@@ -147,42 +151,12 @@
     [CCUtility initEndToEnd:app.activeAccount];
 }
 
-- (void)initE2E:(XLFormRowDescriptor *)sender
+- (void)startE2E:(XLFormRowDescriptor *)sender
 {
-    NSString *message;
- 
     [self deselectFormRow:sender];
 
-    // select Passphrase
-    //app.e2ePassphrase = k_passphrase_test;
-    app.e2ePassphrase = [NYMnemonic generateMnemonicString:@128 language:@"english"];
-    
-    if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
-        
-        message = [NSString stringWithFormat:@"%@\n\n%@\n\n%@", NSLocalizedString(@"_e2e_settings_initialize_already_request_", nil), NSLocalizedString(@"_e2e_settings_view_passphrase_", nil), app.e2ePassphrase];
-
-    } else {
-
-        message = [NSString stringWithFormat:@"%@\n\n%@\n\n%@", NSLocalizedString(@"_e2e_settings_initialize_request_", nil), NSLocalizedString(@"_e2e_settings_view_passphrase_", nil), app.e2ePassphrase];
-    }
-        
-    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_initialization_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
-    
-    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-        NSLog(@"Cancel action");
-    }];
-    
-    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        
-        [self deletePublicKey:sender];
-        [self deletePrivateKey:sender];
-        
-        [CCUtility initEndToEnd:app.activeAccount];
-    }];
-    
-    [alertController addAction:cancelAction];
-    [alertController addAction:okAction];
-    [self presentViewController:alertController animated:YES completion:nil];
+    [CCUtility initEndToEnd:app.activeAccount];
+    [app.endToEndInterface initEndToEndEncryption];
 }
 
 - (void)readPassphrase:(XLFormRowDescriptor *)sender

+ 2 - 3
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -581,10 +581,9 @@
 
 "_e2e_settings_title_"              = "Encryption";
 "_e2e_settings_"                    = "End To End Encryption";
-"_e2e_settings_initialize_"         = "Initialize End To End Encryption";
+"_e2e_settings_start_"              = "Start End To End Encryption";
 "_e2e_settings_not_available_"      = "End To End Encryption not available";
-"_e2e_settings_initialize_already_request_" = "Service already started, you want to restart it?";
-"_e2e_settings_initialize_request_" = "Do you want to start the End To End Encryption?";
+"_e2e_settings_start_request_"      = "Do you want to start the End To End Encryption?";
 "_e2e_settings_activated_"          = "End To End Encryption activated";
 "_e2e_settings_view_passphrase_"    = "This 12 word phrase is like a very strong password: it provides full access to view and use your encrypted files. Please write it down and keep it somewhere safe.";
 "_e2e_settings_read_passphrase_"    = "Read passphrase";