Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: make server not use DHE in less than 1024bits for fix agaist Logjam Attack #1739

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/api/tls.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ automatically set as a listener for the [secureConnection][] event. The

- `dhparam`: A string or `Buffer` containing Diffie Hellman parameters,
required for Perfect Forward Secrecy. Use `openssl dhparam` to create it.
If omitted or invalid, it is silently discarded and DHE ciphers won't be
available.
Its key length should be greater than or equal to 1024 bits, otherwise
it throws an error. It is strongly recommended to use 2048 bits or
more for stronger security. If omitted or invalid, it is silently
discarded and DHE ciphers won't be available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • s/1024bits/1024 bits/, ditto for 2048bits.
  • I would s/recommended/strongly recommended/ and maybe add a warning that someday we're going to enforce it.
  • s/enough strong security/stronger security/


- `handshakeTimeout`: Abort the connection if the SSL/TLS handshake does not
finish in this many milliseconds. The default is 120 seconds.
Expand Down
6 changes: 6 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
if (dh == nullptr)
return;

int keylen = BN_num_bits(dh->p);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: make keylen const.

if (keylen < 1024)
return env->ThrowError("DH parameter is less than 1024 bits");
else if (keylen < 2048)
fprintf(stderr, "WARNING: DH parameter is less than 2048 bits\n");

SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE);
int r = SSL_CTX_set_tmp_dh(sc->ctx_, dh);
DH_free(dh);
Expand Down
10 changes: 6 additions & 4 deletions test/parallel/test-tls-dhe.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ function test(keylen, expectedCipher, cb) {
}

function test512() {
test(512, 'DHE-RSA-AES128-SHA256', test1024);
ntests++;
assert.throws(function() {
test(512, 'DHE-RSA-AES128-SHA256', null);
}, /DH parameter is less than 1024 bits/);
}

function test1024() {
Expand All @@ -77,12 +78,13 @@ function test2048() {
}

function testError() {
test('error', 'ECDHE-RSA-AES128-SHA256', null);
test('error', 'ECDHE-RSA-AES128-SHA256', test512);
ntests++;
}

test512();
test1024();

process.on('exit', function() {
assert.equal(ntests, nsuccess);
assert.equal(ntests, 3);
});