Daniel Lubryka
Daniel Lubryka

Reputation: 41

Java SSL Truststore settings

In one application i'm using three different connections by SSL. Two of them have signed certificates, but one I'm authenticating with:

System.setProperty("javax.net.ssl.trustStore","F:\\eclipse\\terefere\\testkeystore");
System.setProperty("javax.net.ssl.trustStorePassword","123456"); 

Question is - how to get rid of these settings at the end of connection so that next connection is using new server's certificate ?

Upvotes: 2

Views: 1982

Answers (1)

Arnout Engelen
Arnout Engelen

Reputation: 6897

You could of course remember the old values of these properties and re-set them after this call.

This would introduce a race condition though: if another thread makes an SSL connection while this trust store has been set, it will also use this trust store instead of the standard one.

Better would be to use this trust store for specifically this connection without touching the system properties. Whether this is easy (or even possible) depends on what library is making the SSL connection, though.

Upvotes: 1

Related Questions