Hello,
I was experimenting with the following program
and I get the an SSLHandshakeException when I try to execute it.
/*
* @(#)SSLSocketClient.java 1.3 01/05/10
*
* Copyright 1995-2002 Sun Microsystems, Inc. All Rights Reserved.
*/
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
/*
* This example demostrates how to use a SSLSocket as client to
* send a HTTP request and get response from an HTTPS server.
* It assumes that the client is not behind a firewall
*/
public class SSLSocketClient {
public static void main(
String[] args) throws Exception
{
try {
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)factory.createSocket("localhost", 8443);
/*
* send http request
*
* Before any application data is sent or received, the
* SSL socket will do SSL handshaking first to set up
* the security attributes.
*
* SSL handshaking can be initiated by either flushing data
* down the pipe, or by starting the handshaking by hand.
*
* Handshaking is started manually in this example because
* PrintWriter catches all IOExceptions (including
* SSLExceptions), sets an internal error flag, and then
* returns without rethrowing the exception.
*
* Unfortunately, this means any error messages are lost,
* which caused lots of confusion for others using this
* code. The only way to tell there was an error is to call
* PrintWriter.checkError().
*/
socket.startHandshake();
// Retrieve the server's certificate chain
/* java.security.cert.Certificate[] serverCerts =
socket.getSession().getPeerCertificates();
for(int i =0 ;i < serverCerts.length ;++i)
{
System.out.println(serverCerts[i]);
}
*/
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
out.println("GET
http://localhost HTTP/1.1");
out.println();
out.flush();
/*
* Make sure there were no surprises
*/
if (out.checkError())
System.out.println(
"SSLSocketClient: java.io.PrintWriter error");
/* read response */
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
out.close();
socket.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
It works fine with hostname as
www.verisign.com.But when I change it to localhost I get the following error.
I have got
https://localhost:8443 to work with the browser.
javax.net.ssl.SSLHandshakeException: Couldn't find trusted certificate
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.b(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
Does anyone know how to disable the TrustStore Manager.
Thanks
Rupali Desai
[ August 13, 2002: Message edited by: rup desai ]