Browse Source

fix checkTrustedChallenge [rollback] + host

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana 3 years ago
parent
commit
e9099c9785

+ 6 - 1
iOSClient/AppDelegate.swift

@@ -559,7 +559,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_changed_", comment: ""), message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
             let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_changed_", comment: ""), message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
             
             
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
-                NCNetworking.shared.writeCertificate(url: self.urlBase)
+                if NCNetworking.shared.certificatesError.contains(currentHost) {
+                    NCNetworking.shared.writeCertificate(host: currentHost)
+                }
+                if NCNetworking.shared.certificatesError.contains(pushNotificationServerProxyHost) {
+                    NCNetworking.shared.writeCertificate(host: pushNotificationServerProxyHost)
+                }
                 NCNetworking.shared.certificatesError.removeAll()
                 NCNetworking.shared.certificatesError.removeAll()
                 self.startTimerErrorNetworking()
                 self.startTimerErrorNetworking()
             }))
             }))

+ 12 - 4
iOSClient/Login/NCLogin.swift

@@ -258,7 +258,9 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
             
             
             if errorCode == 0 {
             if errorCode == 0 {
                 
                 
-                NCNetworking.shared.writeCertificate(url: url)
+                if let host = URL(string: url)?.host {
+                    NCNetworking.shared.writeCertificate(host: host)
+                }
                 
                 
                 NCCommunication.shared.getLoginFlowV2(serverUrl: url) { (token, endpoint, login, errorCode, errorDescription) in
                 NCCommunication.shared.getLoginFlowV2(serverUrl: url) { (token, endpoint, login, errorCode, errorDescription) in
                     
                     
@@ -310,7 +312,9 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                     let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_untrusted_", comment: ""), message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
                     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
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
-                        NCNetworking.shared.writeCertificate(url: url)
+                        if let host = URL(string: url)?.host {
+                            NCNetworking.shared.writeCertificate(host: host)
+                        }
                         self.appDelegate.startTimerErrorNetworking()
                         self.appDelegate.startTimerErrorNetworking()
                     }))
                     }))
                     
                     
@@ -344,7 +348,9 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
         
         
         if errorCode == 0 {
         if errorCode == 0 {
             
             
-            NCNetworking.shared.writeCertificate(url: url)
+            if let host = URL(string: url)?.host {
+                NCNetworking.shared.writeCertificate(host: host)
+            }
             
             
             let account = user + " " + url
             let account = user + " " + url
             
             
@@ -391,7 +397,9 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
             let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_untrusted_", comment: ""), message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
             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
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
-                NCNetworking.shared.writeCertificate(url: url)
+                if let host = URL(string: url)?.host {
+                    NCNetworking.shared.writeCertificate(host: host)
+                }
                 self.appDelegate.startTimerErrorNetworking()
                 self.appDelegate.startTimerErrorNetworking()
             }))
             }))
             
             

+ 7 - 14
iOSClient/Networking/NCNetworking.swift

@@ -194,22 +194,15 @@ import Queuer
         return false
         return false
     }
     }
     
     
-    func writeCertificate(url: String) {
+    func writeCertificate(host: String) {
         
         
         let directoryCertificate = CCUtility.getDirectoryCerificates()!
         let directoryCertificate = CCUtility.getDirectoryCerificates()!
-
-        if let url = URL(string: url) {
-            let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
-            if let host = urlComponents?.host {
-            
-                let certificateAtPath = directoryCertificate + "/" + host + ".tmp"
-                let certificateToPath = directoryCertificate + "/" + host + ".der"
-            
-                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)
-                }
-            }
-        }
+        let certificateAtPath = directoryCertificate + "/" + host + ".tmp"
+        let certificateToPath = directoryCertificate + "/" + host + ".der"
+    
+        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) {
     private func saveX509Certificate(_ serverTrust: SecTrust, host: String, directoryCertificate: String) {