marinofaggiana 3 years ago
parent
commit
f11556a9bd
1 changed files with 8 additions and 6 deletions
  1. 8 6
      iOSClient/Networking/NCNetworking.swift

+ 8 - 6
iOSClient/Networking/NCNetworking.swift

@@ -225,6 +225,7 @@ import Queuer
     private func checkTrustedChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge) -> Bool {
         
         var trusted = false
+        var trustedV2 = false
         let protectionSpace: URLProtectionSpace = challenge.protectionSpace
         let directoryCertificate = CCUtility.getDirectoryCerificates()!
         let directoryCertificateUrl = URL.init(fileURLWithPath: directoryCertificate)
@@ -260,7 +261,6 @@ import Queuer
                     let data = CFDataGetBytePtr(serverCertificateData);
                     let size = CFDataGetLength(serverCertificateData);
                     let certificate = NSData(bytes: data, length: size)
-                    var certificateSavedFound = true
                     
                     // write certificate tmp to disk
                     let certificatePath = directoryCertificate + "/" + NCGlobal.shared.certificateTmpV2
@@ -269,13 +269,11 @@ import Queuer
                     let certificateSavedPath = directoryCertificate + "/" + host + ".der"
                     if let certificateSaved = NSData(contentsOfFile: certificateSavedPath) {
                         if certificate.isEqual(to: certificateSaved as Data) {
-                            trusted = true
+                            trustedV2 = true
                         }
-                    } else {
-                        certificateSavedFound = false
                     }
                     
-                    if !trusted && certificateSavedFound {
+                    if !trusted && !trustedV2 {
                         #if !EXTENSION
                         DispatchQueue.main.async {
                             let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -287,7 +285,11 @@ import Queuer
             }
         }
         
-        return trusted
+        if trusted || trustedV2 {
+            return true
+        } else {
+            return false
+        }
     }
     
     func writeCertificate(url: String) {