【问题标题】:Two way SSL failed on WatchOS2.1, but same code works on iOS9.1两种方式 SSL 在 WatchOS2.1 上失败,但相同的代码在 iOS9.1 上工作
【发布时间】:2016-02-23 04:19:09
【问题描述】:

我试图通过双向 SSL 与服务通信。

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

得到的错误是:

NSURLErrorDomain 代码=-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);
    }
}

【问题讨论】:

  • 你能显示更多代码吗?

标签: ssl ssl-certificate watchos-2 ios9.1


【解决方案1】:

经 Apple 工程师确认。 这是 Watch OS 的限制。目前不支持双向 SSL。

【讨论】:

  • 在 watchOS 5 beta 1 中仍未修复。
猜你喜欢
  • 2021-07-27
  • 2015-05-20
  • 1970-01-01
  • 1970-01-01
  • 2012-10-15
  • 1970-01-01
  • 1970-01-01
  • 2019-10-14
  • 1970-01-01
相关资源
最近更新 更多