Skip to content

Commit 81c4808

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 81c4808

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

doc/api/tls.markdown

+4-2
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 1024 bits, otherwise
187+
it throws an error. It is strongly recommended to use 2048 bits or
188+
more for stronger 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

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

760+
int keylen = BN_num_bits(dh->p);
761+
if (keylen < 1024)
762+
return env->ThrowError("DH parameter is less than 1024 bits");
763+
else if (keylen < 2048)
764+
fprintf(stderr, "WARNING: DH parameter is less than 2048 bits\n");
765+
760766
SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE);
761767
int r = SSL_CTX_set_tmp_dh(sc->ctx_, dh);
762768
DH_free(dh);

test/parallel/test-tls-dhe.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ 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', null);
67+
}, /DH parameter is less than 1024 bits/);
6768
}
6869

6970
function test1024() {
@@ -77,12 +78,13 @@ function test2048() {
7778
}
7879

7980
function testError() {
80-
test('error', 'ECDHE-RSA-AES128-SHA256', null);
81+
test('error', 'ECDHE-RSA-AES128-SHA256', test512);
8182
ntests++;
8283
}
8384

84-
test512();
85+
test1024();
8586

8687
process.on('exit', function() {
8788
assert.equal(ntests, nsuccess);
89+
assert.equal(ntests, 3);
8890
});

0 commit comments

Comments
 (0)