我正在使用NSURLConnection
连接到具有通配符 TLS 证书(如“*.domain.com”)的服务器,当我调用SecTrustEvaluate
我NSURLConnectionDelegate
的-connection:willSendRequestForAuthenticationChallenge:
方法时,证书被拒绝为无效。接受具有完全指定的 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
浏览器相同的证书检查功能。