Przeglądaj źródła

fix title certificate untrusted or changed

marinofaggiana 3 lat temu
rodzic
commit
cd7e4ddddb

+ 8 - 1
iOSClient/AppDelegate.swift

@@ -564,7 +564,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // check certificate untrusted (-1202)
         if CCUtility.getCertificateError(account) {
             
-            let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_untrusted_", comment: ""), message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
+            var title = ""
+            if CCUtility.getCertificateErrorSavedFound(account) {
+                title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
+            } else {
+                title = NSLocalizedString("_ssl_certificate_untrusted_", comment: "")
+            }
+            
+            let alertController = UIAlertController(title: title, message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
                         
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
                 NCNetworking.shared.writeCertificate(url: self.urlBase)

+ 1 - 1
iOSClient/Networking/NCNetworking.swift

@@ -279,7 +279,7 @@ import Queuer
                         #if !EXTENSION
                         DispatchQueue.main.async {
                             let appDelegate = UIApplication.shared.delegate as! AppDelegate
-                            CCUtility.setCertificateError(appDelegate.account)
+                            CCUtility.setCertificateError(appDelegate.account, certificateSavedFound: certificateSavedFound)
                         }
                         #endif
                     }

+ 1 - 1
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -327,7 +327,7 @@ import Alamofire
                             
                             } else if errorCode == Int(CFNetworkErrors.cfurlErrorServerCertificateUntrusted.rawValue) {
                             
-                                CCUtility.setCertificateError(metadata.account)
+                                CCUtility.setCertificateError(metadata.account, certificateSavedFound: true)
                                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
                                                     
                             } else {

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

@@ -736,6 +736,7 @@
 "_user_authentication_required_"        = "User authentication required";
 "_file_directory_locked_"               = "File or directory locked";
 "_ssl_certificate_untrusted_"           = "The certificate for this server is invalid";
+"_ssl_certificate_changed_"             = "The certificate for this server seems to have changed";
 "_internal_server_"                     = "Internal server error";
 "_file_already_exists_"                 = "Could not complete the operation, a file with the same name exists";
 "_file_folder_not_exists_"              = "The source file wasn't found at the specified path";

+ 2 - 1
iOSClient/Utility/CCUtility.h

@@ -147,7 +147,8 @@
 + (NSData *)getDatabaseEncryptionKey;
 
 + (BOOL)getCertificateError:(NSString *)account;
-+ (void)setCertificateError:(NSString *)account;
++ (BOOL)getCertificateErrorSavedFound:(NSString *)account;
++ (void)setCertificateError:(NSString *)account certificateSavedFound:(BOOL)certificateSavedFound;
 + (void)clearCertificateError:(NSString *)account;
 
 + (BOOL)getDisableLocalCacheAfterUpload;

+ 24 - 8
iOSClient/Utility/CCUtility.m

@@ -562,17 +562,31 @@
     return true;
 }
 
-+ (void)setCertificateError:(NSString *)account
++ (BOOL)getCertificateErrorSavedFound:(NSString *)account
+{
+    NSString *key = [@"certificateErrorSavedFound" stringByAppendingString:account];
+    NSString *error = [UICKeyChainStore stringForKey:key service:NCGlobal.shared.serviceShareKeyChain];
+    
+    if (error == nil) {
+        return false;
+    }
+    
+    return true;
+}
+
++ (void)setCertificateError:(NSString *)account certificateSavedFound:(BOOL)certificateSavedFound
 {
     // In background do not write the error
 #if !defined(EXTENSION)
     UIApplicationState state = [[UIApplication sharedApplication] applicationState];
-    if (state == UIApplicationStateBackground || state == UIApplicationStateInactive) {
-        return;
-    }
-    NSString *key = [@"certificateError" stringByAppendingString:account];
+    if (state == UIApplicationStateBackground || state == UIApplicationStateInactive) { return; }
     
-    [UICKeyChainStore setString:@"true" forKey:key service:NCGlobal.shared.serviceShareKeyChain];
+    NSString *keyCertificateError = [@"certificateError" stringByAppendingString:account];
+    NSString *keyCertificateErrorSavedFound = [@"certificateErrorSavedFound" stringByAppendingString:account];
+
+    [UICKeyChainStore setString:@"true" forKey:keyCertificateError service:NCGlobal.shared.serviceShareKeyChain];
+    NSString *sCertificateSavedFound = (certificateSavedFound) ? @"true" : @"false";
+    [UICKeyChainStore setString:sCertificateSavedFound forKey:keyCertificateErrorSavedFound service:NCGlobal.shared.serviceShareKeyChain];
 #else
     return;
 #endif
@@ -580,9 +594,11 @@
 
 + (void)clearCertificateError:(NSString *)account
 {
-    NSString *key = [@"certificateError" stringByAppendingString:account];
+    NSString *keyCertificateError = [@"certificateError" stringByAppendingString:account];
+    NSString *keyCertificateErrorSavedFound = [@"certificateErrorSavedFound" stringByAppendingString:account];
     
-    [UICKeyChainStore setString:nil forKey:key service:NCGlobal.shared.serviceShareKeyChain];
+    [UICKeyChainStore setString:nil forKey:keyCertificateError service:NCGlobal.shared.serviceShareKeyChain];
+    [UICKeyChainStore setString:nil forKey:keyCertificateErrorSavedFound service:NCGlobal.shared.serviceShareKeyChain];
 }
 
 + (BOOL)getDisableLocalCacheAfterUpload