tags:

views:

51

answers:

2

Hi,

I was playing with security in Java and Tomcat and I came to the point where I was curious which keystore/truststore was loaded by the JVM at the end. Even though I had my own keystore created and in Tomcat configuration, this was used both as keystore and trustore, the reality was that default cacerts file was loaded as truststore (as keystore, my file was used properly).

I was trying to get the name of the file that JVM loads, but I haven't found the solution. My idea was to get System.getProperty("javax.net.ssl.keyStore") but this gave me null. I tried to set this both in Tomcat's server.xml via Connector and as a command line parameter -Djavax.net.ssl.keyStore="file". I am sure that the command line parameter was provided correctly as I am setting JMX paramneters at the same place.

br, Martin

+1  A: 

Are you on Tomcat 6?

I've tried setting this in catalina.bat as

set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG% -Djavax.net.ssl.keyStore="path-to-file"

and it reflects in my code used as System.getProperty("javax.net.ssl.keyStore")

Also, for your info, there was a Bugzilla on other SSL attributes being ignored which was fixed in 6.0.16. keyStore is not specifically mentioned there, but my version is 6.0.20 and it works

JoseK
The version I have tried was 6.0.26. The way I am setting the parameters is to set JAVA_OPTS in setenv.(sh|bat).
Martin
A: 

You won't necessarily be able to get exactly what you want from the file name of even the type and setting the keystore in the connector will have absolutely no effect on the system property.

In addition, the keystore, whether specified from the javax.net.ssl.keyStore property or instantiated explicitly is only one part of the setup of the KeyManager and the SSLContext. (By default, Apache Tomcat will use files and a relatively simple loading mechanism, but it's also possible to customize this using Tomcat's SSLImplementation.) If you really want to see what's being loaded, I would look at the JSSE debugging flags, more specifically, something like this:

-Djavax.net.debug=SSL,keymanager,trustmanager

EDIT: I should add that there is no default keystore generally speaking (outside the context of Tomcat), only a default truststore. Tomcat's JSSEImplementation uses System.getProperty("user.home") + "/.keystore" by default.

Bruno
One thing that can be confusing in Tomcat is that the keystore file is configured using the `keystore` attribute whereas the truststore file is configured using the `truststoreFile` attribute.
Bruno
I had the bellow listed config, but trusted certificates were loaded from cacerts in JRE/lib/security.keystoreFile="conf/keystore.jks" truststoreFile="conf/keystore.jks"
Martin
Try using `keystore=` instead of `keystoreFile=` (but keep `truststoreFile`).
Bruno