diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-12-06 13:21:17 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-12-16 15:01:02 +0100 |
| commit | 8fc8fb15e92e7d59fb1cfc75ed9634b0a75e427f (patch) | |
| tree | 6b3e612f9106908b74401c0209c23dc7c5974d50 | |
| parent | 7cc58c4a65d3af29424622a0a9813548a505a9a8 (diff) | |
| download | mullvadvpn-8fc8fb15e92e7d59fb1cfc75ed9634b0a75e427f.tar.xz mullvadvpn-8fc8fb15e92e7d59fb1cfc75ed9634b0a75e427f.zip | |
SSLPinning: return `.rejectProtectionSpace` instead of `.cancelAuthenticationChallenge` to prevent URLError.cancelled
| -rw-r--r-- | ios/MullvadVPN/REST/SSLPinningURLSessionDelegate.swift | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/ios/MullvadVPN/REST/SSLPinningURLSessionDelegate.swift b/ios/MullvadVPN/REST/SSLPinningURLSessionDelegate.swift index d62e34d7cf..232f3bb2a1 100644 --- a/ios/MullvadVPN/REST/SSLPinningURLSessionDelegate.swift +++ b/ios/MullvadVPN/REST/SSLPinningURLSessionDelegate.swift @@ -22,22 +22,15 @@ class SSLPinningURLSessionDelegate: NSObject, URLSessionDelegate { // MARK: - URLSessionDelegate func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let evaluation: (disposition: URLSession.AuthChallengeDisposition, credential: URLCredential?) - - if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { - if let serverTrust = challenge.protectionSpace.serverTrust, self.verifyServerTrust(serverTrust) { - evaluation = (.useCredential, URLCredential(trust: serverTrust)) - } else { - evaluation = (.cancelAuthenticationChallenge, nil) - } + if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust, + let serverTrust = challenge.protectionSpace.serverTrust, + verifyServerTrust(serverTrust) { + completionHandler(.useCredential, URLCredential(trust: serverTrust)) } else { - evaluation = (.rejectProtectionSpace, nil) + completionHandler(.rejectProtectionSpace, nil) } - - completionHandler(evaluation.disposition, evaluation.credential) } - // MARK: - Private private func verifyServerTrust(_ serverTrust: SecTrust) -> Bool { |
