Skip to content

Commit cdc7c17

Browse files
author
Shigeki Ohtsu
committed
tls: make server not use DHE in less than 1024bits
DHE key lengths less than 1024bits is already weaken as pointed out in https://weakdh.org/ . 1024bits will not be safe in near future. We will extend this up to 2048bits somedays later.
1 parent f29762f commit cdc7c17

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

doc/api/tls.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ automatically set as a listener for the [secureConnection][] event. The
183183

184184
- `dhparam`: A string or `Buffer` containing Diffie Hellman parameters,
185185
required for Perfect Forward Secrecy. Use `openssl dhparam` to create it.
186-
If omitted or invalid, it is silently discarded and DHE ciphers won't be
187-
available.
186+
Its key length should be greater than or equal to 1024bits, otherwise
187+
it throws an error. It is recommended to use 2048bits or more for
188+
enough strong security. If omitted or invalid, it is silently
189+
discarded and DHE ciphers won't be available.
188190

189191
- `handshakeTimeout`: Abort the connection if the SSL/TLS handshake does not
190192
finish in this many milliseconds. The default is 120 seconds.

src/node_crypto.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
757757
if (dh == nullptr)
758758
return;
759759

760+
if (BN_num_bits(dh->p) < 1024) {
761+
return env->ThrowError("DH parameter is less than 1024bits");
762+
}
763+
760764
SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE);
761765
int r = SSL_CTX_set_tmp_dh(sc->ctx_, dh);
762766
DH_free(dh);

test/parallel/test-tls-dhe.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ function test(keylen, expectedCipher, cb) {
6262
}
6363

6464
function test512() {
65-
test(512, 'DHE-RSA-AES128-SHA256', test1024);
66-
ntests++;
65+
assert.throws(function() {
66+
test(512, 'DHE-RSA-AES128-SHA256', test1024);
67+
},
68+
/DH parameter is less than 1024bits/
69+
);
6770
}
6871

6972
function test1024() {

0 commit comments

Comments
 (0)