spring-boot - <localhost> 的证书与任何主题备用名称都不匹配

标签 spring-boot ssl-certificate

错误 :

javax.net.ssl.SSLException: Certificate for <localhost> doesn't match any of the subject alternative names: [xxxxxxx.xxx.xxxxxx.xxx]
我的 localhost 中运行了一个 Spring Boot 应用程序.我也有隧道ssh通过腻子到服务器。
我做过的事情:
  • 我手动创建/导入了所有方式的 key /证书。
  • 我使用 keytool 中的 -ext 将 dns addr 和 localhost 添加到 SAN。
  • 我也用过 openSource java文件来安装证书。
  • 我将主机文件更改为:127.0.0.1 xxx.xxx.xxxxxxx.xxx(如果我 ping dns 名称,它会响应本地主机地址)
  • 我使用 VM Arguments -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 字段将用于匹配将在请求中提供的主机名。所以当你在本地主机上运行你的应用程序时,让我们说 https://localhost:443并且您还想向该特定主机发出请求,而该主机名也应该在 SAN 字段中可用,否则它将在握手过程中失败。

    我们以 Stackoverflow 为例。为了能够通过 https 访问 stackoverflow,我们希望证书至少包含一个条目 stackoverflow.com
    下面是 stackoverflow 的证书 SAN 值,在此示例中突出显示了特定的 DNS:
    Stackoverflow certificate san values

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

    关于spring-boot - <localhost> 的证书与任何主题备用名称都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50928061/

    相关文章:

    wordpress - 从带有 WP 4.1 的 IP 地址到 wordpress 服务器的安全连接?

    eclipse - spring boot 使用 springloaded 在 gradle 中没有工作

    mysql - 如何使用 spring 应用程序中的 key 将缓存的 mysql 数据作为 redis 缓存中的单个项目读取

    spring - 在 Spring Cloud 配置客户端之间共享配置

    java - 如何使用 MongoDB 存储库在 Spring Boot 中通过 ID 以外的其他内容进行搜索

    ssl - Cloudflare ssl 错误显示 "ERR_CERT_AUTHORITY_INVALID"

    ssl - 如何获取 .cer 或 .crt 格式的公钥

    Android SSL 错误 : certificate not trusted. ..有时

    java - Junit 5 找不到测试(Spring Boot)

    ssl - 配置代理的 get_server_certificate() 的替代方法