Przeglądaj źródła

fix checkTrustedChallenge [rollback] + host

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 lat temu
rodzic
commit
72bb6aac74

+ 6 - 51
iOSClient/Login/NCLogin.swift

@@ -228,7 +228,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                     // Login Flow V2
                     if errorCode == 0 && NCBrandOptions.shared.use_loginflowv2 && token != nil && endpoint != nil && login != nil {
                         
-                        self.checkPushNotificationServerProxy { errorCode in
+                        NCNetworking.shared.checkPushNotificationServerProxyCertificateUntrusted(viewController: self, completion: { errorCode in
                             if errorCode == 0 {
                                 if let loginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb {
                                     
@@ -241,12 +241,12 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                                     self.navigationController?.pushViewController(loginWeb, animated: true)
                                 }
                             }
-                        }
+                        })
                         
                     // Login Flow
                     } else if versionMajor >= NCGlobal.shared.nextcloudVersion12 {
                         
-                        self.checkPushNotificationServerProxy { errorCode in
+                        NCNetworking.shared.checkPushNotificationServerProxyCertificateUntrusted(viewController: self, completion: { errorCode in
                             if errorCode == 0 {
                                 if let loginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb {
                                     
@@ -255,7 +255,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                                     self.navigationController?.pushViewController(loginWeb, animated: true)
                                 }
                             }
-                        }
+                        })
                         
                     // NO Login flow available
                     } else if versionMajor < NCGlobal.shared.nextcloudVersion12 {
@@ -328,12 +328,12 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                 
                 NCCommunication.shared.checkServer(serverUrl: serverUrl) { (errorCode, errorDescription) in
                 
-                    self.checkPushNotificationServerProxy { errorCode in
+                    NCNetworking.shared.checkPushNotificationServerProxyCertificateUntrusted(viewController: self, completion: { errorCode in
                         if errorCode == 0 {
                             self.loginButton.isEnabled = true
                             self.standardLogin(url: urlBase, user: user, password: password, errorCode: errorCode, errorDescription: errorDescription)
                         }
-                    }
+                    })
                 }
             }
         }
@@ -417,49 +417,4 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
             self.present(alertController, animated: true, completion: { })
         }
     }
-    
-    // MARK: -
-    
-    func checkPushNotificationServerProxy(completion: @escaping (_ errorCode: Int)->()) {
-        
-        let url = NCBrandOptions.shared.pushNotificationServerProxy
-        
-        NCCommunication.shared.checkServer(serverUrl: url) { (errorCode, errorDescription) in
-            
-            if errorCode == 0 {
-                
-                if let host = URL(string: url)?.host {
-                    NCNetworking.shared.writeCertificate(host: host)
-                }
-                completion(errorCode)
-                
-            } else if errorCode == NSURLErrorServerCertificateUntrusted {
-                
-                let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_untrusted_", comment: ""), message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
-                            
-                alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
-                    if let host = URL(string: url)?.host {
-                        NCNetworking.shared.writeCertificate(host: host)
-                    }
-                    completion(0)
-                }))
-                
-                alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in
-                    completion(errorCode)
-                }))
-                
-                alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
-                    if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() {
-                        self.present(navigationController, animated: true)
-                    }
-                }))
-                
-                self.present(alertController, animated: true)
-                
-            } else {
-                
-                completion(0)
-            }
-        }
-    }
 }

+ 44 - 1
iOSClient/Networking/NCNetworking.swift

@@ -202,7 +202,7 @@ import Queuer
     
         if !NCUtilityFileSystem.shared.moveFile(atPath: certificateAtPath, toPath: certificateToPath) {
             NCContentPresenter.shared.messageNotification("_error_", description: "_error_creation_file_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorCreationFile, forced: true)
-        }        
+        }
     }
     
     private func saveX509Certificate(_ serverTrust: SecTrust, host: String, directoryCertificate: String) {
@@ -251,6 +251,49 @@ import Queuer
         }
     }
     
+    func checkPushNotificationServerProxyCertificateUntrusted(viewController: UIViewController ,completion: @escaping (_ errorCode: Int)->()) {
+        
+        let url = NCBrandOptions.shared.pushNotificationServerProxy
+        
+        NCCommunication.shared.checkServer(serverUrl: url) { (errorCode, errorDescription) in
+            
+            if errorCode == 0 {
+                
+                if let host = URL(string: url)?.host {
+                    NCNetworking.shared.writeCertificate(host: host)
+                }
+                completion(errorCode)
+                
+            } else if errorCode == NSURLErrorServerCertificateUntrusted {
+                
+                let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_untrusted_", comment: ""), message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
+                            
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
+                    if let host = URL(string: url)?.host {
+                        NCNetworking.shared.writeCertificate(host: host)
+                    }
+                    completion(0)
+                }))
+                
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in
+                    completion(errorCode)
+                }))
+                
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
+                    if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() {
+                        viewController.present(navigationController, animated: true)
+                    }
+                }))
+                
+                viewController.present(alertController, animated: true)
+                
+            } else {
+                
+                completion(0)
+            }
+        }
+    }
+    
     //MARK: - Utility
     
     func cancelTaskWithUrl(_ url: URL) {