I have a java code that tries to create ssl handshake with a website. When the website's ssl certificate is self signed or using insecure option, I get errors and the code can't extract the certificate.
SSLSocket socket=null;
SSLSocketFactory factory=null;
factory = HttpsURLConnection.getDefaultSSLSocketFactory();
try{
socket = (SSLSocket) factory.createSocket(host, port);
System.out.println("listen on port "+port+" for host "+host);
} //end try
catch (IOException ex)
{
//remote host is not listening on port 443
System.out.println("Can not listen on port "+port+" of host"+host);
} //end catch
System.out.println("Creating a SSL Socket For "+host+" on port "+port);
SSLSession ss = socket.getSession();
socket.startHandshake(); // start the handshake
System.out.println("Handshake Done");
As an example, I get the following error:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Insecure renegotiation is not allowed
How can I make my java code accept completing handshake with self signed and weak ssl configurations ?