1

I'm using Oracle Java 8 (8u112) with the 'Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE 8' on a Windows 7 system. To improve my understanding of secure sockets, I'm trying to write a simple program which opens a server socket on a thread and then connects to this socket.

I want to use TLSv1.2 and a certificate generated with the Java keytool. I'm using the code (SSLSocketFactoryEx) from this question: Which Cipher Suites to enable for SSL Socket? but I only specify the ciphers I want to use (These are also mentioned on 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

Unfortunately, handshaking fails when I run my program (see below for javax.debug.net=ssl output). If I add the cipher

TLS_DHE_DSS_WITH_AES_256_CBC_SHA256

everything works as expected. It seems that only ciphers with DHE_DSS (and not ECDHE_*) work?? Anybody knows why and how to fix it? JCE is already installed!

*** 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
...
jww
  • 97,681
  • 90
  • 411
  • 885
Jeroen
  • 61
  • 4
  • Related, see [Which Cipher Suites to enable for SSL Socket?](https://stackoverflow.com/q/1037590/608639) – jww Feb 28 '18 at 23:16

1 Answers1

1

It turns out my certificate was the problem. To create a crtificate which allows ECDHE, you need to generate a certificate like this:

keytool -genkeypair -keystore localhostECDHE.jks -alias localhost -keyalg EC -keysize 256 -validity 30 -sigalg SHA512withECDSA
Jeroen
  • 61
  • 4