0

我正在使用 iOS 连接到使用 CN(通用名)和 FQDN(完全限定域名)的证书的服务器server.myexample.com。服务器证书由我自己的根 CA 签名(我通过使用此处SecTrustSetAnchorCertificates描述的方法将其证书添加到我的锚证书并通过验证)。NSURLAuthenticationChallenge

使用我的 iOS 客户端,我试图连接位于:的 REST 服务server.myexample.com/Path1/service1,但我一直收到以下错误:

The certificate for this server is invalid. You might be connecting to a server
that is pretending to be “server.myexample.com” which could put your confidential
information at risk.

Error occurred while fetching https://server.myexample.com/Path1/service1: Error
Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. 
You might be connecting to a server that is pretending to be “server.myexample.com” 
which could put your confidential information at risk." 

我收到具有相同信息但指定错误的其他消息:NSErrorFailingURLStringKeyNSURLErrorFailingURLPeerTrustErrorKey

我发现我也可以调用服务server.myexample.com/service1并从我的请求 URL 中删除 Path1,并且服务器证书验证工作正常。为什么是这样?我的印象是服务器只需要 1 个证书,这意味着它托管的任何服务也将使用相同的证书。也许您需要每个路径单独的服务器证书?我不知道服务器 ip 地址/域之后的路径需要拥有自己的证书。

总结一下:

  • 锚点证书中具有根 CA 证书的 iOS 客户端应用程序
  • server1由 Root CA 签署的服务器证书的 CN 为server.myexample.com,其 FQDN 为https://server.myexample.com
  • 可以通过 Web 浏览器通过以下方式访问的 服务器server.myexample.com主机:service1
    • https://server.myexample.com/service1 (通过iOS客户端对服务器的认证)
    • https://server.myexample.com/Path1/service1 (iOS 客户端对服务器的身份验证失败)
  • CA 和服务器证书是通过 OpenSSL 创建的

提前致谢!

4

0 回答 0