Browse Source

Inizialize e2e

Marino Faggiana 7 years ago
parent
commit
43d6ed7e09

+ 27 - 1
iOSClient/Security/NCEntoToEndInterface.swift

@@ -27,6 +27,10 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
+    var deletePublicKey = false;
+    var deletePrivateKey = false;
+    
+    
     override init() {
     }
     
@@ -35,7 +39,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
     // --------------------------------------------------------------------------------------------
     
     @objc func initEndToEndEncryption() {
-
+        
         let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
         
         metadataNet.action = actionGetEndToEndPublicKeys;
@@ -116,10 +120,21 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
     }
     
     func deleteEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
+        
+        deletePublicKey = true;
+        if (deletePrivateKey) {
+            deletePublicKey = false;
+            deletePrivateKey = false;
+            initEndToEndEncryption()
+        }
+
         appDelegate.messageNotification("E2E delete public key", description: "Public key was deleted", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.success, errorCode: 0)
     }
     
     func deleteEnd(toEndPublicKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
+        
+        deletePublicKey = false;
+        
         appDelegate.messageNotification("E2E delete public key", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
     }
     
@@ -212,10 +227,21 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
     }
     
     func deleteEnd(toEndPrivateKeySuccess metadataNet: CCMetadataNet!) {
+        
+        deletePrivateKey = true;
+        if (deletePublicKey) {
+            deletePublicKey = false;
+            deletePrivateKey = false;
+            initEndToEndEncryption()
+        }
+        
         appDelegate.messageNotification("E2E delete private key", description: "Private key was deleted", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.success, errorCode: 0)
     }
     
     func deleteEnd(toEndPrivateKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
+        
+        deletePrivateKey = false;
+        
         appDelegate.messageNotification("E2E delete private key", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
     }
     

+ 29 - 5
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -63,11 +63,11 @@
 #ifdef DEBUG
     // Section DELETE KEYS -------------------------------------------------
     
-    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"Delete", nil)];
+    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"Delete server keys ", nil)];
     [form addFormSection:section];
     
     // Delete publicKey
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePublicKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_encryption_delete_publicKey_", nil)];
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePublicKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete PublicKey", 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"];
@@ -75,7 +75,7 @@
     [section addFormRow:row];
     
     // Delete privateKey
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePrivateKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_encryption_delete_privateKey_", nil)];
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePrivateKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete PrivateKey", 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"];
@@ -108,9 +108,33 @@
 
 - (void)initE2E:(XLFormRowDescriptor *)sender
 {
-    [CCUtility initEndToEnd:app.activeAccount];
+    NSString *message;
+ 
+    [self deselectFormRow:sender];
+
+    if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
+        message = NSLocalizedString(@"_e2e_settings_encryption_initialize_already_request_", nil);
+    } else {
+        message = NSLocalizedString(@"_e2e_settings_encryption_initialize_request_", nil);
+    }
+        
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_e2e_settings_encryption_initialize_", 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];
+    }];
     
-    [app.endToEndInterface initEndToEndEncryption];
+    [alertController addAction:cancelAction];
+    [alertController addAction:okAction];
+    [self presentViewController:alertController animated:YES completion:nil];
 }
 
 @end

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

@@ -578,6 +578,8 @@
 "_e2e_settings_encryption_"         = "End To End Encryption";
 "_e2e_settings_encryption_initialize_"      = "Initialize End To End Encryption";
 "_e2e_settings_encryption_not_available_"   = "End To End Encryption not available";
+"_e2e_settings_encryption_initialize_already_request_"  = "Service already inizialized, you want to reinitialize it ?";
+"_e2e_settings_encryption_initialize_request_" = "you want to start the End To End Encryption ?";