Browse Source

add check certificate untrusted

marinofaggiana 6 years ago
parent
commit
fad4828b98

+ 5 - 0
iOSClient/AppDelegate.m

@@ -325,6 +325,11 @@ PKPushRegistry *pushRegistry;
     if ([CCUtility getPassword:self.activeAccount].length == 0) {
         [self openLoginView:self.window.rootViewController delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
     }
+    
+    // check certificate untrusted (-1202)
+    if ([CCUtility getCertificateError]) {
+        [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:NSLocalizedString(@"_ssl_certificate_untrusted_", nil) viewController:self.window.rootViewController delegate:self];
+    }
 }
 
 - (void)openLoginView:(UIViewController *)viewController delegate:(id)delegate loginType:(NSInteger)loginType selector:(NSInteger)selector

+ 0 - 4
iOSClient/Favorites/CCFavorites.m

@@ -179,8 +179,6 @@
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadata.fileID favorite:favorite];
             [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:metadata.fileID action:k_action_MOD];
-        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         } else {
@@ -244,8 +242,6 @@
             
             [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
             
-        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         } else {

+ 4 - 18
iOSClient/Main/CCMain.m

@@ -1131,8 +1131,6 @@
                 [self readFolder:metadata.serverUrl];
             }
             
-        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         } else {
@@ -1261,8 +1259,6 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
-        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         } else {
@@ -1322,9 +1318,7 @@
             
         } else {
             
-            if (errorCode == NSURLErrorServerCertificateUntrusted) {
-                [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
-            } else if (errorCode != 0) {
+            if (errorCode != 0) {
                 [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
             } else {
                 NSLog(@"[LOG] It has been changed user during networking process, error.");
@@ -1510,9 +1504,7 @@
                 
             } else if (errorCode != 0) {
                 
-                if (errorCode == NSURLErrorServerCertificateUntrusted) {
-                    [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
-                } else if (errorCode == kOCErrorServerPathNotFound) {
+                if (errorCode == kOCErrorServerPathNotFound) {
                 
                     NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
                     NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, fileNameNew];
@@ -1595,9 +1587,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == NSURLErrorServerCertificateUntrusted) {
-                [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
-            } else if (errorCode == kOCErrorServerPathNotFound) {
+            if (errorCode == kOCErrorServerPathNotFound) {
             
                 NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
                 NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName];
@@ -1803,9 +1793,7 @@
             [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileIDTemp]];
             [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
             
-            if (errorCode == NSURLErrorServerCertificateUntrusted) {
-                [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
-            } else if (errorCode != 0) {
+            if (errorCode != 0) {
                 [appDelegate messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
             } else {
                 NSLog(@"[LOG] It has been changed user during networking process, error.");
@@ -2134,8 +2122,6 @@
                 [appDelegate startLoadAutoDownloadUpload];
             }
             
-        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         } else {

+ 4 - 0
iOSClient/Networking/CCNetworking.m

@@ -547,6 +547,8 @@
             
             if (metadata && errorCode == kOCErrorServerUnauthorized)
                 [CCUtility setPassword:metadata.account password:nil];
+            else if (metadata && errorCode == NSURLErrorServerCertificateUntrusted)
+                [CCUtility setCertificateError:YES];
 
             [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[CCError manageErrorKCF:errorCode withNumberError:NO] sessionSelector:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusDownloadError predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
         }
@@ -1100,6 +1102,8 @@
 
             if (metadata && errorCode == kOCErrorServerUnauthorized)
                 [CCUtility setPassword:metadata.account password:nil];
+            else if (metadata && errorCode == NSURLErrorServerCertificateUntrusted)
+                [CCUtility setCertificateError:YES];
             
             [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[CCError manageErrorKCF:errorCode withNumberError:NO] sessionSelector:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusUploadError predicate:[NSPredicate predicateWithFormat:@"fileID == %@", tempFileID]];
             

+ 80 - 0
iOSClient/Networking/OCNetworking.m

@@ -361,6 +361,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -406,6 +408,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -458,6 +462,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -579,6 +585,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -651,6 +659,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -706,6 +716,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         completion(account, nil, nil, message, errorCode);
@@ -755,6 +767,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -795,6 +809,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -908,6 +924,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -999,6 +1017,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1041,6 +1061,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1091,6 +1113,8 @@
             // Server Unauthorized
             if (errorCode == kOCErrorServerUnauthorized) {
                 [CCUtility setPassword:account password:nil];
+            } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+                [CCUtility setCertificateError:YES];
             }
             
             // Error
@@ -1186,6 +1210,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1228,6 +1254,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1272,6 +1300,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1313,6 +1343,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1356,6 +1388,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1397,6 +1431,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1438,6 +1474,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1479,6 +1517,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1520,6 +1560,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1572,6 +1614,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1612,6 +1656,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1653,6 +1699,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1694,6 +1742,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1735,6 +1785,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1776,6 +1828,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1836,6 +1890,8 @@
             // Server Unauthorized
             if (errorCode == kOCErrorServerUnauthorized) {
                 [CCUtility setPassword:account password:nil];
+            } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+                [CCUtility setCertificateError:YES];
             }
             
             // Error
@@ -1858,6 +1914,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -1906,6 +1964,8 @@
             // Server Unauthorized
             if (errorCode == kOCErrorServerUnauthorized) {
                 [CCUtility setPassword:account password:nil];
+            } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+                [CCUtility setCertificateError:YES];
             }
             
             // Error
@@ -1928,6 +1988,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2015,6 +2077,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2055,6 +2119,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2095,6 +2161,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2137,6 +2205,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2223,6 +2293,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2265,6 +2337,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2312,6 +2386,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2382,6 +2458,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error
@@ -2425,6 +2503,8 @@
         // Server Unauthorized
         if (errorCode == kOCErrorServerUnauthorized) {
             [CCUtility setPassword:account password:nil];
+        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            [CCUtility setCertificateError:YES];
         }
         
         // Error

+ 1 - 0
iOSClient/Security/CCCertificate.m

@@ -153,6 +153,7 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
         [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                                                            
             [[CCCertificate sharedManager] acceptCertificate];
+            [CCUtility setCertificateError:NO];
             
             if([self.delegate respondsToSelector:@selector(trustedCerticateAccepted)])
                 [self.delegate trustedCerticateAccepted];

+ 0 - 2
iOSClient/Shares/NCShares.m

@@ -204,8 +204,6 @@
             
             [self reloadDatasource];
             
-        } if (errorCode == NSURLErrorServerCertificateUntrusted) {
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         } else {