【发布时间】:2014-12-17 00:45:42
【问题描述】:
我正在使用NSURLConnection 连接到具有通配符 TLS 证书(如“*.domain.com”)的服务器,当我在我的 NSURLConnectionDelegate 的 -connection:willSendRequestForAuthenticationChallenge: 方法中调用 SecTrustEvaluate 时,证书因无效而被拒绝。接受具有完全指定的 TLS 证书(如“server2.domain.com”)的另一台服务器。两个证书均由同一个 CA 颁发,我已将 CA 证书添加到设备的受信任证书列表中。
我在我的 iPhone / iOS 8.1 上看到了来自 Safari 的相同行为。具有通配符证书的服务器被报告为具有不受信任的证书,而另一台服务器工作正常。所以看起来iOS的默认证书验证拒绝通配符证书。是这样吗?
有没有办法告诉SecEvaluateTrust 允许通配符证书?这是我的-connection:willSendRequestForAuthenticationChallenge:的摘录
- (void)connection:(NSURLConnection *)connection
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust]) {
SecTrustRef trust = [challenge.protectionSpace serverTrust];
SecTrustResultType trustResult;
OSStatus status = SecTrustEvaluate(trust, &trustResult);
if (status == noErr) {
if (trustResult == kSecTrustResultProceed
|| trustResult == kSecTrustResultUnspecified) {
// Success. server2 gets here
} else {
// Server authentication failure. server1 gets here
}
}
}
}
编辑我们软件的 Android 版本可以很好地接受通配符证书,所以我怀疑这里有一些特定于 iOS 证书处理的东西。 Android 客户端使用BrowserCompatHostnameVerifier 来验证证书,据我了解,它执行与SecPolicyCreateSSL 相同的功能——执行与浏览器相同的证书检查。
【问题讨论】:
标签: ios ssl ssl-certificate nsurlconnection secure-transport