Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 72357e5

Browse files
committed
tls: more secure defaults
Port of io.js commit: nodejs/node@77f3586 Original commit message: This updates the default cipher suite to an more secure list, which prefers strong ciphers with Forward Secrecy. Additionally, it enables `honorCipherOrder` by default. Noteable effect of this change is that the insecure RC4 ciphers are disabled and that Chrome negotiates a more secure ECDHE cipher. Reviewed-By: James M Snell <jasnell@gmail.com> PR-URL: #14383
1 parent 94beb29 commit 72357e5

File tree

5 files changed

+41
-35
lines changed

5 files changed

+41
-35
lines changed

doc/api/tls.markdown

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ To create a self-signed certificate with the CSR, do this:
2525

2626
Alternatively you can send the CSR to a Certificate Authority for signing.
2727

28-
(TODO: docs on creating a CA, for now interested users should just look at
29-
`test/fixtures/keys/Makefile` in the Node source code)
28+
For Perfect Forward Secrecy, it is required to generate Diffie-Hellman
29+
parameters:
30+
31+
openssl dhparam -outform PEM -out dhparam.pem 2048
3032

3133
To create .pfx or .p12, do this:
3234

@@ -170,31 +172,20 @@ automatically set as a listener for the [secureConnection][] event. The
170172
- `crl` : Either a string or list of strings of PEM encoded CRLs (Certificate
171173
Revocation List)
172174

173-
- `ciphers`: A string describing the ciphers to use or exclude.
174-
175-
To mitigate [BEAST attacks] it is recommended that you use this option in
176-
conjunction with the `honorCipherOrder` option described below to
177-
prioritize the non-CBC cipher.
178-
179-
Defaults to
180-
`ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL`.
181-
Consult the [OpenSSL cipher list format documentation] for details
182-
on the format.
183-
184-
`ECDHE-RSA-AES128-SHA256`, `DHE-RSA-AES128-SHA256` and
185-
`AES128-GCM-SHA256` are TLS v1.2 ciphers and used when node.js is
186-
linked against OpenSSL 1.0.1 or newer, such as the bundled version
187-
of OpenSSL. Note that it is still possible for a TLS v1.2 client
188-
to negotiate a weaker cipher unless `honorCipherOrder` is enabled.
175+
- `ciphers`: A string describing the ciphers to use or exclude, separated by
176+
`:`. The default cipher suite is:
189177

190-
`RC4` is used as a fallback for clients that speak on older version of
191-
the TLS protocol. `RC4` has in recent years come under suspicion and
192-
should be considered compromised for anything that is truly sensitive.
193-
It is speculated that state-level actors possess the ability to break it.
178+
ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:
179+
DHE-RSA-AES256-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:
180+
HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA
194181

195-
**NOTE**: Previous revisions of this section suggested `AES256-SHA` as an
196-
acceptable cipher. Unfortunately, `AES256-SHA` is a CBC cipher and therefore
197-
susceptible to [BEAST attacks]. Do *not* use it.
182+
The default cipher suite prefers ECDHE and DHE ciphers for Perfect Forward
183+
secrecy, while offering *some* backward compatibility. Old clients which
184+
rely on insecure and deprecated RC4 or DES-based ciphers (like Internet
185+
Explorer 6) aren't able to complete the handshake with the default
186+
configuration. If you absolutely must support these clients, the
187+
[TLS recommendations] may offer a compatible cipher suite. For more details
188+
on the format, see the [OpenSSL cipher list format documentation].
198189

199190
- `ecdhCurve`: A string describing a named curve to use for ECDH key agreement
200191
or false to disable ECDH.
@@ -212,7 +203,7 @@ automatically set as a listener for the [secureConnection][] event. The
212203
times out.
213204

214205
- `honorCipherOrder` : When choosing a cipher, use the server's preferences
215-
instead of the client preferences.
206+
instead of the client preferences. Default: `true`.
216207

217208
Although, this option is disabled by default, it is *recommended* that you
218209
use this option in conjunction with the `ciphers` option to mitigate
@@ -853,5 +844,6 @@ The numeric representation of the local port.
853844
[ECDHE]: https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman
854845
[asn1.js]: http://npmjs.org/package/asn1.js
855846
[OCSP request]: http://en.wikipedia.org/wiki/OCSP_stapling
847+
[TLS recommendations]: https://wiki.mozilla.org/Security/Server_Side_TLS
856848
[SSL_CTX_set_options]: https://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
857849
[CVE-2014-3566]: https://access.redhat.com/articles/1232123

lib/_tls_wrap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,10 @@ Server.prototype.setOptions = function(options) {
735735
secureOptions |= constants.SSL_OP_CIPHER_SERVER_PREFERENCE;
736736
}
737737

738-
if (options.honorCipherOrder)
739-
this.honorCipherOrder = true;
738+
if (options.honorCipherOrder !== undefined)
739+
this.honorCipherOrder = !!options.honorCipherOrder;
740740
else
741-
this.honorCipherOrder = false;
741+
this.honorCipherOrder = true;
742742

743743
this.secureOptions = secureOptions;
744744

lib/tls.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,24 @@ exports.CLIENT_RENEG_WINDOW = 600;
3535

3636
exports.SLAB_BUFFER_SIZE = 10 * 1024 * 1024;
3737

38-
exports.DEFAULT_CIPHERS =
39-
// TLS 1.2
40-
'ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:AES128-GCM-SHA256:' +
41-
// TLS 1.0
42-
'RC4:HIGH:!MD5:!aNULL';
38+
exports.DEFAULT_CIPHERS = [
39+
'ECDHE-RSA-AES256-SHA384',
40+
'DHE-RSA-AES256-SHA384',
41+
'ECDHE-RSA-AES256-SHA256',
42+
'DHE-RSA-AES256-SHA256',
43+
'ECDHE-RSA-AES128-SHA256',
44+
'DHE-RSA-AES128-SHA256',
45+
'HIGH',
46+
'!aNULL',
47+
'!eNULL',
48+
'!EXPORT',
49+
'!DES',
50+
'!RC4',
51+
'!MD5',
52+
'!PSK',
53+
'!SRP',
54+
'!CAMELLIA'
55+
].join(':');
4356

4457
exports.DEFAULT_ECDH_CURVE = 'prime256v1';
4558

test/simple/test-tls-dhe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function test(keylen, expectedCipher, cb) {
4747
var options = {
4848
key: key,
4949
cert: cert,
50+
ciphers: ciphers,
5051
dhparam: loadDHParam(keylen)
5152
};
5253

test/simple/test-tls-getcipher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ server.listen(common.PORT, '127.0.0.1', function() {
4949
rejectUnauthorized: false
5050
}, function() {
5151
var cipher = client.getCipher();
52-
assert.equal(cipher.name, cipher_list[0]);
52+
assert.equal(cipher.name, cipher_list[1]);
5353
assert(cipher_version_pattern.test(cipher.version));
5454
client.end();
5555
server.close();

0 commit comments

Comments
 (0)