4

我正在使用NSURLConnection连接到具有通配符 TLS 证书(如“*.domain.com”)的服务器,当我调用SecTrustEvaluateNSURLConnectionDelegate-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浏览器相同的证书检查功能。

4

2 回答 2

4

由于您在 Safari 上也看到了相同的行为,因此可能是证书问题或您期望证书匹配的问题。请检查(或发布)证书的详细信息以及您如何访问它。示例:仅包含 for 条目的证书*.example.com将匹配foo.example.com,但不匹配example.comor bar.foo.example.com。此外,有关名称的任何信息都应在 SAN 部分(主题替代名称)中,为此使用通用名称已被贬低。

于 2014-10-21T19:16:22.900 回答
0

我们在最新的 iOS 设备上遇到同样问题的另一个原因是:Apple 不允许在域名中使用下划线 (_)

没有下划线,一切都开始工作了。

于 2021-02-11T03:48:42.307 回答