Selaa lähdekoodia

fix checkTrustedChallenge return in main thread

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 vuotta sitten
vanhempi
commit
387010d004
2 muutettua tiedostoa jossa 28 lisäystä ja 30 poistoa
  1. 26 24
      iOSClient/AppDelegate.swift
  2. 2 6
      iOSClient/Networking/NCNetworking.swift

+ 26 - 24
iOSClient/AppDelegate.swift

@@ -542,31 +542,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
               host == currentHost
         else { return }
 
-        let certificateHostSavedPath = CCUtility.getDirectoryCerificates()! + "/" + host + ".der"
-        var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
-        
-        if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
-            title = NSLocalizedString("_connect_server_anyway_", comment: "")
-        }
-        
-        let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
-        
-        alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
-            NCNetworking.shared.writeCertificate(host: host)
-        }))
-        
-        alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in }))
-        
-        alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
-            if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController {
-                let viewController = navigationController.topViewController as! NCViewCertificateDetails
-                viewController.delegate = self
-                viewController.host = host
-                self.window?.rootViewController?.present(navigationController, animated: true)
+        DispatchQueue.main.async {
+            let certificateHostSavedPath = CCUtility.getDirectoryCerificates()! + "/" + host + ".der"
+            var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
+
+            if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
+                title = NSLocalizedString("_connect_server_anyway_", comment: "")
             }
-        }))
-        
-        window?.rootViewController?.present(alertController, animated: true)
+
+            let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
+
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
+                NCNetworking.shared.writeCertificate(host: host)
+            }))
+
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in }))
+
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
+                if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController {
+                    let viewController = navigationController.topViewController as! NCViewCertificateDetails
+                    viewController.delegate = self
+                    viewController.host = host
+                    self.window?.rootViewController?.present(navigationController, animated: true)
+                }
+            }))
+
+            self.window?.rootViewController?.present(alertController, animated: true)
+        }
     }
 
     func viewCertificateDetailsDismiss(host: String) {

+ 2 - 6
iOSClient/Networking/NCNetworking.swift

@@ -168,16 +168,12 @@ import Photos
 
         #if !EXTENSION
         defer {
-            DispatchQueue.main.async {
-                if !isTrusted {
-                    (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host)
-                }
+            if !isTrusted {
+                (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host)
             }
         }
         #endif
         
-        print("SSL host: \(host)")
-        
         if let serverTrust: SecTrust = protectionSpace.serverTrust, let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0)  {
             
             // extarct certificate txt