错误:
javax.net.ssl.SSLException: Certificate for <localhost> doesn't match any of the subject alternative names: [xxxxxxx.xxx.xxxxxx.xxx]
我的 Spring Boot 应用程序正在运行localhost
。我也有隧道ssh
通过腻子到服务器。
我做过的事情:
- 我以各种方式手动创建/导入密钥/证书。
- 我使用 keytool 中的 -ext 将 dns addr 和 localhost 添加到 SAN。
- 我也用过一个开源java 文件来安装证书。
- 我将主机文件更改为:127.0.0.1 xxx.xxx.xxxxxxx.xxx(如果我 ping dns 名称,它会响应本地主机地址)
- 我使用 VM 参数 -Djavax.net.debug=ssl 来检查证书是否正确加载。
我缺少什么?顺便说一句,我也在使用 VPN。
创建证书时,您需要提供 localhost 作为使用者备用名称。您可以通过提供以下附加参数来做到这一点:-ext "SAN:c=DNS:localhost,IP:127.0.0.1"
所以像这样:
keytool -genkeypair -keyalg RSA -keysize 2048 -alias stackoverflow \
-dname "CN=stackoverflow,OU=Hakan,O=Hakan,C=NL" \
-ext "SAN:c=DNS:localhost,IP:127.0.0.1" -validity 3650 \
-storepass <password> -keypass <password> \
-keystore identity.jks -deststoretype pkcs12
一些解释:
SAN 字段将用于匹配请求中提供的主机名。因此,当您在本地主机上运行应用程序时,可以说https://localhost:443
,并且您还想向该特定主机发出请求,那么该主机名也应该在 SAN 字段中可用;否则会在握手过程中失败。
让我们以 Stackoverflow 为例。为了能够通过 https 访问 stackoverflow,我们期望证书应至少包含以下条目stackoverflow.com
Below is the certificate SAN value of stackoverflow with the specific DNS highlighted for this example:
正如您所看到的,它还包含其他 DNS 值。通过这种方式,网站所有者可以对多个网站/子域等使用相同的证书。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)