我有一個Java代碼,試圖與網站創建ssl握手。當網站的SSL證書是自簽名的或使用不安全的選項時,我會收到錯誤,並且代碼無法提取證書。如何讓我的java代碼接受完成握手與自簽名或弱sslv2協議
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配置握手?
可能的重複[如何接受與Java HttpsURLConnection的自簽名證書?](http://stackoverflow.com/questions/859111/how-do-i-accept-a-self-signed-certificate -with-a-java-httpsurlconnection) –
在問題中沒有證據表明您需要支持SSLv2。 – EJP