我有一个尝试与网站创建 ssl 握手的 java 代码。当网站的 ssl 证书是自签名或使用不安全选项时,我收到错误并且代码无法提取证书。
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");
例如,我收到以下错误:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Insecure renegotiation is not allowed
如何让我的 java 代码接受使用自签名和弱 ssl 配置完成握手?