wood burning stoves 2.0*
The moose likes Java in General and the fly likes HttpsURLConnection - Problem in SSL Handshaking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HttpsURLConnection - Problem in SSL Handshaking " Watch "HttpsURLConnection - Problem in SSL Handshaking " New topic
Author

HttpsURLConnection - Problem in SSL Handshaking

Madhavan Sundarraj
Greenhorn

Joined: Dec 22, 2004
Posts: 4
I am trying to make HttpsURLConnection, but I got javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found exception.

I included my code here

If u find anything wrong here, please let me know

System.setProperty("javax.net.debug","all");

System.setProperty("UseSunHttpHandler", "true");
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "my proxy ip");
System.setProperty("http.proxyPort", "80");

System.setProperty("java.protocol.handler.pkgs","javax.net.ssl");

String c_keystore = "madhu.keystore";
System.setProperty("javax.net.ssl.keyStore",c_keystore);
System.setProperty("javax.net.ssl.keyStorePassword","madhu123");
System.setProperty("javax.net.ssl.trustStore",c_keystore);
System.setProperty("javax.net.ssl.trustStorePassword","madhu123");

com.sun.net.ssl.internal.ssl.Provider.install();
java.security.Security.insertProviderAt(new com.sun.net.ssl.internal.ssl.Provider(), 1);

//URL url = new URL("https://myhostname/myfile.jsp");
URL url = new URL(null, "https://myhostname/myfile.jsp", new com.sun.net.ssl.internal.www.protocol.https.Handler());

HttpsURLConnection urlConn; //I tried with HttpURLConnection also
DataOutputStream printout;
BufferedReader input;
String content = "loginname=neonlines&password=password";

System.out.println("OPEN CONNECTION");

urlConn = (HttpsURLConnection)url.openConnection(); //I tried with HttpURLConnection also
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("POST");
urlConn.setFollowRedirects(true);

/******************** I commented the following lines - No need for me *************
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestProperty("Content-length", String.valueOf(content.length()));

System.out.println("OUTPUT STREAM");

printout = new DataOutputStream(urlConn.getOutputStream());
printout.writeBytes(content);
printout.flush();
******************** I commented the above lines - No need for me *************/


System.out.println("READ INPUT STREAM");

input = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); //EXCEPTION IN THIS LINE
String str;
String line = "";
System.out.println("PRINTING THE PAGE ");
while((str = input.readLine()) != null) {
System.out.println(str);
line += str;
}


I added the keystore "madhu.keystore" using keytool from x509 (extension cer)


I got the following exception

xecuteThread: '19' for queue: 'weblogic.kernel.Default', SEND TLSv1 ALERT: fatal, description = certificate_unknown
ExecuteThread: '19' for queue: 'weblogic.kernel.Default', WRITE: TLSv1 Alert, length = 2
ExecuteThread: '19' for queue: 'weblogic.kernel.Default', called closeSocket()
ExecuteThread: '19' for queue: 'weblogic.kernel.Default', handling exception: javax.net.ssl.SSLHandshakeException: sun.security.vali
dator.ValidatorException: No trusted certificate found
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275)
at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA6275)
.
.
.
.
more

Please let me know where I 'm doing wrong.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
This is much easier to use:

http://jakarta.apache.org/commons/httpclient/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpsURLConnection - Problem in SSL Handshaking
 
Similar Threads
Https problem when accessing through java programs
IDEA couldn't find trusted certificate.
Need Advice on creating a server that uses SSL!
HttpsURLConnection - Problem in SSL Handshaking
Could not find trusted certificate