Java 6上的TLS 1.2
我有一个在java 6上运行的遗留应用程序。但是,由于某些安全因素,我们需要升级到TLS 1.2。 为此,我曾尝试下面的代码: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 6 SE版本是6u45,它不支持TLS 1.2。要在Java 6中使用TLS 1.2,我看到两种可能性:
- Oracle提供付费Java SE Advance程序。在此,构建6u141可用于TLS 1.2支持:http://www.oracle.com/technetwork/java/javase/overview-156328.html#R160_141
- 尝试Bouncy Castle库。您可以在此找到答案示例实现:https://*.com/a/33122393/7059880
马塞尔已经提到的,是Java 6没有TLS支持也许你可以使用外部软件,如卷曲作为一种解决方法,使系统与您的要求。 exec()?
真正的修复?升级到Java 1.7或更高版本。继续运行Java 1.6 Update 45并将其连接到Internet是专业的鲁莽。
鲁莽如何?非常。
因为Oracle在四年前发布了a critical patch update for Java 1.6 Update 45fixed over 40 security vulnerabilities。
在这些四年前固定:此漏洞的
- CVE-2413至62年成功的攻击会导致未经授权的操作系统包括收购执行任意代码。
- CVE-2013-2463易于被利用的漏洞允许通过多种协议成功进行未经验证的网络攻击。成功攻击此漏洞可能导致未经授权的操作系统接管,包括任意代码执行。
- CVE-2013-2464易受攻击的漏洞允许通过多种协议成功进行未经验证的网络攻击。成功攻击此漏洞可能导致未经授权的操作系统接管,包括任意代码执行。
- CVE-2013-2465易受攻击的漏洞允许通过多种协议成功进行未经验证的网络攻击。成功攻击此漏洞可能导致未经授权的操作系统接管,包括任意代码执行。
- CVE-2013-2466易受攻击的漏洞允许通过多种协议成功进行未经身份验证的网络攻击。成功攻击此漏洞可能导致未经授权的操作系统接管,包括任意代码执行。
- CVE-2013-2468易受攻击的漏洞允许通过多种协议成功进行未经验证的网络攻击。成功攻击此漏洞可能导致未经授权的操作系统接管,包括任意代码执行。
而且SIX更是有10.0漏洞等级 - 这意味着它是一个容易利用的远程漏洞。
这只是Oracle四年前在Java 1.6 Update 45中实际修复的严重安全漏洞列表。还有更多的东西在那个仍然存在的补丁中没有修复。
而你没有其中任何被修正。
重申:这些漏洞 - and a whole lot more - 在Java 1.6的更新仍然存在45
还是那句话:继续使用Java 1.6更新45,并将其连接到互联网是鲁莽。 Java 1.6 Update 45有至少25(!!!)已知可远程利用安全漏洞,CVE得分为9.3或更高。