我試圖執行與具體協議版本SSL連接,與下面的Java代碼:SSL連接
System.out.println("Locating socket factory for SSL...");
SSLSocketFactory sslsocketfactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
System.out.println("Creating secure socket to " + https_url + ":443");
SSLSocket sslSocket = (SSLSocket)sslsocketfactory.createSocket();
String []protocol = {"SSLv2Hello"};
sslSocket.setEnabledProtocols(protocol);
SocketAddress addr = new InetSocketAddress(https_url,443);
sslSocket.connect(addr);
String [] P = sslSocket.getEnabledProtocols();
System.out.println("Enabled Protocol: " + Arrays.toString(P));
運行代碼時,我得到以下異常:
Exception in thread "main" java.lang.IllegalArgumentException: SSLv2Hello cannot be enabled unless at least one other supported version is also enabled. at sun.security.ssl.ProtocolList.(Unknown Source) at sun.security.ssl.ProtocolList.(Unknown Source) at sun.security.ssl.SSLSocketImpl.setEnabledProtocols(Unknown Source) at CheckByURL.test(CheckByURL.java:36) at CheckByURL.main(CheckByURL.java:15)
當我嘗試使用其他SSL版本時,它運行良好。
有人知道如何解決這個問題嗎?
我試圖連接的服務器使用SSL v2。 當我使用SSL實驗室執行SSL測試時,似乎服務器支持SSL v2。 – user3202597