I am on a mac with Java 1.6 - this is what I found:
TrustMaterial.java launches static initialization code ->
String pathToCacerts = javaHome + "/lib/security/cacerts"; String pathToJSSECacerts = javaHome + "/lib/security/jssecacerts"; TrustMaterial cacerts = null; TrustMaterial jssecacerts = null; try { File f = new File(pathToCacerts); if (f.exists()) { cacerts = new TrustMaterial(pathToCacerts); } } catch (Exception e) { e.printStackTrace(); } try { File f = new File(pathToJSSECacerts); if (f.exists()) { jssecacerts = new TrustMaterial(pathToJSSECacerts); } } catch (Exception e) { e.printStackTrace(); } CACERTS = cacerts; JSSE_CACERTS = jssecacerts; if (JSSE_CACERTS != null) { DEFAULT = JSSE_CACERTS; } else { DEFAULT = CACERTS; }
Now, above, there is an error related to the assumption that the JAVA_HOME/lib/security/... files are valid keystores. If neither of these files is a valid repository, both CACERTS and JSSE_CACERTS are equal to zero, and this line in line 127 calls NPE because JSSE_CACERTS is null:
this.jks = CACERTS != null ? CACERTS.jks : JSSE_CACERTS.jks;
So why are both null values?
When I look at my file system:
file /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts
I get this:
/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts: broken symbolic link to /System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts
This is a symbolic link to an invalid cacerts repository. What I did was get a good copy of the JDK1.6 repository with this command:
sudo find / -name 'cacerts' 2>/dev/null
/ some / others / path / to / cacerts
Then do file /some/other/path/to/cacerts to make sure you get a valid file:
/ some / other / path / to / cacerts: Java KeyStore
Copy this to /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts to replace the broken symbolic link and make sure it is good:
file /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts
/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts: Java KeyStore
Once this is a valid keystore, this code will work.
What a pain in the ass.
mikeb source share