@Youraj
How to do what is said above
Typically a barebones example of this would look something like:
extension ViewController: URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
if let secTrustRef = challenge.protectionSpace.serverTrust {
let host = challenge.protectionSpace.host
let sslPolicy = SecPolicyCreateSSL(true, host as CFString)
SecTrustSetPolicies(secTrustRef, sslPolicy)
var error: CFError?
if !SecTrustEvaluateWithError(secTrustRef, &error) {
print("SecTrustEvaluateWithError failed: \(error.debugDescription)")
// Decide whether to do further evaluation on the certificate or fail immediately
// completionHandler(.cancelAuthenticationChallenge, nil)
}
if let trustDetails = SecTrustCopyResult(secTrustRef) as? [String: AnyObject] {
// Extract - trustDetails[kSecTrustCertificateTransparency as String]
// Extract - trustDetails[kSecTrustRevocationValidUntilDate as String]
}
// Proceed with the completion handler or extracting any other data from
// secTrustRef or from the server's certificates.
}
}
completionHandler(.cancelAuthenticationChallenge, nil)
}
}
However there can be much more functionality added here based on your app's requirements.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com