Background Transfer Service and Client Certificates

I can't get NSURLSession background tasks to use client certificates.


I have a simple app that creates an NSURLSessionDownloadTask from an NSURLSession that uses NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(...).

I have a custom delegate that implements:

"func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void)". For NSURLAuthenticationMethodServerTrust, I accept any server. For NSURLAuthenticationMethodClientCertificate, I have a hardcoded PKCS12 bundle with a single certificate and key from which I successfully create an NSURLCredential (using SecPKCS12Import), then pass that credential to the completion handler with .UseCredential.

At runtime, I get the didReceiveChallenge callback for ClientCertificate, then another for NSURLAuthenticationMethodServerTrust, then URLSessionDidFinishEventsForBackgroundURLSession right away without completing the TLS handshake.

If I change the NSURLSessionConfiguration to use NSURLSessionConfiguration.defaultSessionConfiguration(), the client cert is presented correctly and the download proceeds.

Both tests are done with the app in the foreground.

Hmmm, this issue cropped up in three different scenarios:

  • URLSession background sessions

  • watchOS

  • WKWebView

We’ve fixed at least two out of those three. Are you still seeing this problem with URLSession background sessions?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Ok, this is looking good now. If my tests are not wrong (it's a bit hard to match the exact requirements), the relevant delegate call urlSessionDidReceiveChallenge is now being called in a background session!

Background Transfer Service and Client Certificates
 
 
Q