Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot <;本地主机>;不';t与任何主题备选名称不匹配_Spring Boot_Ssl Certificate - Fatal编程技术网

Spring boot <;本地主机>;不';t与任何主题备选名称不匹配

Spring boot <;本地主机>;不';t与任何主题备选名称不匹配,spring-boot,ssl-certificate,Spring Boot,Ssl Certificate,错误: javax.net.ssl.SSLException: Certificate for <localhost> doesn't match any of the subject alternative names: [xxxxxxx.xxx.xxxxxx.xxx] javax.net.ssl.SSLException:的证书与任何主题备选名称不匹配:[xxxxxxx.xxx.xxxxxx] 我的localhost中运行了一个Spring Boot应用程序。我还有一个通过p

错误

javax.net.ssl.SSLException: Certificate for <localhost> doesn't match any of the subject alternative names: [xxxxxxx.xxx.xxxxxx.xxx]
javax.net.ssl.SSLException:的证书与任何主题备选名称不匹配:[xxxxxxx.xxx.xxxxxx]
我的
localhost
中运行了一个Spring Boot应用程序。我还有一个通过putty连接到服务器的隧道
ssh

我所做的事情:

  • 我以各种方式手动创建/导入密钥/证书
  • 我使用keytool中的-ext将dns地址和本地主机添加到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 -keystore identity.jks -storepass secret -keypass secret -deststoretype pkcs12
一些解释:

SAN字段将用于匹配请求中提供的主机名。因此,当您在本地主机上运行应用程序时,假设您还希望向该特定主机发出请求,而该主机名在SAN字段中也应可用,否则它将在握手过程中失败

让我们以Stackoverflow为例。为了能够通过https访问stackoverflow,我们希望证书至少包含
stackoverflow.com

下面是stackoverflow的证书SAN值,在此示例中突出显示了特定的DNS:


正如您已经看到的,它还包含其他dns值。通过这种方式,网站所有者可以对多个网站/子域等使用相同的证书。

为什么备选名称包含自身stackoverflow.com?您说它包含自身是什么意思?