• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make HttpsURLConnection pick up newly added public certifica  RSS feed

Kevin Lai
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using URL, URLConnection, and HttpsURLConnection to secure an SSL enabled HTTP communication.

Here is the souce code in my Java program:
URL u = new URL("https://www.mycompany.com/cgi-bin/APerl.cgi");
HttpURLConnection connection = (HttpsURLConnection) u.openConnection();
OutputStream out = connection.getOutputStream();
wout = new OutputStreamWriter(out);
wout.write("hello, this is a test msg to HTTPS");

It works as expected:
1. If I have a trusted certificate is placed in JRE/lib/security directory, then HTTPS goes through to my CGI program
2. If I don't have the trusted certificate, then the communication fails because of a SSLHandshakeException "No trusted certificate found".

However, I have a problem: if my Java program starts without the certificate in place so the first few HTTPS connection fail, if later
a trusted certificate is added to the JRE/lib/security directory,
the same SSLHandshakeException error still happens.

It turns out that with my current program the certificate has to be there PRIOR to the start of my Java problem.

But the desired behavior is that when a correct certificate is added to the
correct security directory, the HTTPS communication starts to work.

Could someone please help me on how to "manually" re-init the SSL handshaking and/or other setup steps? I searched through HttpsURLConnection, URL, URLConnection classes but found no clue. Do I need to use other classes to perform this dynamic SSL authentication?

Thank all who help!

Kevin Lai
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!