Last active
July 27, 2023 21:31
-
-
Save o-nnerb/67b8517cc486d1dbcc943cf77e0180bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func urlSession( | |
_ session: URLSession, | |
task: URLSessionTask, | |
didReceive challenge: URLAuthenticationChallenge, | |
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void | |
) { | |
// SERVER TRUST | |
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate { | |
guard | |
let data = try? Data(contentsOf: localClientCertificateDERURL), | |
let thePKCS12 = PKCS12(data, password: clientCertificatePFXPassword), | |
let credentials = URLCredential(PKCS12: thePKCS12) | |
else { | |
fatalError("An error occurred while attempting to import the PKCS12 data using SecPKCS12Import.") | |
} | |
completionHandler(.useCredential, credentials) | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment