0

Can anybody tell me what exactly is the cause of the error?. Am trying to establish an SSL connection to a server. But connection is always failing. After requesting for logs from the server guys, i can see javax.net.ssl.SSLHandshakeException: null cert chain on their error logs. i have been trying to research what this error is and what could cause it but to no avail. i would appreciate it if someone could give me a detailed explanation on what this error is and what could cause it.

Between here is my client code i am using to connect to the server

import java.io.*;
import java.net.*;
import java.security.*;


import java.util.Enumeration;
import javax.net.ssl.*;

public class SSLConnect {

public String MakeSSlCall(String meternum) {
String message = "";
FileWriter file = null;
try {
    file = new FileWriter("C:\\SSLCERT\\ClientJavalog.txt");

} catch (Exception ee) {
    message = ee.getMessage();

}
//writer = new BufferedWriter(file );
try {
    file.write("KeyStore Generated\r\n");
    KeyStore keystore = KeyStore.getInstance("JKS");
    keystore.load(new FileInputStream("C:\\SSLCERT\\newclientkeystore"), "client".toCharArray());
    file.write("KeyStore Generated\r\n");
    Enumeration enumeration = keystore.aliases();
    while (enumeration.hasMoreElements()) {
        String alias = (String) enumeration.nextElement();
        file.write("alias name: " + alias + "\r\n");
        keystore.getCertificate(alias);
        file.write(keystore.getCertificate(alias).toString() + "\r\n");
    }
    TrustManagerFactory tmf =TrustManagerFactory.getInstance("SunX509");
    tmf.init(keystore);
    file.write("KeyStore Stored\r\n");
    SSLContext context = SSLContext.getInstance("SSL");
    TrustManager[] trustManagers = tmf.getTrustManagers();
    context.init(null, trustManagers, null);

    SSLSocketFactory f = context.getSocketFactory();
    file.write("About to Connect to Ontech\r\n");
    SSLSocket c = (SSLSocket) f.createSocket("192.168.1.16", 4447);
    file.write("Connection Established to 196.14.30.33 Port: 8462\r\n");
    file.write("About to Start Handshake\r\n");
    c.startHandshake();

    file.write("Handshake Established\r\n");
    file.flush();
    file.close();
    return "Connection Established";
}
 catch (Exception e) {
    try {
        file.write("An Error Occured\r\n");
        file.write(e.getMessage() + "\r\n");
        file.flush();
        file.close();
    } catch (Exception eee) {
        message = eee.getMessage();
    }
    return "Connection Failed";
}
}
}

My Keytool commands for generating a Truststore and importing the servers certificate and my own certificate

Keytool commands for creating my truststore

keytool -import -alias client -file client.cer -keystore MyKeystore -storepass mystore

keytool -import -alias server -file server.cer -keystore MyKeystore -storepass mystore

Obafemi Tayo
  • 73
  • 1
  • 6
  • 16
  • Possible duplicate of [Restlet javax.net.ssl.SSLHandshakeException: null cert chain](http://stackoverflow.com/questions/32506278/restlet-javax-net-ssl-sslhandshakeexception-null-cert-chain) – ulab Feb 21 '17 at 10:32
  • @ulab That post doesnt answer my question. I want to know what that error actually mean, why is that error thrown and possibly solutions to it. There are no documentations on this exception and its quite depressing. – Obafemi Tayo Feb 21 '17 at 11:07
  • Did you enable SSL debug `-Djavax.net.debug=ssl:handshake` ? It is certainly have to do with certificates in question. – ulab Feb 21 '17 at 16:03

0 Answers0