Browse Source

clear keychain when delete account

marinofaggiana 5 years ago
parent
commit
4c50b2fdf2

+ 4 - 4
iOSClient/Security/CCCertificate.m

@@ -145,9 +145,6 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
     _delegate = delegate;
     
-    // Stop timer error network
-    [appDelegate.timerErrorNetworking invalidate];
-    
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
     
         UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_ssl_certificate_untrusted_", nil) message:NSLocalizedString(@"_connect_server_anyway_", nil)  preferredStyle:UIAlertControllerStyleAlert];
@@ -170,7 +167,10 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
                 [self.delegate trustedCerticateDenied];
         }]];
         
-        [appDelegate.window.rootViewController presentViewController:alertController animated:YES completion:nil];
+        [appDelegate.window.rootViewController presentViewController:alertController animated:YES completion:^{
+            // Stop timer error network
+            [appDelegate.timerErrorNetworking invalidate];
+        }];
     });
 }
 

+ 21 - 14
iOSClient/Settings/CCManageAccount.m

@@ -404,26 +404,33 @@
         XLFormPickerCell *pickerAccount = (XLFormPickerCell *)[[self.form formRowWithTag:@"pickerAccount"] cellForFormController:self];
         
         tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", pickerAccount.rowDescriptor.value]];
+        NSString *account = tableAccount.account;
         
-        if (tableAccount) {
+        if (account) {
             
-            [appDelegate unsubscribingNextcloudServerPushNotification:tableAccount.account url:tableAccount.url withSubscribing:false];
+            [appDelegate unsubscribingNextcloudServerPushNotification:account url:tableAccount.url withSubscribing:false];
         
-            [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableActivitySubjectRich class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableMedia class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:tableAccount.account];
-            [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:tableAccount.account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableActivitySubjectRich class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableMedia class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:account];
+            [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:account];
         
             // Clear active user
             [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
+            
+            // Clear keychain
+            [CCUtility clearAllKeysEndToEnd:account];
+            [CCUtility clearAllKeysPushNotification:account];
+            [CCUtility setPassword:account password:nil];
+            [CCUtility setCertificateError:account error:NO];
         }
         
         NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];

+ 1 - 0
iOSClient/Utility/CCUtility.h

@@ -146,6 +146,7 @@
 + (NSString *)getPushNotificationDeviceIdentifier:(NSString *)account;
 + (void)setPushNotificationDeviceIdentifierSignature:(NSString *)account deviceIdentifierSignature:(NSString *)deviceIdentifierSignature;
 + (NSString *)getPushNotificationDeviceIdentifierSignature:(NSString *)account;
++ (void)clearAllKeysPushNotification:(NSString *)account;
 
 + (NSInteger)getMediaWidthImage;
 + (void)setMediaWidthImage:(NSInteger)width;

+ 10 - 0
iOSClient/Utility/CCUtility.m

@@ -551,6 +551,16 @@
     return [UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain];
 }
 
++ (void)clearAllKeysPushNotification:(NSString *)account
+{
+    [self setPushNotificationPublicKey:account data:nil];
+    [self setPushNotificationSubscribingPublicKey:account publicKey:nil];
+    [self setPushNotificationPrivateKey:account data:nil];
+    [self setPushNotificationToken:account token:nil];
+    [self setPushNotificationDeviceIdentifier:account deviceIdentifier:nil];
+    [self setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:nil];
+}
+
 + (NSInteger)getMediaWidthImage
 {
     NSString *width = [UICKeyChainStore stringForKey:@"mediaWidthImage" service:k_serviceShareKeyChain];