System.setProperty("javax.net.ssl.keyStorePassword", _storePwd) question

Why the system properties are not being set programmatically?

When I say does not take affect it happens only when we do things in a certain order.

For example we need to connect to URL_CACERTS and URL_KS. URL_KS connection needs the keystore properties. For URL_CACERTS we just imported their public key to cacerts.

Case 1: If we connect to URL_CACERTS first and then to URL_KS, connection to URL_KS is not successful. Somehow the setting keystore properties does not take affect. We have the following lines of code before doing the HttpURLConnection:

System.setProperty("javax.net.ssl.keyStorePassword", _storePwd);

System.setProperty("javax.net.ssl.keyStore", _keystorePath);

Case 2: If we connect to URL_KS first, and then URL_CACERTS, this sequence always works, somehow the keystore properties are set for the entire length.

So to overcome this conflict, we added the properties to the tomcat service:

If we start the tomcat service(or adding to catalina.bat) with the following parameters:

-Djavax.net.ssl.keyStorePassword=changeit

-Djavax.net.ssl.keyStore=C:\certificates\pntKS

These system properties setting takes affect, and order of conneting to URL_CACERTS or URL_KS does not matter.

My question in how is connecting to URL_CACERTS first affecting the keystore properties?

Without the above and doing the following only, its dependent on the order of connection. why?

when we do the same thing by doing this it does not take affect

System.setProperty("javax.net.ssl.keyStorePassword", _storePwd);

System.setProperty("javax.net.ssl.keyStore", _keystorePath);

Connecting to URL_CACERTS does not have any special code, we do plain HttpURLConnection and write and read from the http connection.

What is happening behind the scene? Why does order matter?

Thanks for reading.

Rumpa Giri

[1922 byte] By [rgiria] at [2007-10-2 22:00:04]
# 1
I suspect they are only read once and if someone else, e.g. Tomcat, has already used SSL before you you're out of luck. In that case you can use the programmatic solution described in the JSSE guide, where you initialize your own SSLContext, TrustManagerFactory, &c.
ejpa at 2007-7-14 1:16:17 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...