@@ -28,6 +28,7 @@ if (!common.hasCrypto) {
2828
2929const {
3030 opensslCli,
31+ hasOpenSSL,
3132} = require ( '../common/crypto' ) ;
3233
3334// OpenSSL has a set of security levels which affect what algorithms
@@ -104,9 +105,15 @@ function testCustomParam(keylen, expectedCipher) {
104105}
105106
106107( async ( ) => {
107- // By default, DHE is disabled while ECDHE is enabled.
108+ // By default, DHE is disabled while ECDHE is enabled. OpenSSL 4.0
109+ // implements RFC 7919 FFDHE negotiation for TLS 1.2 which enables DHE
110+ // (with FFDHE-2048) even without a server-supplied dhparam.
108111 for ( const dhparam of [ undefined , null ] ) {
109- await test ( dhparam , null , ecdheCipher ) ;
112+ if ( hasOpenSSL ( 4 , 0 ) ) {
113+ await test ( dhparam , 2048 , dheCipher ) ;
114+ } else {
115+ await test ( dhparam , null , ecdheCipher ) ;
116+ }
110117 }
111118
112119 // The DHE parameters selected by OpenSSL depend on the strength of the
@@ -124,14 +131,24 @@ function testCustomParam(keylen, expectedCipher) {
124131
125132 // Custom DHE parameters are supported (but discouraged).
126133 // 1024 is disallowed at security level 2 and above so use 3072 instead
127- // for higher security levels
134+ // for higher security levels.
135+ // OpenSSL 4.0 implements RFC 7919 FFDHE negotiation for TLS 1.2 and
136+ // ignores the server-supplied dhparam in favor of FFDHE-2048, so the
137+ // negotiated key length is always 2048.
128138 if ( secLevel < 2 ) {
129139 await testCustomParam ( 1024 , dheCipher ) ;
140+ } else if ( hasOpenSSL ( 4 , 0 ) ) {
141+ await test ( loadDHParam ( 3072 ) , 2048 , dheCipher ) ;
130142 } else {
131143 await testCustomParam ( 3072 , dheCipher ) ;
132144 }
133145 await testCustomParam ( 2048 , dheCipher ) ;
134146
135- // Invalid DHE parameters are discarded. ECDHE remains enabled.
136- await testCustomParam ( 'error' , ecdheCipher ) ;
147+ // Invalid DHE parameters are discarded. Prior to OpenSSL 4.0 this
148+ // disabled DHE and ECDHE was negotiated; since 4.0, FFDHE-2048 is used.
149+ if ( hasOpenSSL ( 4 , 0 ) ) {
150+ await test ( loadDHParam ( 'error' ) , 2048 , dheCipher ) ;
151+ } else {
152+ await testCustomParam ( 'error' , ecdheCipher ) ;
153+ }
137154} ) ( ) . then ( common . mustCall ( ) ) ;
0 commit comments