@@ -68,18 +68,31 @@ public class SSL {
6868 static { configureJSSE (); }
6969
7070 private static void configureJSSE () {
71- final String ephemeralDHKeySize = "jdk.tls.ephemeralDHKeySize" ;
72- try {
73- if ( System .getProperty (ephemeralDHKeySize ) == null ) {
74- // The key size is the same as the authentication certificate,
75- // but must be between 1024 bits and 2048 bits, inclusively.
76- // However, the SunJCE provider only supports 2048-bit DH keys larger
77- // than 1024 bits. Consequently, you may use the values 1024 or 2048 only.
78- System .setProperty (ephemeralDHKeySize , "matched" ); // only affects Java 8
71+ if ( OpenSSL .javaVersion8 (true ) ) { // >= 1.8
72+ final String ephemeralDHKeySize = "jdk.tls.ephemeralDHKeySize" ;
73+ try {
74+ if ( System .getProperty (ephemeralDHKeySize ) == null ) {
75+ // The key size is the same as the authentication certificate,
76+ // but must be between 1024 bits and 2048 bits, inclusively.
77+ // However, the SunJCE provider only supports 2048-bit DH keys larger
78+ // than 1024 bits. Consequently, you may use the values 1024 or 2048 only.
79+ System .setProperty (ephemeralDHKeySize , "matched" ); // only on Java 8
80+ }
81+ }
82+ catch (SecurityException ex ) {
83+ OpenSSL .debug ("setting " + ephemeralDHKeySize + " failed: " + ex );
7984 }
8085 }
81- catch (SecurityException ex ) {
82- OpenSSL .debug ("setting " + ephemeralDHKeySize + " failed: " + ex );
86+ else { // on JDK 7 DHE is weak - disable completely (unless user-set)
87+ final String disabledAlgorithms = "jdk.tls.disabledAlgorithms" ;
88+ try {
89+ if ( System .getProperty (disabledAlgorithms ) == null ) {
90+ System .setProperty (disabledAlgorithms , "SSLv3, DHE" );
91+ }
92+ }
93+ catch (SecurityException se ) {
94+ OpenSSL .debug ("setting " + disabledAlgorithms + " failed: " + se );
95+ }
8396 }
8497 }
8598
0 commit comments