spring boot https PKCS12 DerInputStream.getLength() : lengthTag=111, 太大

标签 spring spring-boot https

我需要在 https 上使用 Spring Boot 应用程序。我有一个letsencrypt签名的 key 。我将此证书转换为 PKCS12,如下所示:

openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name tomcat -CAfile chain.pem -caname root

我将此 keystore 文件复制到资源目录,这是配置部分:
require-ssl: true

server:
  port: 8443
  ssl:
    key-store-type: PKCS12
    key-store: classpath:keystore.p12
    key-store-password: xxxxx
    key-alias: tomcat

如果我检查这个 keystore ,我得到了这个:
keytool -list -keystore keystore.p12 
Keystore type: PKCS12
Keystore provider: SUN

Your keystore contains 1 entry

tomcat, May 15, 2019, PrivateKeyEntry, 
Certificate fingerprint (SHA-256): 

当我启动我的应用程序时:
Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=111, too big.
at sun.security.util.DerInputStream.getLength(DerInputStream.java:599)
at sun.security.util.DerValue.init(DerValue.java:391)
at sun.security.util.DerValue.<init>(DerValue.java:332)
at sun.security.util.DerValue.<init>(DerValue.java:345)
at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1938)
at java.security.KeyStore.load(KeyStore.java:1445)
at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:449)
at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:353)
at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:606)
at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:546)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:371)
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:763)
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:491)
at org.apache.catalina.connector.Connector.startInternal(Connector.java:986)

我需要配置任何其他吗?
谢谢,
扎梅克

最佳答案

发现问题了,我的pom.xml里面有个资源过滤插件破坏了key文件。我不得不从资源过滤器插件中排除 key 文件。

关于spring boot https PKCS12 DerInputStream.getLength() : lengthTag=111, 太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56148884/

相关文章:

java - OneToMany 映射在 Controller CRUD Spring Boot Rest API 中不起作用

java - 我正在使用 @PropertySource 和 @ConfigurationProperties 的组合,但我想用外部属性文件覆盖它们

caching - 大多数 A 级浏览器是否通过 https 将内容缓存到磁盘?

http - nginx 将所有 http 重定向到 https

java - 云类型转换: Error 402: App packaging failed: 'Application exceeds maximum allowed size (536.87MB)'

java - 当没有为 Spring JPA 标准指定值时如何避免 NPE

java - 对于其余请求,验证在 Spring boot 中不起作用

java - Android 中的 Post 请求 Spring Boot Rest 服务出现 I/O 错误

java - Spring RestTemplate 抛出异常 "Broken pipe",同时调用不同的 Rest API 同步

azure - 尝试为 Azure Web App 添加 SSL 绑定(bind)时没有证书