I have two applications running in the same java virtual machine, and both use different keystores and truststores.
A viable option would be use a single keystore and import all the other ones into the shared keystore (e.g. keytool -import), but it would really help my requirements if I could use separate keystores for separate applications running in the same jvm.
I could set the keystore and truststores to be used as jvm parameters or system properties as follows:
java -Djavax.net.ssl.keyStore=serverKeys
-Djavax.net.ssl.keyStorePassword=password
-Djavax.net.ssl.trustStore=serverTrust
-Djavax.net.ssl.trustStorePassword=password SSLApplication
or
System.setProperty("javax.net.ssl.keyStore","serverKeys")
But the problem with this approach is that it specifies the keystore/truststore to be used at a JVM level, thus all applications running in the same JVM gets the same keystore/truststore.
I have also tried creating a custom SSLContext and setting it as the default, but it also sets the context for all applications running in the same JVM.
SSLContext context = SSLContext.getInstance("SSL");
context.init(kms, tms, null);
SSLContext.setDefault(context);
I want to be able use different keystores/truststores without modifying individual application codes.
A solution that can dynamically register multiple key stores in addition to the default keystore/certs in jre into jvm would be great.
The solution will work in this way:
- When JVM boots, it loads all the default certs/keystores from jre/certs folder (default java behaviour when no keystores specified).
- When App 1 loads it registers its keystores,
- then when App 2 loads it registers its keystores...
Please let me know your ideas or solutions. Thanks in advance!