GeezerVison is showing github.com — tls: add --tls-cipher-list command line switch · nodejs/node@5fef5c6
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 +39-1Lines changed: 39 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -77,6 +77,44 @@ handshake extensions allowing you: | 77 | 77 | * SNI - to use one TLS server for multiple hostnames with different SSL | 78 | 78 | certificates. | 79 | 79 |
| | 80 | +## Modifying the Default TLS Cipher suite | | 81 | + | | 82 | +Node.js is built with a default suite of enabled and disabled TLS ciphers. | | 83 | +Currently, the default cipher suite is: | | 84 | + | | 85 | + ECDHE-RSA-AES128-GCM-SHA256: | | 86 | + ECDHE-ECDSA-AES128-GCM-SHA256: | | 87 | + ECDHE-RSA-AES256-GCM-SHA384: | | 88 | + ECDHE-ECDSA-AES256-GCM-SHA384: | | 89 | + DHE-RSA-AES128-GCM-SHA256: | | 90 | + ECDHE-RSA-AES128-SHA256: | | 91 | + DHE-RSA-AES128-SHA256: | | 92 | + ECDHE-RSA-AES256-SHA384: | | 93 | + DHE-RSA-AES256-SHA384: | | 94 | + ECDHE-RSA-AES256-SHA256: | | 95 | + DHE-RSA-AES256-SHA256: | | 96 | + HIGH: | | 97 | + !aNULL: | | 98 | + !eNULL: | | 99 | + !EXPORT: | | 100 | + !DES: | | 101 | + !RC4: | | 102 | + !MD5: | | 103 | + !PSK: | | 104 | + !SRP: | | 105 | + !CAMELLIA | | 106 | + | | 107 | +This default can be overriden entirely using the `--tls-cipher-list` command | | 108 | +line switch. For instance, the following makes | | 109 | +`ECDHE-RSA-AES128-GCM-SHA256:!RC4` the default TLS cipher suite: | | 110 | + | | 111 | + node --tls-cipher-list="ECDHE-RSA-AES128-GCM-SHA256:!RC4" | | 112 | + | | 113 | +Note that the default cipher suite included within Node.js has been carefully | | 114 | +selected to reflect current security best practices and risk mitigation. | | 115 | +Changing the default cipher suite can have a significant impact on the security | | 116 | +of an application. The `--tls-cipher-list` switch should by used only if | | 117 | +absolutely necessary. | 80 | 118 |
| 81 | 119 | ## Perfect Forward Secrecy | 82 | 120 |
| @@ -138,7 +176,7 @@ automatically set as a listener for the [secureConnection][] event. The | 138 | 176 | - `crl` : Either a string or list of strings of PEM encoded CRLs (Certificate | 139 | 177 | Revocation List) | 140 | 178 |
| 141 | | - - `ciphers`: A string describing the ciphers to use or exclude, seperated by | | 179 | + - `ciphers`: A string describing the ciphers to use or exclude, separated by | 142 | 180 | `:`. The default cipher suite is: | 143 | 181 |
| 144 | 182 | ECDHE-RSA-AES128-GCM-SHA256: | |
Collapse file Copy file name to clipboardExpand all lines: doc/iojs.1 +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,6 +64,9 @@ and servers. | 64 | 64 |
| 65 | 65 | --v8-options print v8 command line options | 66 | 66 |
| | 67 | + --tls-cipher-list=list use an alternative default TLS cipher list | | 68 | + (available only when Node.js is built with | | 69 | + OpenSSL and crypto support enabled) | 67 | 70 |
| 68 | 71 | .SH ENVIRONMENT VARIABLES | 69 | 72 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/tls.js +2-23Lines changed: 2 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ const url = require('url'); | 5 | 5 | const util = require('util'); | 6 | 6 | const binding = process.binding('crypto'); | 7 | 7 | const Buffer = require('buffer').Buffer; | | 8 | +const constants = require('constants'); | 8 | 9 |
| 9 | 10 | // Allow {CLIENT_RENEG_LIMIT} client-initiated session renegotiations | 10 | 11 | // every {CLIENT_RENEG_WINDOW} seconds. An error event is emitted if more | @@ -15,29 +16,7 @@ exports.CLIENT_RENEG_WINDOW = 600; | 15 | 16 |
| 16 | 17 | exports.SLAB_BUFFER_SIZE = 10 * 1024 * 1024; | 17 | 18 |
| 18 | | -exports.DEFAULT_CIPHERS = [ | 19 | | - 'ECDHE-RSA-AES128-GCM-SHA256', | 20 | | - 'ECDHE-ECDSA-AES128-GCM-SHA256', | 21 | | - 'ECDHE-RSA-AES256-GCM-SHA384', | 22 | | - 'ECDHE-ECDSA-AES256-GCM-SHA384', | 23 | | - 'DHE-RSA-AES128-GCM-SHA256', | 24 | | - 'ECDHE-RSA-AES128-SHA256', | 25 | | - 'DHE-RSA-AES128-SHA256', | 26 | | - 'ECDHE-RSA-AES256-SHA384', | 27 | | - 'DHE-RSA-AES256-SHA384', | 28 | | - 'ECDHE-RSA-AES256-SHA256', | 29 | | - 'DHE-RSA-AES256-SHA256', | 30 | | - 'HIGH', | 31 | | - '!aNULL', | 32 | | - '!eNULL', | 33 | | - '!EXPORT', | 34 | | - '!DES', | 35 | | - '!RC4', | 36 | | - '!MD5', | 37 | | - '!PSK', | 38 | | - '!SRP', | 39 | | - '!CAMELLIA' | 40 | | -].join(':'); | | 19 | +exports.DEFAULT_CIPHERS = constants.defaultCipherList; | 41 | 20 |
| 42 | 21 | exports.DEFAULT_ECDH_CURVE = 'prime256v1'; | 43 | 22 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3111,6 +3111,9 @@ static void PrintHelp() { | 3111 | 3111 | " --track-heap-objects track heap object allocations for heap " | 3112 | 3112 | "snapshots\n" | 3113 | 3113 | " --v8-options print v8 command line options\n" | | 3114 | +#if HAVE_OPENSSL | | 3115 | + " --tls-cipher-list=val use an alternative default TLS cipher list\n" | | 3116 | +#endif | 3114 | 3117 | #if defined(NODE_HAVE_I18N_SUPPORT) | 3115 | 3118 | " --icu-data-dir=dir set ICU data load path to dir\n" | 3116 | 3119 | " (overrides NODE_ICU_DATA)\n" | @@ -3242,6 +3245,10 @@ static void ParseArgs(int* argc, | 3242 | 3245 | } else if (strcmp(arg, "--v8-options") == 0) { | 3243 | 3246 | new_v8_argv[new_v8_argc] = "--help"; | 3244 | 3247 | new_v8_argc += 1; | | 3248 | +#if HAVE_OPENSSL | | 3249 | + } else if (strncmp(arg, "--tls-cipher-list=", 18) == 0) { | | 3250 | + default_cipher_list = arg + 18; | | 3251 | +#endif | 3245 | 3252 | #if defined(NODE_HAVE_I18N_SUPPORT) | 3246 | 3253 | } else if (strncmp(arg, "--icu-data-dir=", 15) == 0) { | 3247 | 3254 | icu_data_dir = arg + 15; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_constants.cc +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,10 @@ namespace node { | 24 | 24 | using v8::Handle; | 25 | 25 | using v8::Object; | 26 | 26 |
| | 27 | +#if HAVE_OPENSSL | | 28 | +const char* default_cipher_list = DEFAULT_CIPHER_LIST_CORE; | | 29 | +#endif | | 30 | + | 27 | 31 | void DefineErrnoConstants(Handle<Object> target) { | 28 | 32 | #ifdef E2BIG | 29 | 33 | NODE_DEFINE_CONSTANT(target, E2BIG); | @@ -1108,13 +1112,25 @@ void DefineUVConstants(Handle<Object> target) { | 1108 | 1112 | NODE_DEFINE_CONSTANT(target, UV_UDP_REUSEADDR); | 1109 | 1113 | } | 1110 | 1114 |
| | 1115 | +void DefineCryptoConstants(Handle<Object> target) { | | 1116 | +#if HAVE_OPENSSL | | 1117 | + NODE_DEFINE_STRING_CONSTANT(target, | | 1118 | + "defaultCoreCipherList", | | 1119 | + DEFAULT_CIPHER_LIST_CORE); | | 1120 | + NODE_DEFINE_STRING_CONSTANT(target, | | 1121 | + "defaultCipherList", | | 1122 | + default_cipher_list); | | 1123 | +#endif | | 1124 | +} | | 1125 | + | 1111 | 1126 | void DefineConstants(Handle<Object> target) { | 1112 | 1127 | DefineErrnoConstants(target); | 1113 | 1128 | DefineWindowsErrorConstants(target); | 1114 | 1129 | DefineSignalConstants(target); | 1115 | 1130 | DefineOpenSSLConstants(target); | 1116 | 1131 | DefineSystemConstants(target); | 1117 | 1132 | DefineUVConstants(target); | | 1133 | + DefineCryptoConstants(target); | 1118 | 1134 | } | 1119 | 1135 |
| 1120 | 1136 | } // namespace node |
Collapse file Copy file name to clipboardExpand all lines: src/node_constants.h +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | #include "node.h" | 5 | 5 | #include "v8.h" | 6 | 6 |
| | 7 | +#if HAVE_OPENSSL | | 8 | +#define DEFAULT_CIPHER_LIST_CORE "ECDHE-RSA-AES128-GCM-SHA256:" \ | | 9 | + "ECDHE-ECDSA-AES128-GCM-SHA256:" \ | | 10 | + "ECDHE-RSA-AES256-GCM-SHA384:" \ | | 11 | + "ECDHE-ECDSA-AES256-GCM-SHA384:" \ | | 12 | + "DHE-RSA-AES128-GCM-SHA256:" \ | | 13 | + "ECDHE-RSA-AES128-SHA256:" \ | | 14 | + "DHE-RSA-AES128-SHA256:" \ | | 15 | + "ECDHE-RSA-AES256-SHA384:" \ | | 16 | + "DHE-RSA-AES256-SHA384:" \ | | 17 | + "ECDHE-RSA-AES256-SHA256:" \ | | 18 | + "DHE-RSA-AES256-SHA256:" \ | | 19 | + "HIGH:" \ | | 20 | + "!aNULL:" \ | | 21 | + "!eNULL:" \ | | 22 | + "!EXPORT:" \ | | 23 | + "!DES:" \ | | 24 | + "!RC4:" \ | | 25 | + "!MD5:" \ | | 26 | + "!PSK:" \ | | 27 | + "!SRP:" \ | | 28 | + "!CAMELLIA" | | 29 | +#endif | | 30 | + | 7 | 31 | namespace node { | | 32 | + | | 33 | +#if HAVE_OPENSSL | | 34 | +extern const char* default_cipher_list; | | 35 | +#endif | | 36 | + | 8 | 37 | void DefineConstants(v8::Handle<v8::Object> target); | 9 | 38 | } // namespace node | 10 | 39 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_internals.h +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 |
| 13 | 13 | struct sockaddr; | 14 | 14 |
| | 15 | +// Variation on NODE_DEFINE_CONSTANT that sets a String value. | | 16 | +#define NODE_DEFINE_STRING_CONSTANT(target, name, constant) \ | | 17 | + do { \ | | 18 | + v8::Isolate* isolate = target->GetIsolate(); \ | | 19 | + v8::Local<v8::String> constant_name = \ | | 20 | + v8::String::NewFromUtf8(isolate, name); \ | | 21 | + v8::Local<v8::String> constant_value = \ | | 22 | + v8::String::NewFromUtf8(isolate, constant); \ | | 23 | + v8::PropertyAttribute constant_attributes = \ | | 24 | + static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \ | | 25 | + target->ForceSet(isolate->GetCurrentContext(), \ | | 26 | + constant_name, \ | | 27 | + constant_value, \ | | 28 | + constant_attributes); \ | | 29 | + } while (0) | | 30 | + | 15 | 31 | namespace node { | 16 | 32 |
| 17 | 33 | // Forward declaration | |
Collapse file Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | + | | 4 | +if (!common.hasCrypto) { | | 5 | + console.log('1..0 # Skipped: missing crypto'); | | 6 | + return; | | 7 | +} | | 8 | + | | 9 | +const assert = require('assert'); | | 10 | +const spawn = require('child_process').spawn; | | 11 | +const defaultCoreList = require('constants').defaultCoreCipherList; | | 12 | + | | 13 | +function doCheck(arg, check) { | | 14 | + var out = ''; | | 15 | + var arg = arg.concat([ | | 16 | + '-pe', | | 17 | + 'require("constants").defaultCipherList' | | 18 | + ]); | | 19 | + spawn(process.execPath, arg, {}). | | 20 | + on('error', assert.fail). | | 21 | + stdout.on('data', function(chunk) { | | 22 | + out += chunk; | | 23 | + }).on('end', function() { | | 24 | + assert.equal(out.trim(), check); | | 25 | + }).on('error', assert.fail); | | 26 | +} | | 27 | + | | 28 | +// test the default unmodified version | | 29 | +doCheck([], defaultCoreList); | | 30 | + | | 31 | +// test the command line switch by itself | | 32 | +doCheck(['--tls-cipher-list=ABC'], 'ABC'); |
|