March 10, 2021 in Tutorial2 minutes
In this tutorial we will test the behaviour of javax.net.ssl.trustStore
option. The objective is to check whether -Djavax.net.ssl.trustStore
option append or replace the default java keystore being used by java.
Install openjdk-8-jdk on Ubuntu 16.04
sudo apt-get install openjdk-8-jdk
Create HttpsUrlReader
app. Source code can be found in this link.
Check connections without providing custom keystore (both will succeed)
java HttpsUrlReader https://icanhazip.com
java HttpsUrlReader https://helloworld.letsencrypt.org
Remove Let’s Encrypt Root certificates
sudo keytool -delete -alias debian:isrg_root_x1.pem -keystore /etc/ssl/certs/java/cacerts
sudo keytool -delete -alias debian:dst_root_ca_x3.pem -keystore /etc/ssl/certs/java/cacerts
Note: To search alias we can list all certificates inside keystore using command below.
keytool -list -v -keystore /etc/ssl/certs/java/cacerts | grep Alias
Check connection without providing custom keystore (icanhazip.com will succeed, helloworld.letsencrypt.org will fail)
java HttpsUrlReader https://icanhazip.com
java HttpsUrlReader https://helloworld.letsencrypt.org
Download ISRG And DST / TrustID Root
wget -c https://raw.githubusercontent.com/letsencrypt/website/master/static/certs/isrgrootx1.pem
wget -c https://raw.githubusercontent.com/letsencrypt/website/master/static/certs/trustid-x3-root.pem
Add ISRG and DST root to new keystore named customKeystore
keytool -import -trustcacerts -alias debian:isrg_root_x1.pem -file isrgrootx1.pem -keystore customKeystore
keytool -import -trustcacerts -alias debian:dst_root_ca_x3.pem -file trustid-x3-root.pem -keystore customKeystore
A new keystore customKeystore
will be created in the current working directory.
Check connection using new customKeystore
. Let’s encrypt will succeed, icanhazip.com will fail
java -Djavax.net.ssl.trustStore=customKeystore -Djavax.net.debug=ssl HttpsUrlReader https://icanhazip.com
java -Djavax.net.ssl.trustStore=customKeystore HttpsUrlReader https://helloworld.letsencrypt.org
When we provide javax.net.ssl.trustStore
option to java application, the default keystore will not be used. The custom trust store passed by javax.net.ssl.trustStore
option replace the default keystore.