How to debug SSL handshake errors using java program?



import javax.net.ssl.SSLSocket;


import javax.net.ssl.SSLSocketFactory;

import java.io.InputStream;

import java.io.OutputStream;



public class SSLDebugClient {


    public static void main(String[] args) {

        if (args.length != 2) {

            System.out.println("Input values: "+SSLDebugClient.class.getName()+" <host> <port>");

            System.exit(1);

        }


        try {

            SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();

            //arg0 for host and  arg1 for port

            SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(args[0], Integer.parseInt(args[1]));


            InputStream inputStream = sslSocket.getInputStream();

            OutputStream outputStream = sslSocket.getOutputStream();


            // Write test data

            outputStream.write(1);


            while (inputStream.available() > 0) {

                System.out.print(inputStream.read());

            }

            System.out.println("Connection established successfully");


        } catch (Exception exception) {

            exception.printStackTrace();

        }

    }

}


Command line: 

1.  javac SSLDebugClient.java

2. java -Djavax.net.debug=ssl,handshake -Dhttps.protocols=TLSv1.2,TLSv1.1,TLSv1 SSLDebugClient 123.test.net 443


Eclipse Run Configuration settings before running this program:





Another way to check directly from local server:

curl -v -I https://123.test.net


Comments

Popular posts from this blog

how to generate classes from swagger

How to create new user/account in BCC