Setting up a truststore without a keystore
See original GitHub issueI would like to be able to run a spring boot webserver that connects to other servers using the SSL protocol that uses self-signed certificates.
To do this I now have to specify the javax.net.ssl.trustStore
and javax.net.ssl.trustStorePassword
system properties when starting the application.
I would like to be able to set this up using my application.properties
, so that all configuration is in one place, and I can use classpath to locate the trust store.
I can specify the server.ssl.trust-store
and server.ssl.trust-store-password
but this is not picked up without also specifying server.ssl.key-store
and related properties.
The main problem then becomes that the spring boot application will start with a https connector (and no http connector), while actually I have no interest to run in https mode. The spring boot server just needs to connect to other servers with https.
My feature request is that you are able to set up a trust store without having to specify properties related to running the server in https mode.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:13
- Comments:7 (4 by maintainers)
For what it’s worth, this is how we do it. We put the self-signed server certificate in
src/main/resources
, and add a custom propertyapp.ssl.trusted-certificate-location = classpath:server.cert.pem
. We use a certificate instead of a keystore because it’s easier to export from the server.In the code, we parse the certificate and add it to a custom X509TrustManager that trusts both the default truststore and the included certificate (because we use valid certificates for production, and self-signed for staging). Then we call
SSLContext.setDefault(sslContext)
andHttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory())
. Only the former should be needed, but it seems to be ignored by IBM WebSphere, so we call the latter as well.SslConfig.java
SslProperties.java
ExtraCertsTrustManager.java
I don’t think the sample code will add much to the information already provided, but here you go. You can see in the Application.java what I would like to be able to set in the application.properties
truststore-example.zip