NSURLErrorClientCertificateRejected when only matching client certificate is expired in WebKit
0 reputation · 17 May 2025, 18:04 UTC
0 reputation · 17 May 2025, 18:04 UTC
When a TLS server requests a client certificate during mutual authentication, WebKit's NSURLSession presents identities from the Keychain that match the server's trusted CA list. If the only matching certificate has expired, the authentication challenge fails with NSURLErrorClientCertificateRejected (-1205) and no system-provided fallback UI appears to let the user select an alternative valid certificate.
This behavior stems from WebKit's certificate selection logic in AuthenticationCF.cpp, which does not automatically retry the challenge with other Keychain identities. The Keychain enforces least-privilege access through ACLs requiring user consent per identity, yet the embedding application (Safari) does not expose a certificate picker for expired-credential scenarios. Enterprise MDM profiles can pre-provision certificates and modify ACLs, further complicating the fallback decision.
31775 reputation · 18 May 2025, 00:00 UTC
When a TLS server requests a client certificate for mutual authentication and the only identity matching the server's trusted Certificate Authorities in the Keychain has expired, WebKit's NSURLSession presents that credential and the handshake fails with NSURLErrorClientCertificateRejected (-1205). No system‑level certificate picker appears because the Security framework treats the expired match as a validation failure rather than an ambiguous selection requiring user input.
The error code -1205 is returned by the Security framework when a client certificate is presented but fails server validation, typically due to expiration. The standard delegate method URLSession:didReceiveChallenge:completionHandler: is the only portable way to intercept and re‑issue the challenge.
NSURLSessionDelegate method and catch NSURLAuthenticationMethodClientCertificate.SecIdentityCopyCertificate / Keychain APIs to enumerate identities matching the server's CA list.SecCertificate's notAfter date against the current time; exclude expired credentials.URLCredential from the selected identity and pass it to the completion handler.Are you observing this behavior in a custom WKWebView / NSURLSession implementation or within the standalone Safari browser? The answer determines whether Safari's internal handling applies or whether you must supply the delegate logic yourself.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.