Ash*_*lix 20 encryption ssl java-7 java-security tls1.2
Server:
TLS Version: v1.2
Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA256
Client:
JRE 1.7
Run Code Online (Sandbox Code Playgroud)
当我尝试通过SSL直接从客户端连接到服务器时,我收到以下错误:
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
Run Code Online (Sandbox Code Playgroud)
以下代码启用TLSv1.2
Set<String> enabledTLSSet = new HashSet<String>(Arrays.asList(sslsocket.getEnabledProtocols()));
enabledTLSSet.add("TLSv1.2");
sslsocket.setEnabledProtocols(enabledTLSSet.toArray(new String[enabledTLSSet.size()]));
Run Code Online (Sandbox Code Playgroud)
以下代码启用了TLS_RSA_WITH_AES_256_CBC_SHA256密码套件:
Set<String> enabledCipherSuitesSet = new HashSet<String>(Arrays.asList(sslsocket.getEnabledCipherSuites()));
enabledCipherSuitesSet.add("TLS_RSA_WITH_AES_256_CBC_SHA256");
sslsocket.setEnabledCipherSuites(enabledCipherSuitesSet.toArray(new String[enabledCipherSuitesSet.size()]));
Run Code Online (Sandbox Code Playgroud)
从Java代码执行上述两个操作后,我可以通过SSL成功连接到服务器.
是否有可能使/力TLSv1.2和TLS_RSA_WITH_AES_256_CBC_SHA256Java 7中,而无需通过性能,参数或调试道具改变任何Java代码?
我尝试了所有形式和组合(启用和禁用)以及失败的所有以下属性.
-Dhttps.protocols=TLSv1.2
-Dhttps.cipherSuites=TLS_RSA_WITH_AES_256_CBC_SHA256
-Ddeployment.security.TLSv1.2=true
Run Code Online (Sandbox Code Playgroud)
我正在执行类似下面的程序:
java -jar -Dhttps.protocols=TLSv1.2 -Dhttps.cipherSuites=TLS_RSA_WITH_AES_256_CBC_SHA256 Ddeployment.security.TLSv1.2=true -Djavax.net.debug=ssl:handshake SSLPoker.jar <SERVER> 443
Run Code Online (Sandbox Code Playgroud)
SSLPoker包含以下代码:
package com.ashok.ssl;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/**
* Establish a SSL connection to a host and port, writes a byte and prints the response - Ashok Goli. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
/**
* The main method.
* Usage: $java -jar SSLPoker.jar <host> <port>
*
* @param args the arguments
*/
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: " + SSLPoke.class.getName() + " <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket =
(SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));
InputStream in = sslsocket.getInputStream();
OutputStream out = sslsocket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
System.out.println("Successfully connected");
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果没有Java代码更改如何实现这一点的任何指针将非常感激.
ped*_*ofb 18
只有使用属性时才使用简单的HTTPS连接(而不是SSL套接字)
-Dhttps.protocols=TLSv1.2
-Dhttps.cipherSuites=TLS_RSA_WITH_AES_256_CBC_SHA256
Run Code Online (Sandbox Code Playgroud)
请参阅http://fsanglier.blogspot.com.es/上的帖子
Java 7引入了对TLS v1.2的支持(参见 http://docs.oracle.com/javase/7/docs/technotes/guides/security/enhancements-7.html)但是默认情况下不启用它.换句话说,您的客户端应用程序必须在创建SSLContext时明确指定"TLS v1.2",否则将无法使用它.
如果需要使用直接安全套接字协议,请在应用程序启动时创建"TLSv1.2"SSLContext,并使用SSLContext.setDefault(ctx)调用将该新上下文注册为默认上下文.
SSLContext context = SSLContext.getInstance("TLSv1.2");
SSLContext.setDefault(context);
Run Code Online (Sandbox Code Playgroud)
小智 8
JRE默认禁用所有256位加密.要使您能够在此处下载Java Cryptography Extension(JCE)Unlimited Strength Jurisdiction Policy Files:http://www.oracle.com/technetwork/java/javase/downloads/index.html
将local_policy.jar和US_export_policy.jar jars文件替换为jre目录中的lib/security.
| 归档时间: |
|
| 查看次数: |
67625 次 |
| 最近记录: |