title: JMX SSL connection without setting javax.net.ssl.trustStore as a system property
body: <p>I'm trying to protect my JMX connection with SSL, for being able to do that I'm specifying java trust store and key store by setting java system properties, here's the code snippet:</p>
  
  <pre><code>    HashMap&lt;String,Object&gt; env = new HashMap&lt;String,Object&gt;();
  
      // check if jmx ssl config file exists
      if(checkIfFileExists(JMX_SSL_CONFIG)) {
          String keyStore = null;
          String keyStorePassword = null;
          String trustStore = null;
          String trustStorePassword = null;
          Properties prop = new Properties();
          InputStream input = null;
          input = new FileInputStream(JMX_SSL_CONFIG);
          prop.load(input);
          keyStore = prop.getProperty("javax.net.ssl.keyStore");
          keyStorePassword = prop.getProperty("javax.net.ssl.keyStorePassword");
          trustStore = prop.getProperty("javax.net.ssl.trustStore");
          trustStorePassword = prop.getProperty("javax.net.ssl.trustStorePassword");
          System.setProperty("javax.net.ssl.trustStore", trustStore);
          System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
          System.setProperty("javax.net.ssl.keyStore", keyStore);
          System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
  
          env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
  
      }
  
     JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
  </code></pre>
  
  <p>The problem is that I don't want to set trust store/key store by setting system properties, as it breaks some other thing in my system. I want to somehow pass them via SslRMIClientSocketFactory or maybe SslRMIServerSocketFactory. I know that JMX connection works via RMI call which means that client socket implementation is actually provided by the server, so I have to somehow pass the trust store and key store to server object but cannot find a way do to it.</p>