java 如何使用 Spring Boot 配置受信任的 SSL 密钥库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44958116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:25:26  来源:igfitidea点击:

How to Configure trusted SSL keystore with Spring boot?

javaspring-bootspring-securityhttpsssl-certificate

提问by Speise

Want to introduce HTTPS protocol (trusted certificate) to my Spring Boot(1.3.2.RELEASE) application. For this purpose tried next SSL properties:

想在我的 Spring Boot(1.3.2.RELEASE) 应用中引入 HTTPS 协议(可信证书)。为此,尝试了下一个 SSL 属性:

server.ssl.trust-store=classpath:key.jks
server.ssl.trust-store-password=pass

and have the error:

并有错误:

Caused by: java.lang.IllegalArgumentException: Resource location must not be null
at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:131) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.configureSslKeyStore(TomcatEmbeddedServletContainerFactory.java:340) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.configureSsl(TomcatEmbeddedServletContainerFactory.java:323) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]

In that error you can see that configureSslKeyStoreshould be passed. When I am trying to launch the application with next set of changes:

在该错误中,您可以看到应该传递configureSslKeyStore。当我尝试使用下一组更改启动应用程序时:

server.ssl.key-store=classpath:key.jks
server.ssl.key-store-password=pass
server.ssl.trust-store=classpath:key.jks
server.ssl.trust-store-password=pass

Application starts successfully but https is not reachable: enter image description here

应用程序成功启动但无法访问 https: 在此处输入图片说明

So now I have several questions:

所以现在我有几个问题:

  • What can be the reason of such behavior, that protocol is unsupported?(Certificate is fresh and not outdated)
  • Is it correctly that there is no way to configure trusted certificate without redundant properties?
  • Is there some other more convenient way to configure trusted SSL?
  • 这种行为的原因是什么,该协议不受支持?(证书是新的,没有过时)
  • 没有冗余属性就无法配置可信证书是否正确?
  • 有没有其他更方便的方法来配置受信任的 SSL?

UPDATE:

更新:

It is JAR file and certificate exists inside of it classpath:key.jks"".

它是 JAR 文件,证书存在于其中 classpath:key.jks""。

回答by Speise

The reason was in my .jks file. It was generated in a wrong way. Here is the linkwhere you can find the correct structure of storekeys.

原因在我的 .jks 文件中。它以错误的方式生成。这里是链接在这里您可以找到storekeys的正确结构。