aspose file tools*
The moose likes BEA/Weblogic 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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
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);


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.
Madhavan Sundarraj
Greenhorn

Joined: Dec 22, 2004
Posts: 4
I solved the problem by muyself.

I dynamically installed the certificate using TrustManagerFactory and now it's working fine
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HttpsURLConnection - Problem in SSL Handshaking