在localhost中测试TLS:证书对给定域无效

问题描述 投票:0回答:1

我正试图用我个人电脑上运行的spring boot应用程序测试SSL。我使用keytool生成了一个PKCS12证书,参数如下。

CN = localhost:8080
OU = localhost:8080
O = localhost:8080
L = Galle
S = Galle
C = LK

我配置了我的应用程序来使用这个证书,并将这个自签名证书安装到我的chrome浏览器中。

enter image description here

当我试图访问我的 API 端点 (https:/localhost:8080apimetadivisions。)使用chrome扩展的Advanced REST客户端,我收到一个错误信息,说是

Certificate is invalid for given domain
Certificate presented to the app has different CN (common name) than the domain of the request.

这个错误的原因是什么,如何才能狐疑?

ssl ssl-certificate tls1.2 keytool self-signed-certificate
1个回答
0
投票

当使用127.0.0.1作为CN并在生成自签名证书时填写SAN扩展名时,这种情况得到了解决。


0
投票

我试图重现同样的行为,最初我的chrome也阻止了这个页面。看来google不允许使用localhost:8080作为CN名。

如果你尝试以下命令。

keytool -genkeypair -keyalg RSA -keysize 2048 -alias server -dname "CN=abcd,OU=efgh,O=ijkl,C=Galle" -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -validity 3650 -keystore identity.jks -storepass secret -keypass secret -deststoretype pkcs12

用你自己的值在你的应用程序中添加以下弹簧属性。

server:
  port: 8443
  ssl:
    enabled: true
    key-store: classpath:identity.jks
    key-password: secret
    key-store-password: secret

从keystore导出证书,并添加到你的机器或chrome中,它应该可以工作。要提取证书,你可以使用以下命令。

keytool -exportcert -keystore identity.jks -storepass secret -alias server -rfc -file server.cer

你能用上面的步骤重试一下吗?

© www.soinside.com 2019 - 2024. All rights reserved.