错误 :
javax.net.ssl.SSLException: Certificate for <localhost> doesn't match any of the subject alternative names: [xxxxxxx.xxx.xxxxxx.xxx]
我的 localhost
中运行了一个 Spring Boot 应用程序.我也有隧道ssh
通过腻子到服务器。我做过的事情:
我错过了什么?顺便说一句,我也在使用 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 -keystore identity.jks -storepass secret -keypass secret -deststoretype pkcs12
一些解释:
SAN 字段将用于匹配将在请求中提供的主机名。所以当你在本地主机上运行你的应用程序时,让我们说 https://localhost:443并且您还想向该特定主机发出请求,而该主机名也应该在 SAN 字段中可用,否则它将在握手过程中失败。
我们以 Stackoverflow 为例。为了能够通过 https 访问 stackoverflow,我们希望证书至少包含一个条目
stackoverflow.com
下面是 stackoverflow 的证书 SAN 值,在此示例中突出显示了特定的 DNS:
正如您已经看到的,它还包含其他 dns 值。通过这种方式,网站所有者可以为多个网站/子域等使用相同的证书。
关于spring-boot - <localhost> 的证书与任何主题备用名称都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50928061/