keytool -genkey -alias client -keyalg RSA -keystore client.jks -keysize 2048
keytool -export -alias client -file client.crt -keystore client.jks
keytool -import -v -trustcacerts -alias client -file client.crt -keystore clienttrust.jks
keytool -printcert -v -file mydomain.crt
keytool -list -v -keystore keystore.jks
keytool -list -v -keystore keystore.jks -alias mydomain
keytool -delete -alias mydomain -keystore keystore.jks
keytool -storepasswd -new new_storepass -keystore keystore.jks
keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts
keytool -import -trustcacerts -file /path/to/ca/ca.pem -alias CA_ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts
Based on source
For more info on certificates check here.
The stores can be changed using:
System.setProperty("javax.net.ssl.keyStore", "keystore.jks");
System.setProperty("javax.net.ssl.trustStore", "cacerts.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
or:
-Djavax.net.ssl.keyStore=path/to/keystore.jks
-Djavax.net.ssl.trustStore=cacerts.jks"
-Djavax.net.ssl.keyStorePassword=changeit
This isn't working on last ubuntu, here another solution
echo -n | openssl s_client -connect url:443 | openssl x509 -out /tmp/cert.crt