GeezerVison is showing github.com — tls: make server not use DHE in less than 1024bits · nodejs/node@9b35be5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/tls.markdown +4-2Lines changed: 4 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -183,8 +183,10 @@ automatically set as a listener for the [secureConnection][] event. The | 183 | 183 |
| 184 | 184 | - `dhparam`: A string or `Buffer` containing Diffie Hellman parameters, | 185 | 185 | 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. | 188 | 190 |
| 189 | 191 | - `handshakeTimeout`: Abort the connection if the SSL/TLS handshake does not | 190 | 192 | finish in this many milliseconds. The default is 120 seconds. | |
Collapse file Copy file name to clipboardExpand all lines: src/node_crypto.cc +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -757,6 +757,12 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) { | 757 | 757 | if (dh == nullptr) | 758 | 758 | return; | 759 | 759 |
| | 760 | + const 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 | + | 760 | 766 | SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE); | 761 | 767 | int r = SSL_CTX_set_tmp_dh(sc->ctx_, dh); | 762 | 768 | DH_free(dh); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-tls-dhe.js +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,8 +62,9 @@ function test(keylen, expectedCipher, cb) { | 62 | 62 | } | 63 | 63 |
| 64 | 64 | 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/); | 67 | 68 | } | 68 | 69 |
| 69 | 70 | function test1024() { | @@ -77,12 +78,13 @@ function test2048() { | 77 | 78 | } | 78 | 79 |
| 79 | 80 | function testError() { | 80 | | - test('error', 'ECDHE-RSA-AES128-SHA256', null); | | 81 | + test('error', 'ECDHE-RSA-AES128-SHA256', test512); | 81 | 82 | ntests++; | 82 | 83 | } | 83 | 84 |
| 84 | | -test512(); | | 85 | +test1024(); | 85 | 86 |
| 86 | 87 | process.on('exit', function() { | 87 | 88 | assert.equal(ntests, nsuccess); | | 89 | + assert.equal(ntests, 3); | 88 | 90 | }); |
|