Browse Source

Read passphrase on Settings

Marino Faggiana 7 years ago
parent
commit
762eff91db

+ 1 - 0
iOSClient/Security/CCBKPasscode.h

@@ -31,6 +31,7 @@ typedef enum : NSUInteger {
     CCBKPasscodeFromLockDirectory,
     CCBKPasscodeFromDisactivateDirectory,
     CCBKPasscodeFromCheckCryptoKey,
+    CCBKPasscodeFromCheckPassphrase,
     CCBKPasscodeFromSettingsPasscode,
     CCBKPasscodeFromSimply
 } CCBKPasscodeTypeFrom;

+ 6 - 2
iOSClient/Settings/CCSettings.m

@@ -103,8 +103,8 @@
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [section addFormRow:row];
     
-    // Passcode only directory
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_folder_", nil)];
+    // Passcode no screen
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [section addFormRow:row];
     
@@ -432,6 +432,10 @@
             sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
         }
         break;
+        case 2: {
+            sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
+        }
+        break;
         case 4: {
             
             tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilites];

+ 2 - 1
iOSClient/Settings/NCManageEndToEndEncryption.h

@@ -23,7 +23,8 @@
 
 #import "XLFormViewController.h"
 #import "XLForm.h"
+#import "BKPasscodeViewController.h"
 
-@interface NCManageEndToEndEncryption : XLFormViewController
+@interface NCManageEndToEndEncryption : XLFormViewController <BKPasscodeViewControllerDelegate>
 
 @end

+ 118 - 10
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -25,8 +25,16 @@
 #import "AppDelegate.h"
 #import "CCNetworking.h"
 #import "NYMnemonic.h"
+
 #import "NCBridgeSwift.h"
 
+@interface NCManageEndToEndEncryption ()
+{
+    NSUInteger _failedAttempts;
+    NSDate *_lockUntilDate;
+}
+@end
+
 @implementation NCManageEndToEndEncryption
 
 -(id)init
@@ -61,18 +69,21 @@
     row.action.formSelector = @selector(initE2E:);
     [section addFormRow:row];
    
-    // Section INITIALIZE -------------------------------------------------
+    if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
+        
+        // Section PASSPHRASE -------------------------------------------------
     
-    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
-    [form addFormSection:section];
+        section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_read_passphrase_", 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];
+        // Read Passphrase
+        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"readPassphrase" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_read_passphrase_", 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(readPassphrase:);
+        [section addFormRow:row];
+    }
     
 #ifdef DEBUG
     // Section DELETE KEYS -------------------------------------------------
@@ -95,6 +106,15 @@
     [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
     row.action.formSelector = @selector(deletePrivateKey:);
     [section addFormRow:row];
+    
+    // Delete locally Encryption
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deleteLocallyEncryption" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete locally encryption", 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(deleteLocallyEncryption:);
+    [section addFormRow:row];
+    
 #endif
     
     return [super initWithForm:form];
@@ -120,6 +140,13 @@
     [app addNetworkingOperationQueue:app.netQueue delegate:app.endToEndInterface metadataNet:metadataNet];
 }
 
+- (void)deleteLocallyEncryption:(XLFormRowDescriptor *)sender
+{
+    [self deselectFormRow:sender];
+    
+    [CCUtility initEndToEnd:app.activeAccount];
+}
+
 - (void)initE2E:(XLFormRowDescriptor *)sender
 {
     NSString *message;
@@ -158,4 +185,85 @@
     [self presentViewController:alertController animated:YES completion:nil];
 }
 
+- (void)readPassphrase:(XLFormRowDescriptor *)sender
+{
+    [self deselectFormRow:sender];
+    
+    if ([[CCUtility getBlockCode] length]) {
+        
+        CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
+        viewController.delegate = self;
+        viewController.fromType = CCBKPasscodeFromCheckPassphrase;
+        viewController.type = BKPasscodeViewControllerCheckPasscodeType;
+            
+        if ([CCUtility getSimplyBlockCode]) {
+            viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
+            viewController.passcodeInputView.maximumLength = 6;
+        } else {
+            viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
+            viewController.passcodeInputView.maximumLength = 64;
+        }
+        
+        BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
+        touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
+        viewController.touchIDManager = touchIDManager;
+        
+        viewController.title = NSLocalizedString(@"_e2e_settings_read_passphrase_", nil);
+        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
+            
+        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
+        [self presentViewController:navigationController animated:YES completion:nil];
+        
+    } else {
+        
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:NSLocalizedString(@"_e2e_settings_lock_not_active_", nil) preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+        }];
+        [alertController addAction:okAction];
+        [self presentViewController:alertController animated:YES completion:nil];
+    }
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark === BKPasscodeViewController ===
+#pragma --------------------------------------------------------------------------------------------
+
+- (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
+{
+    return _failedAttempts;
+}
+
+- (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
+{
+    return _lockUntilDate;
+}
+
+- (void)passcodeViewCloseButtonPressed:(id)sender
+{
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+
+- (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
+{
+    if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
+        _lockUntilDate = nil;
+        _failedAttempts = 0;
+        aResultHandler(YES);
+    } else
+        aResultHandler(NO);
+}
+
+- (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
+{
+    [aViewController dismissViewControllerAnimated:YES completion:nil];
+    
+    NSString *message = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"_e2e_settings_the_passphrase_is_", nil), [CCUtility getEndToEndPassphrase:app.activeAccount]];
+    
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+    }];
+    [alertController addAction:okAction];
+    [self presentViewController:alertController animated:YES completion:nil];
+}
+
 @end

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

@@ -94,7 +94,8 @@
 "_passcode_"                = "Password";
 "_lock_active_"             = "Lock: Active";
 "_lock_not_active_"         = "Lock: Not Active";
-"_lock_protection_folder_"  = "Lock only for protected folders";
+"_lock_protection_no_screen_"        = "Do not ask at startup";
+"_lock_protection_no_screen_footer_" = "Use \"Do not ask at startup\" for protected folders only or Encryption passphrase";
 "_url_"                     = "URL";
 "_username_"                = "Username";
 "_change_credentials_"      = "Change your credentials";
@@ -584,6 +585,7 @@
 "_e2e_settings_initialize_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";
+"_e2e_settings_lock_not_active_"    = "Lock not active, go back in Settings and activates the Lock";
+"_e2e_settings_the_passphrase_is_"  = "The passphrase is: \n\n";