SSL settings spring boot

岁酱吖の 提交于 2021-02-08 09:22:29

问题


I have some questions about ssl in spring boot. I have files certifications and private key with extension .crt and .key. how can I get from them right format for settings in spring boot like this

    server.ssl.key-store-type=PKCS12
    server.ssl.key-store=classpath:keystore.p12
    server.ssl.key-store-password=password 
    server.ssl.key-alias=tomcat

回答1:


To convert a certificate file and private key to PKCS#12(.p12) format, use the below command:

openssl pkcs12 -export -out certificate.p12 -inkey privateKey.key -in certificate.crt -certfile CACert.crt

Please go through the below links for your reference on dealing with https in spring boot.

  1. Enable HTTPS in Spring Boot
  2. Configure HTTP to HTTPS Redirection in Spring Boot



回答2:


I found solution. I got keystore use this comand:

    openssl pkcs12 -export -in <mycert.crt> -inkey <mykey.key> -out keystore.p12 -name <alias>

And added keystore into application.properies

    #ssl
    server.port=8443
    server.ssl.enabled=true
    server.ssl.key-store-type=PKCS12
    **server.ssl.key-store=keystore/keystore.p12**
    server.ssl.key-store-password=password
    server.ssl.key-alias=alias

It is correct config. When I use classpath:keystore.p12 it did not work. Maybe it cause that I work with spring boot 2. Then I created external folder and put inside keystore. Now it is working.



来源:https://stackoverflow.com/questions/56228577/ssl-settings-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!