Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 28, 2021 07:50 pm GMT

SSL certificate for java application

A third-party service is available via https, so how can java app connect to that service?

Truststore and Keystore

Java has two places for save certificate: truststore and keystore

Truststore - for client and public key
Keystore - for private key

In our task we need a truststore

Tools

For SSL certificate use such tools like openssl and keytool from jdk

Example

First of all download certificate from third-party-service.

sudo rm -f thirdPartyCert.pem && sudo echo -n | openssl s_client -showcerts -connect third-party-service:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > thirdPartyCert.pem

Copy current truststore

cp $JAVA_HOME/lib/security/cacerts currentCacerts

Import the new certificate to truststore

keytool -import -trustcacerts -keystore"currentCacerts"-aliasthird-party-service-file"thirdPartyCert.pem"-storepasschangeit

Check certificate

keytool -list -v -keystore currentCacerts -alias third-party-service -storepass changeit

Use the option to add a certificate while launching your app

-Djavax.net.ssl.trustStore=mySuperCacerts

Perfect!
Alt Text


Original Link: https://dev.to/lbatters/ssl-certificate-for-java-application-5a0o

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To