Setting System property for the JVM

L

Lakshmi Ashok

I am retrieving emails from a mail box using pop3 over SSL. For that
purpose I am setting a truststore variable as a system property.

<code>
System.clearProperty("javax.net.ssl.trustStore");
Properties p = new Properties(System.getProperties());
p.put("javax.net.ssl.trustStore", "C:\\cacerts");
System.setProperties(p);
<code>

Everything works fine.

But lets say that, in my current executing thread, this parameter
needs to be altered runtime, to, Say a file in a non-existing folder,

<code>
System.clearProperty("javax.net.ssl.trustStore");
Properties p = new Properties(System.getProperties());
p.put("javax.net.ssl.trustStore", "C:\\certificates\\cacerts");
System.setProperties(p);
<code>

And, also that I delete the C:\\cacerts file to make sure the new path
is picked up...

The program fails !

I see that this property is being set only once for that JVM instance.
Any subsequent modification is not being considered.

Is this how this was designed?
 
S

Sabine Dinis Blochberger

Lakshmi said:
But lets say that, in my current executing thread, this parameter
needs to be altered runtime, to, Say a file in a non-existing folder,
[snip]
And, also that I delete the C:\\cacerts file to make sure the new path
is picked up...

The program fails !

Maybe because you try to delete a folder where you have files open?
I see that this property is being set only once for that JVM instance.
Any subsequent modification is not being considered.

Is that the only behaviour you see? Not any other errors/exceptions?
Is this how this was designed?

I don't know, have you looked it up?
 
L

Lakshmi Ashok

What i'm trying to do is to set the certificate path in the program
dynamically without restarting the Thread. Whats happening is that
whatever I set for the certificate path is being set for the first
time and the subsequent times i re-set , it just ignores it and
considers the value set the first time.

The important thing here is that either the System property is not
getting set the second time or the Java Mail API is not recognising
it.
I did not see any mention of this in any of the API docs or the Specs.

Please Let me know if the problem is clear.
 
E

EJP

Lakshmi said:
The important thing here is that either the System property is not
getting set the second time or the Java Mail API is not recognising
it.

Actually it is JSSE only reading the value once, the first time it needs it.

You need to look into defining your own SSLContext. See the
Javadoc/Guide to Features/Security/JSSE.

Alternatively, and more simply, reconsider why you need multiple
truststores. Why can't you put all your trusted certificates into the
same truststore?
 
L

Lakshmi Ashok

Yes. I decided to import all the certs into one file using the keytool
utility.
But everytime any changes are made on this file, the application needs
to be restarted.

I am yet to look into defining my own SSLContext. Let me check and
reply back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top