跳到主要内容
ecdsa.com
Java (JSSE HostnameChecker)Java

错误信息

No subject alternative names matching IP address 127.0.0.1 found

也可能输出为

  • java.security.cert.CertificateException: No subject alternative names matching IP address 127.0.0.1 found

其中的地址就是你 URL 中的地址;JDK 21 及更高版本会在异常文本前加上“(certificate_unknown) ”。对于 DNS 主机名,消息为“No subject alternative DNS name matching <host> found.”。

Java (JSSE HostnameChecker) — URL host is an IP address that is not an IP SAN of the certificate

含义

URL 中的主机是 IP 地址,而证书的主题备用名称(SAN)扩展中没有与它相等的 IP 地址条目。Java(依据 RFC 6125)只把 IP 地址与 IP SAN 条目比较;DNS 名称和通用名称永远不会与地址匹配。

原因

修复方法

  1. 1.

    使用证书中列出的 DNS 名称连接

    使用主机名,并让它解析到所需的地址;这样主机名验证就能通过。

    bash
    # Use the DNS name from the certificate; map it to the IP where needed
    echo "10.0.0.5 api.example.com" | sudo tee -a /etc/hosts
    curl -sI https://api.example.com/
  2. 2.

    签发带 IP SAN 的证书

    如果客户端必须使用地址,就把它作为 IP 条目加入(公共 CA 很少签发这类证书;私有 CA 可以)。

    bash
    # Or issue the certificate with the IP address as an IP SAN entry
    openssl req -new -key server.key -out server.csr -subj "/CN=api.example.com" \
      -addext "subjectAltName=DNS:api.example.com,IP:10.0.0.5"
    keytool -certreq -alias server -keystore server.p12 -ext "SAN=dns:api.example.com,ip:10.0.0.5" -file server.csr

相关错误

浏览完整的签名错误库