JSSE Gurus : Problem with SSLSocketClientWithClientAuth

Hi

I am trying to run SSLSocketClientWithClientAuth.java which is present in samples directory.

I am running as

SSLSocketClientWithClientAuth myserver 443 login.jsp

public class SSLSocketClientWithClientAuth {

public static void main(String[] args) throws Exception {

String host = null;

int port = -1;

String path = null;

for (int i = 0; i < args.length; i++)

System.out.println(args);

if (args.length < 3) {

System.out.println(

"USAGE: java SSLSocketClientWithClientAuth " +

"host port requestedfilepath");

System.exit(-1);

}

try {

host = args[0];

port = Integer.parseInt(args[1]);

path = args[2];

} catch (IllegalArgumentException e) {

System.out.println("USAGE: java SSLSocketClientWithClientAuth " +

"host port requestedfilepath");

System.exit(-1);

}

try {

/*

* Set up a key manager for client authentication

* if asked by the server. Use the implementation's

* default TrustStore and secureRandom routines.

*/

java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");

// set proxy for running inside firewall

System.setProperty("https.proxySet","true");

System.setProperty("https.proxyHost","myproxy");

System.setProperty("https.proxyPort","80");

System.setProperty("javax.net.ssl.trustStore", "/home1/usr/jdk/jre/lib/security/mytruststore");

SSLSocketFactory factory = null;

try {

SSLContext ctx;

KeyManagerFactory kmf;

KeyStore ks;

char[] passphrase = "welcome".toCharArray();

ctx = SSLContext.getInstance("TLS");

kmf = KeyManagerFactory.getInstance("SunX509");

ks = KeyStore.getInstance("JKS");

//this keystore consists of the client's certificate ..I have

//created using keytool

ks.load(new FileInputStream("/home1/usr/jdk/jre/lib/security/clientkeystore"), passphrase);

kmf.init(ks, passphrase);

ctx.init(kmf.getKeyManagers(), null, null);

factory = ctx.getSocketFactory();

} catch (Exception e) {

throw new IOException(e.getMessage());

}

SSLSocket socket = (SSLSocket)factory.createSocket(host, port);

socket.startHandshake();

PrintWriter out = new PrintWriter(

new BufferedWriter(

new OutputStreamWriter(

socket.getOutputStream())));

out.println("GET " + path + " 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();

}

}

}

But I am getting the following exception :

java.io.IOException: Broken pipe

at java.net.SocketOutputStream.socketWrite(Native Method)

at java.net.SocketOutputStream.write(SocketOutputStream.java, Compiled Code)

at com.sun.net.ssl.internal.ssl.OutputRecord.a([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.HandshakeOutStream.flush([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.Handshaker.sendChangeCipherSpec([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.e([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.a([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.Handshaker.process_record([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a([DashoPro-V1.2-120198], Compiled Code)

at com.sun.net.ssl.internal.ssl.AppOutputStream.write([DashoPro-V1.2-120198], Compiled Code)

at java.io.OutputStream.write(OutputStream.java, Compiled Code)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake([DashoPro-V1.2-120198], Compiled Code)

at SSLSocketClientWithClientAuth.main(SSLSocketClientWithClientAuth.java, Compiled Code)

[4839 byte] By [npatha] at [2007-9-26 4:30:26]
# 1
I beleive this has got to with http://forum.java.sun.com/thread.jsp?forum=2&thread=161585
neville_sequeira at 2007-6-29 17:42:52 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...