Hi everyone,



I am new to JSSE and I have to develop a java client that is going to send and receive data to a https server. I am using java version "1.4.2_04" on windows XP. The administrator on the server side has given me a file called "cacerts.pem" , I assume this is certificate, and another one called "nat.cer". I have written my client as follows :



import java.net.*;
import javax.net.ssl.*;
import java.util.*;
import javax.net.*;
import java.io.*;
import java.security.*;
import java.security.cert.X509Certificate;

public class TestHttpsClient {




public static void main(String[] args) {
try
{

//String natis_url = "https://servername:8443/";

//initialising the string to send.
String send_string = "string t send to the server ";

//verify if the hostname exixts
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: "+urlHostName+" vs. "+session.getPeerHost());
return true;
}
};

HttpsURLConnection.setDefaultHostnameVerifier(hv);


System.out.println("connect.....");

URL url = new URL("https://servername:8443/");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

System.out.println("POST parameters.....");
String parms = send_string;
byte[] bytes = parms.getBytes();

conn.setRequestMethod("POST");
conn.setRequestMethod(send_string);
conn.setRequestProperty("Content-type", "text/xml");

conn.setDoInput(true);
conn.setDoOutput(true);
PrintWriter out_write = new PrintWriter(new BufferedOutputStream(conn.getOutputStream()));
out_write.println(parms);


OutputStream out = conn.getOutputStream();
out.write(bytes);
out.flush();
out.close();


System.out.println("response........");

BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = reader.readLine();

do {
System.out.println(response);
response = reader.readLine();
} while (response != null);


System.out.println("OK");

}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e);
//serverSocket.close();
}

}



The code compiles fine, and when I try to run it, I get the following error :

c:\_dev> java TestHttpsClient

POST parameters.....
Warning: URL Host: servername vs. servername
response........
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.b(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.b(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.AppInputStream.read(DashoA6275)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:222)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:756)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:711)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:626)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Dash
oA6275)
at NatisHttpsClient.main(TestHttpsClient.java:66)
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure


I have read through the postings on the net over the past week and haven't been succesfull in getting any where. My main problem is how to tell my program of "nat.cer" of "cacert.pem".



Please help

Nthoethatha