How should I do hostname validation when using JSSE?

Java 7 (and above) You can implicitly use the X509ExtendedTrustManager introduced in Java 7 using this (see this answer: SSLParameters sslParams = new SSLParameters(); sslParams.setEndpointIdentificationAlgorithm(“HTTPS”); sslSocket.setSSLParameters(sslParams); // also works on SSLEngine Android I’m less familiar with Android, but Apache HTTP Client should be bundled with it, so it’s not really an additional library. As such, … Read more

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