File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes How to make HttpsURLConnection pick up newly added public certifica Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "How to make HttpsURLConnection pick up newly added public certifica" Watch "How to make HttpsURLConnection pick up newly added public certifica" New topic
Author

How to make HttpsURLConnection pick up newly added public certifica

Kevin Lai
Greenhorn

Joined: Sep 01, 2004
Posts: 1
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();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
OutputStream out = connection.getOutputStream();
wout = new OutputStreamWriter(out);
wout.write("hello, this is a test msg to HTTPS");
wout.flush();
wout.close();

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
chlai@lucent.com
 
 
subject: How to make HttpsURLConnection pick up newly added public certifica