[英]TLS 1.2 on Java 6
我有一個在Java 6上運行的舊版應用程序。但是,由於某些安全因素,我們需要升級到TLS 1.2。 為此,我嘗試了以下代碼:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
public class TlsCheck {
/**
* test whether this client can connect to TLS v1.2 or not
*/
public static boolean isSuccessfulTLS12connection(){
try{
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
URL url = new URL("https://tlstest.paypal.com");
HttpsURLConnection httpsConnection = (HttpsURLConnection)url.openConnection();
httpsConnection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(httpsConnection.getInputStream()));
StringBuilder body = new StringBuilder();
while(reader.ready()){
body.append(reader.readLine());
}
httpsConnection.disconnect();
System.out.println("The body is::"+body.toString());
if(body.toString().equals("PayPal_Connection_OK")){
return true;
}
}catch(NoSuchAlgorithmException ne){
ne.printStackTrace();
}catch(UnknownHostException ue){
ue.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}catch(KeyManagementException ke){
ke.printStackTrace();
}
return false;
}
public static void main(String args[]){
try{
SSLParameters sslParams = SSLContext.getDefault().getSupportedSSLParameters();
System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
sslParams.setProtocols(new String[] { "TLSv1.2"});
String[] protocols = sslParams.getProtocols();
System.out.println("The Supported Protocols are::"+Arrays.asList(protocols));
}catch(NoSuchAlgorithmException ne){
ne.printStackTrace();
}
if(isSuccessfulTLS12connection()){
System.out.println("The connection to TLS v1.2 endpoint is succesful");
}else{
System.out.println("The connection to TLS v1.2 failed!");
}
}
}
但我得到以下錯誤:
The Supported Protocols are::[TLSv1.2]
javax.net.ssl.SSLException: Received fatal alert: protocol_version
The connection to TLS v1.2 failed!
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
at TlsCheck.isSuccessfulTLS12connection(TlsCheck.java:30)
at TlsCheck.main(TlsCheck.java:65)
有人可以提出比設置財產更好的方法嗎? 我也嘗試設置JVM參數,但是沒有運氣!
真正的解決辦法? 升級到Java 1.7或更高版本。 繼續運行Java 1.6 Update 45並將其連接到Internet絕對是魯re的。
多么魯ck? 非常。
因為Oracle發布了Java 1.6 Update 45的重要補丁程序更新,該更新程序 在四年前 修復了40多個安全漏洞 。
在四年前修復的那些文件中:
還有六種漏洞評級為10.0-這意味着它是一個易於利用的遠程漏洞。
這只是四年前Oracle實際上在Java 1.6 Update 45中修復的關鍵安全漏洞的列表。 在那個補丁中仍然存在的更多未解決的問題。
而且您沒有任何固定的解決方案。
重申一下 :Java 1.6 Update 45中仍然存在這些漏洞- 還有很多其他漏洞。
再次:繼續使用Java 1.6 Update 45並將其連接到Internet是魯ck的 。 Java 1.6 Update 45 至少具有25(!!!)個已知的可遠程利用的安全漏洞,CVE評分為9.3或更高。
最新的公共Java 6 SE構建為6u45,不支持TLS 1.2。 要將TLS 1.2與Java 6結合使用,我看到兩種可能性:
正如Marcel已經提到的那樣,Java 6不支持TLS。也許您可以使用curl等外部軟件作為變通辦法來通過System.exec()發出請求?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.