Is there a way to load a different cacerts than the one specified in the java_home/jre/lib/security folder?

I think you want to specify the truststore: java -Djavax.net.ssl.trustStore=/home/gene/mycacerts … Or if you are using certs through JSSE (you probably are), you can copy your truststore to jssecacerts in the $JAVA_HOME/jre/lib/security/ directory (although you’d still have to do that each time a JDK got installed/reinstalled). Sun’s JSSE looks for $JAVA_HOME/jre/lib/security/jssecacerts before $JAVA_HOME/jre/lib/security/cacerts. See http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#X509TrustManager

Why does java have both the cacerts and jssecacerts files?

From Java™ Secure Socket Extension (JSSE) Reference Guide, TrustManagerFactory uses the following steps to try to find trust material: system property javax.net.ssl.trustStore java-home/lib/security/jssecacerts java-home/lib/security/cacerts (shipped by default) I think this is based on convention over configuration concept. Without extra coding effort, cacert will be used. For extra private CA/Signing certs, a developer either can use … Read more

Keystore type: which one to use?

There are a few more types than what’s listed in the standard name list you’ve linked to. You can find more in the cryptographic providers documentation. The most common are certainly JKS (the default) and PKCS12 (for PKCS#12 files, often with extension .p12 or sometimes .pfx). JKS is the most common if you stay within … Read more

How can I use different certificates on specific connections?

Create an SSLSocket factory yourself, and set it on the HttpsURLConnection before connecting. … HttpsURLConnection conn = (HttpsURLConnection)url.openConnection(); conn.setSSLSocketFactory(sslFactory); conn.setMethod(“POST”); … You’ll want to create one SSLSocketFactory and keep it around. Here’s a sketch of how to initialize it: /* Load the keyStore that includes self-signed cert as a “trusted” entry. */ KeyStore keyStore = … Read more