CloudKit 终结点 SSL 证书主机名问题

CloudKit endpoint SSL certificate hostname issue

我正在使用 Apache HttpClient 4.5.2 发出 CloudKit Web API 请求。当我向 CloudKit 端点 URL (https://api.apple-cloudkit.com/[...]) 发送请求时,出现以下错误:

javax.net.ssl.SSLException: Certificate for <api.apple-cloudkit.com> doesn't match any of the subject alternative names: [*.icloud.com]

我不是 SSL 专家,但看起来 Apple 正在为 api.apple-cloudkit.com 提供仅对 *.icloud.com 有效的证书。我理解的对吗?

或者如果证书是正确的,那么为什么 HttpClient 会抱怨?

您使用的库或底层平台似乎不支持Server Name Indication (SNI)。如果没有 SNI,您会得到:

$ openssl s_client -connect api.apple-cloudkit.com:443 | openssl x509 -text
...
Subject: CN=*.icloud.com, 

但是当使用 SNI 时,您会得到一个不同的证书:

$ openssl s_client -connect api.apple-cloudkit.com:443 \
   -servername api.apple-cloudkit.com | openssl x509 -text
...
Subject: ...CN=cdn.apple-cloudkit.com
X509v3 Subject Alternative Name: 
  DNS:api.apple-cloudkit.com, DNS:cdn.apple-cloudkit.com

已知旧版本的 Apache HTTPClient 库缺少对 SNI 的支持,因此请确保使用最新版本。