【问题标题】:Spring Boot SSL IllegalArgumentException: DerInputStream.getLength(): lengthTag=109, too bigSpring Boot SSL IllegalArgumentException:DerInputStream.getLength():lengthTag=109,太大
【发布时间】:2021-10-27 00:16:57
【问题描述】:

我刚刚尝试使用此页面中的方法从 DigiCert 安装我的证书以在 SpringBootApplication 上激活 SSL:https://www.thomasvitale.com/https-spring-boot-ssl-certificate/。我是一步一步做的,但我以编程方式设置配置,而不是使用属性文件。

SpringApplication springApplication = new SpringApplication(PosDetailServer.class);
Map<String, Object> defaults = new HashMap<>();
if(args[0].equalsIgnoreCase("https")) {
    defaults.put("server.ssl.key-store", args[1]);
    defaults.put("server.ssl.key-store-password", "password");
    defaults.put("server.ssl.key-store-type", "PKCS12");
    defaults.put("server.ssl.key-alias", "tomcat");
    defaults.put("server.ssl.key-password", "password");
}
defaults.put("server.port", "8181");
springApplication.setDefaultProperties(defaults);
springApplication.run(args);

当我尝试运行它时,我得到了错误:

IllegalArgumentException:DerInputStream.getLength():lengthTag=109,太大。

步骤有什么问题?我该如何解决?

【问题讨论】:

    标签: java spring spring-boot tomcat


    【解决方案1】:

    环顾四周,我在一些信息中发现实际上是因为keytool ma​​ke a JKS 而不是 PKCS12。所以我把配置改成:

        defaults.put("server.ssl.key-store-type", "JKS");
    

    又发生了一个错误:

    java.io.IOException: 别名 tomcat 无法识别关键条目

    所以我开始寻找另一种解决方案,我找到了足够的信息,我需要在 JKS 中包含 私钥,但我没有它。但在 PKCS12 中,不需要它。所以我开始搜索如何使用现有的 crt 文件获取 PKCS12。

    最后我提出了这个问题:Adding .crt to Spring Boot to enable SSL 并且那里的答案有效,只需要稍作修改。

    所以,我只需要使用 openssl 使用我当前的 crt 文件导出 PKCS12 文件

    openssl pkcs12 -export -in <domain-name.crt> -inkey </path-to private.key> -name <alias-name> -out <domain-name.p12>
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-08
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 2017-09-05
      • 2016-08-20
      • 2020-01-13
      相关资源
      最近更新 更多