我正在测试一个 Java 应用程序。我正在尝试使用 DH 密码套件启动 SSL 握手。但我收到以下错误:
java.lang.RuntimeException: Could not generate DH keypair
有人建议BouncyCastle
,但很多人报告了它的错误,所以如果有其他选择,我不鼓励使用它。
有人建议Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files
从http://www.oracle.com/technetwork/java/javase/downloads/index.html下载。我确实替换了以下两个文件java.security
并java.policy
在C:\Program Files (x86)\Java\jre7\lib\security
. 请注意,我还注意到我已经Java\jre7\security
安装了:Program Files (x86)
并且Program Files
我都替换了。但是,我仍然看到同样的错误。
这个错误有什么解决方法吗?
编辑: 堆栈跟踪:
javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at MyClass.MyClass.myFunction(MyProg.java:78)
at MyClass.MyClass.main(MyClass.java:233)
Caused by: java.lang.RuntimeException: Could not generate DH keypair
at sun.security.ssl.DHCrypt.<init>(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverKeyExchange(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
... 4 more
Caused by: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DHKeyPairGenerator.java:120)
at java.security.KeyPairGenerator$Delegate.initialize(Unknown Source)
... 11 more
EDIT2: 我的代码充当客户端,尝试与远程服务器(网站)启动 SSL 握手。我将客户端的密码套件列表设置为:
{
"TLS_ECDHE_RSA_WITH_RC4_128_SHA",
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
"TLS_ECDHE_RSA_WITH_NULL_SHA",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA"
};
Java 支持客户端列表中的所有密码套件。当服务器提供长 DH 密钥时,如何配置 Java 客户端以支持发起 SSL 握手?