Search code examples
javaconfigurationssljvmrmi

How to set up SSL for Java RMI dynamically from code?


I am using Java RMI and until now just used the following VM arguments

-Djavax.net.ssl.trustStore=${workspace_loc:/ssltest/server/servertruststore.jks} 
-Djavax.net.ssl.trustStorePassword=server
-Djavax.net.ssl.keyStore=${workspace_loc:/ssltest/server/serverkeystore} 
-Djavax.net.ssl.keyStorePassword=server

and just used SslRMI socket factories for the registry and the export of the objects.
Now I want to get rid of the additional command line parameters and read that from a property file. I hoped that for that I just need to set the properties via

System.setProperty("javax.net.ssl.trustStore", "C:/servertruststore.jks");

and so on and then set up the stuff automatically (like it happens when starting with the VM arguments). What do I have to do to make that happen?

And if that is not possible, what else can I do? Do I have to create my own SSLContext with the Keystore and TrustManagers? And how do I get this context to my SslRMIFactories?


Solution

  • Yes - those parameters can be set using System.setProperty as well. The answer to how depends on your environment. If you are using an application server, there might be some configuration file to set/expose custom system properties automatically. For example, on JBoss that file is properties-service.xml under deploy folder.