Two way SSL failed on WatchOS2.1, but same code works on iOS9.1

220 Views Asked by At

I was trying to communicate with a service with two way SSL.

I found the connection was cancelled immediately after the client (watch) provide the client certificate, by calling completeHandler(NSURLSessionAuthChallengeUseCredential, credential)

The error got is:

NSURLErrorDomain Code=-999 cancelled

But I've tried run the same piece of code on a phone, it did succeed. Apart from that, other requests work fine on the watch.

Since, the frameworks on WatchOS and iOS are different, I am wondering if that might be an issue for WatchOS? Or is there anything specifically need to be configured for the watch?

Here is the code

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
    NSURLProtectionSpace *protectionSpace = [challenge protectionSpace];
    NSString *authMethod = [protectionSpace authenticationMethod];
    if (authMethod == NSURLAuthenticationMethodServerTrust) {
        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:serverTrust]);
    } else if (authMethod == NSURLAuthenticationMethodClientCertificate) {
        // cancelled immediately after calling the method below.
        completionHandler(NSURLSessionAuthChallengeUseCredential, self.credential);
    } else {
        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
    }
}
1

There are 1 best solutions below

1
On

Confirmed by Apple engineer. It is an restriction of Watch OS. Two way SSL is not supported for now.