Importing a self signed certificate to java cacert trust store
The following steps to be used only in non production environments.
Self signed certificates could be used in some organisations to make server to server calls between java programs on SSL. During these situations, we can import the certificate from the server jvm to client's jvm to fix the SSL handshake issue.
keytool -import -v -trustcacerts -alias test.example.com -file /tmp/localhost.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -keypass changeit -storepass changeit -noprompt
keytool -delete -alias test.example.com -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit
Self signed certificates could be used in some organisations to make server to server calls between java programs on SSL. During these situations, we can import the certificate from the server jvm to client's jvm to fix the SSL handshake issue.
On Server JVM:
Generate a self signed certificate
keytool -genkey -noprompt -alias test.example.com -dname "CN=localhost, OU=Team Name, O=Organisation Name, L=London, S=Greater London, C=UK" -ext "san=dns:test.example.com,dns:test.example.org" -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore /tmp/keystore.p12 -validity 36500 -storepass mypassword -keypass mypasswordList the certificate
keytool -list -keystore /tmp/keystore.p12 -storepass mypassword -storetype PKCS12 -vExport the certificate
keytool -exportcert -keystore /tmp/keystore.p12 -storetype PKCS12 -storepass mypassword -alias localhost -file /tmp/test.example.com.crtOn Client JVM:
List existing certificate in default trust store (cacerts)
keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeitImport the server certificate
Prefix the following command with sudo if you get permission denied error.keytool -import -v -trustcacerts -alias test.example.com -file /tmp/localhost.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -keypass changeit -storepass changeit -noprompt
List the newly imported certificate
keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -alias test.example.comDelete the newly imported certificate (after finishing the test)
Prefix the following command with sudo if you get permission denied error.keytool -delete -alias test.example.com -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit
Comments
Post a Comment