双向 SSL 在 WatchOS2.1 上失败,但相同的代码在 iOS9.1 上有效



我试图用双向SSL与服务进行通信。

我发现在客户端(手表)通过调用completeHandler(NSURLSessionAuthChallengeUseCredential, credential)提供客户端证书后立即取消了连接

得到的错误是:

NSURLErrorDomain Code=-999 已取消

但是我尝试在手机上运行相同的代码段,它确实成功了。除此之外,其他请求在手表上工作正常。

由于WatchOS和iOS上的框架不同,我想知道这对WatchOS来说是否是一个问题?还是有什么特别需要为手表配置的?

这是代码

- (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);
    }
}

由 Apple 工程师确认。这是监视操作系统的限制。目前不支持双向 SSL。

相关内容

最新更新