tls: make server not use DHE in less than 1024bits
authorShigeki Ohtsu <ohtsu@iij.ad.jp>
Wed, 20 May 2015 05:20:26 +0000 (14:20 +0900)
committerShigeki Ohtsu <ohtsu@iij.ad.jp>
Wed, 20 May 2015 15:02:44 +0000 (00:02 +0900)
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.

PR-URL: https://github.com/nodejs/io.js/pull/1739
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
doc/api/tls.markdown
src/node_crypto.cc
test/parallel/test-tls-dhe.js

index 657f690343ff033a11fd2e40bf236cf530067e2e..a00b27dab91c9408f2474fd4255fcb73e6196610 100644 (file)
@@ -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.
 
   - `handshakeTimeout`: Abort the connection if the SSL/TLS handshake does not
     finish in this many milliseconds. The default is 120 seconds.
index 03dc7d61807d587379a6d806c734bea8949a2d53..e2c478a510be8435bcc38c647d28f524a5c9d2a6 100644 (file)
@@ -757,6 +757,12 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
   if (dh == nullptr)
     return;
 
+  const int keylen = BN_num_bits(dh->p);
+  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);
index 5c9eb87b2e2935daf18c5172dd7b0237bbd5383e..92fff3f221b65feb6366c597e4b23017600195ad 100644 (file)
@@ -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() {
@@ -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);
 });