Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save o-nnerb/67b8517cc486d1dbcc943cf77e0180bf to your computer and use it in GitHub Desktop.
Save o-nnerb/67b8517cc486d1dbcc943cf77e0180bf to your computer and use it in GitHub Desktop.
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