GeezerVison is showing github.com — crypto: support OPENSSL_CONF again · nodejs/node@f8da60f
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/cli.md +13Lines changed: 13 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -328,8 +328,21 @@ malformed, but any errors are otherwise ignored. | 328 | 328 | Note that neither the well known nor extra certificates are used when the `ca` | 329 | 329 | options property is explicitly specified for a TLS or HTTPS client or server. | 330 | 330 |
| | 331 | +### `OPENSSL_CONF=file` | | 332 | +<!-- YAML | | 333 | +added: REPLACEME | | 334 | +--> | | 335 | + | | 336 | +Load an OpenSSL configuration file on startup. Among other uses, this can be | | 337 | +used to enable FIPS-compliant crypto if Node.js is built with `./configure | | 338 | +\-\-openssl\-fips`. | | 339 | + | | 340 | +If the [`--openssl-config`][] command line option is used, the environment | | 341 | +variable is ignored. | | 342 | + | 331 | 343 | [emit_warning]: process.html#process_process_emitwarning_warning_name_ctor | 332 | 344 | [Buffer]: buffer.html#buffer_buffer | 333 | 345 | [debugger]: debugger.html | 334 | 346 | [REPL]: repl.html | 335 | 347 | [SlowBuffer]: buffer.html#buffer_class_slowbuffer | | 348 | +[`--openssl-config`]: #cli_openssl_config_file |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -215,6 +215,16 @@ when outputting to a TTY on platforms which support async stdio. | 215 | 215 | Setting this will void any guarantee that stdio will not be interleaved or | 216 | 216 | dropped at program exit. \fBAvoid use.\fR | 217 | 217 |
| | 218 | +.TP | | 219 | +.BR OPENSSL_CONF = \fIfile\fR | | 220 | +Load an OpenSSL configuration file on startup. Among other uses, this can be | | 221 | +used to enable FIPS-compliant crypto if Node.js is built with | | 222 | +\fB./configure \-\-openssl\-fips\fR. | | 223 | + | | 224 | +If the | | 225 | +\fB\-\-openssl\-config\fR | | 226 | +command line option is used, the environment variable is ignored. | | 227 | + | 218 | 228 |
| 219 | 229 | .SH BUGS | 220 | 230 | Bugs are tracked in GitHub Issues: | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -179,7 +179,7 @@ bool no_deprecation = false; | 179 | 179 | bool enable_fips_crypto = false; | 180 | 180 | bool force_fips_crypto = false; | 181 | 181 | # endif // NODE_FIPS_MODE | 182 | | -const char* openssl_config = nullptr; | | 182 | +std::string openssl_config; // NOLINT(runtime/string) | 183 | 183 | #endif // HAVE_OPENSSL | 184 | 184 |
| 185 | 185 | // true if process warnings should be suppressed | @@ -3691,7 +3691,7 @@ static void PrintHelp() { | 3691 | 3691 | " --force-fips force FIPS crypto (cannot be disabled)\n" | 3692 | 3692 | #endif /* NODE_FIPS_MODE */ | 3693 | 3693 | " --openssl-config=path load OpenSSL configuration file from the\n" | 3694 | | - " specified path\n" | | 3694 | + " specified file (overrides OPENSSL_CONF)\n" | 3695 | 3695 | #endif /* HAVE_OPENSSL */ | 3696 | 3696 | #if defined(NODE_HAVE_I18N_SUPPORT) | 3697 | 3697 | " --icu-data-dir=dir set ICU data load path to dir\n" | @@ -3726,6 +3726,7 @@ static void PrintHelp() { | 3726 | 3726 | #endif | 3727 | 3727 | " prefixed to the module search path\n" | 3728 | 3728 | "NODE_REPL_HISTORY path to the persistent REPL history file\n" | | 3729 | + "OPENSSL_CONF load OpenSSL configuration from file\n" | 3729 | 3730 | "\n" | 3730 | 3731 | "Documentation can be found at https://nodejs.org/\n"); | 3731 | 3732 | } | @@ -3860,7 +3861,7 @@ static void ParseArgs(int* argc, | 3860 | 3861 | force_fips_crypto = true; | 3861 | 3862 | #endif /* NODE_FIPS_MODE */ | 3862 | 3863 | } else if (strncmp(arg, "--openssl-config=", 17) == 0) { | 3863 | | - openssl_config = arg + 17; | | 3864 | + openssl_config.assign(arg + 17); | 3864 | 3865 | #endif /* HAVE_OPENSSL */ | 3865 | 3866 | #if defined(NODE_HAVE_I18N_SUPPORT) | 3866 | 3867 | } else if (strncmp(arg, "--icu-data-dir=", 15) == 0) { | @@ -4355,6 +4356,9 @@ void Init(int* argc, | 4355 | 4356 | V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1); | 4356 | 4357 | #endif | 4357 | 4358 |
| | 4359 | + if (openssl_config.empty()) | | 4360 | + SafeGetenv("OPENSSL_CONF", &openssl_config); | | 4361 | + | 4358 | 4362 | // Parse a few arguments which are specific to Node. | 4359 | 4363 | int v8_argc; | 4360 | 4364 | const char** v8_argv; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_crypto.cc +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5904,14 +5904,14 @@ void InitCryptoOnce() { | 5904 | 5904 | OPENSSL_no_config(); | 5905 | 5905 |
| 5906 | 5906 | // --openssl-config=... | 5907 | | - if (openssl_config != nullptr) { | | 5907 | + if (!openssl_config.empty()) { | 5908 | 5908 | OPENSSL_load_builtin_modules(); | 5909 | 5909 | #ifndef OPENSSL_NO_ENGINE | 5910 | 5910 | ENGINE_load_builtin_engines(); | 5911 | 5911 | #endif | 5912 | 5912 | ERR_clear_error(); | 5913 | 5913 | CONF_modules_load_file( | 5914 | | - openssl_config, | | 5914 | + openssl_config.c_str(), | 5915 | 5915 | nullptr, | 5916 | 5916 | CONF_MFLAGS_DEFAULT_SECTION); | 5917 | 5917 | int err = ERR_get_error(); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_internals.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,7 @@ namespace node { | 36 | 36 |
| 37 | 37 | // Set in node.cc by ParseArgs with the value of --openssl-config. | 38 | 38 | // Used in node_crypto.cc when initializing OpenSSL. | 39 | | -extern const char* openssl_config; | | 39 | +extern std::string openssl_config; | 40 | 40 |
| 41 | 41 | // Set in node.cc by ParseArgs when --preserve-symlinks is used. | 42 | 42 | // Used in node_config.cc to set a constant on process.binding('config') | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-crypto-fips.js +22-3Lines changed: 22 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,8 +37,9 @@ function testHelper(stream, args, expectedOutput, cmd, env) { | 37 | 37 | env: env | 38 | 38 | }); | 39 | 39 |
| 40 | | - console.error('Spawned child [pid:' + child.pid + '] with cmd ' + | 41 | | - cmd + ' and args \'' + args + '\''); | | 40 | + console.error('Spawned child [pid:' + child.pid + '] with cmd \'' + | | 41 | + cmd + '\' expect %j with args \'' + args + '\'' + | | 42 | + ' OPENSSL_CONF=%j', expectedOutput, env.OPENSSL_CONF); | 42 | 43 |
| 43 | 44 | function childOk(child) { | 44 | 45 | console.error('Child #' + ++num_children_ok + | @@ -92,10 +93,26 @@ testHelper( | 92 | 93 | compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED, | 93 | 94 | 'require("crypto").fips', | 94 | 95 | process.env); | 95 | | -// OPENSSL_CONF should _not_ be able to turn on FIPS mode | | 96 | + | | 97 | +// OPENSSL_CONF should be able to turn on FIPS mode | 96 | 98 | testHelper( | 97 | 99 | 'stdout', | 98 | 100 | [], | | 101 | + compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED, | | 102 | + 'require("crypto").fips', | | 103 | + addToEnv('OPENSSL_CONF', CNF_FIPS_ON)); | | 104 | + | | 105 | +// --openssl-config option should override OPENSSL_CONF | | 106 | +testHelper( | | 107 | + 'stdout', | | 108 | + [`--openssl-config=${CNF_FIPS_ON}`], | | 109 | + compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED, | | 110 | + 'require("crypto").fips', | | 111 | + addToEnv('OPENSSL_CONF', CNF_FIPS_OFF)); | | 112 | + | | 113 | +testHelper( | | 114 | + 'stdout', | | 115 | + [`--openssl-config=${CNF_FIPS_OFF}`], | 99 | 116 | FIPS_DISABLED, | 100 | 117 | 'require("crypto").fips', | 101 | 118 | addToEnv('OPENSSL_CONF', CNF_FIPS_ON)); | @@ -107,6 +124,7 @@ testHelper( | 107 | 124 | compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING, | 108 | 125 | 'require("crypto").fips', | 109 | 126 | process.env); | | 127 | + | 110 | 128 | // OPENSSL_CONF should _not_ make a difference to --enable-fips | 111 | 129 | testHelper( | 112 | 130 | compiledWithFips() ? 'stdout' : 'stderr', | @@ -122,6 +140,7 @@ testHelper( | 122 | 140 | compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING, | 123 | 141 | 'require("crypto").fips', | 124 | 142 | process.env); | | 143 | + | 125 | 144 | // Using OPENSSL_CONF should not make a difference to --force-fips | 126 | 145 | testHelper( | 127 | 146 | compiledWithFips() ? 'stdout' : 'stderr', | |
|