我使用Oracle Java 8(8u112)和JDK / JRE 8的Java密码学扩展(JCE)无限强度管辖权政策文件'在Windows 7系统上。为了提高我对安全套接字的理解,我试图编写一个简单的程序,在一个线程上打开服务器套接字,然后连接到这个套接字。
我想使用TLSv1.2和使用Java keytool生成的证书。我在这个问题中使用了代码(SSLSocketFactoryEx):Which Cipher Suites to enable for SSL Socket?但我只指定了我想要使用的密码(这些也在this Oracle support page上提到):
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
TLS_EMPTY_RENEGOTIATION_INFO_SCSV
不幸的是,当我运行程序时,握手失败(请参阅下面的javax.debug.net = ssl输出)。如果我添加密码
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
一切按预期工作。似乎只有DHE_DSS(而不是ECDHE_ *)的密码才有效?有谁知道为什么以及如何解决它? JCE已经安装好了!
*** ClientHello, TLSv1.2
RandomCookie: GMT: 1469871576 bytes = { 114, 27, 128, 235, 21, 129, 252, 118, 108, 93, 245, 56, 159, 145, 94, 197, 161, 8, 37, 124, 4, 8, 58, 189, 102, 164, 83, 249 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, secp192k1, sect193r1, sect193r2, secp224k1, sect239k1, secp256k1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
***
main, WRITE: TLSv1.2 Handshake, length = 139
server, READ: TLSv1.2 Handshake, length = 139
*** ClientHello, TLSv1.2
RandomCookie: GMT: 1469871576 bytes = { 114, 27, 128, 235, 21, 129, 252, 118, 108, 93, 245, 56, 159, 145, 94, 197, 161, 8, 37, 124, 4, 8, 58, 189, 102, 164, 83, 249 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, secp192k1, sect193r1, sect193r2, secp224k1, sect239k1, secp256k1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
***
%% Initialized: [Session-1, SSL_NULL_WITH_NULL_NULL]
%% Invalidated: [Session-1, SSL_NULL_WITH_NULL_NULL]
server, SEND TLSv1.2 ALERT: fatal, description = handshake_failure
...
答案 0 :(得分:1)
事实证明我的证书是问题所在。要创建允许ECDHE的证书,您需要生成如下证书:
keytool -genkeypair -keystore localhostECDHE.jks -alias localhost -keyalg EC -keysize 256 -validity 30 -sigalg SHA512withECDSA