crypto: fix openssl.cnf FIPS handling & testing
* Add documentation for `--openssl-conf=file`. * Fix openssl.cnf loading and OpenSSL init ordering * Fix FIPS tests so `OPENSSL_CONF` is not longer usable but `--openssl-conf` is PR-URL: https://github.com/nodejs/node-private/pull/82 Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
db411cf116
commit
bb173f931a
@ -234,6 +234,16 @@ Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.)
|
|||||||
(Same requirements as `--enable-fips`)
|
(Same requirements as `--enable-fips`)
|
||||||
|
|
||||||
|
|
||||||
|
### `--openssl-config=file`
|
||||||
|
<!-- YAML
|
||||||
|
added: v6.9.0
|
||||||
|
-->
|
||||||
|
|
||||||
|
Load an OpenSSL configuration file on startup. Among other uses, this can be
|
||||||
|
used to enable FIPS-compliant crypto if Node.js is built with
|
||||||
|
`./configure --openssl-fips`.
|
||||||
|
|
||||||
|
|
||||||
### `--icu-data-dir=file`
|
### `--icu-data-dir=file`
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.11.15
|
added: v0.11.15
|
||||||
|
@ -165,6 +165,12 @@ Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with
|
|||||||
Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.)
|
Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.)
|
||||||
(Same requirements as \fB\-\-enable\-fips\fR)
|
(Same requirements as \fB\-\-enable\-fips\fR)
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR \-\-openssl\-config =\fIfile\fR
|
||||||
|
Load an OpenSSL configuration file on startup. Among other uses, this can be
|
||||||
|
used to enable FIPS-compliant crypto if Node.js is built with
|
||||||
|
\fB./configure \-\-openssl\-fips\fR.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BR \-\-icu\-data\-dir =\fIfile\fR
|
.BR \-\-icu\-data\-dir =\fIfile\fR
|
||||||
Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR)
|
Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR)
|
||||||
|
@ -179,13 +179,10 @@ typedef intptr_t ssize_t;
|
|||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
NODE_EXTERN extern bool no_deprecation;
|
NODE_EXTERN extern bool no_deprecation;
|
||||||
#if HAVE_OPENSSL
|
#if HAVE_OPENSSL && NODE_FIPS_MODE
|
||||||
# if NODE_FIPS_MODE
|
|
||||||
NODE_EXTERN extern bool enable_fips_crypto;
|
NODE_EXTERN extern bool enable_fips_crypto;
|
||||||
NODE_EXTERN extern bool force_fips_crypto;
|
NODE_EXTERN extern bool force_fips_crypto;
|
||||||
# endif // NODE_FIPS_MODE
|
#endif
|
||||||
NODE_EXTERN extern const char* openssl_config;
|
|
||||||
#endif // HAVE_OPENSSL
|
|
||||||
|
|
||||||
NODE_EXTERN int Start(int argc, char *argv[]);
|
NODE_EXTERN int Start(int argc, char *argv[]);
|
||||||
NODE_EXTERN void Init(int* argc,
|
NODE_EXTERN void Init(int* argc,
|
||||||
|
@ -5767,14 +5767,20 @@ void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InitCryptoOnce() {
|
void InitCryptoOnce() {
|
||||||
|
SSL_load_error_strings();
|
||||||
OPENSSL_no_config();
|
OPENSSL_no_config();
|
||||||
|
|
||||||
// --openssl-config=...
|
// --openssl-config=...
|
||||||
if (openssl_config != nullptr) {
|
if (openssl_config != nullptr) {
|
||||||
|
OPENSSL_load_builtin_modules();
|
||||||
|
#ifndef OPENSSL_NO_ENGINE
|
||||||
|
ENGINE_load_builtin_engines();
|
||||||
|
#endif
|
||||||
|
ERR_clear_error();
|
||||||
CONF_modules_load_file(
|
CONF_modules_load_file(
|
||||||
openssl_config,
|
openssl_config,
|
||||||
nullptr,
|
nullptr,
|
||||||
CONF_MFLAGS_DEFAULT_SECTION | CONF_MFLAGS_IGNORE_MISSING_FILE);
|
CONF_MFLAGS_DEFAULT_SECTION);
|
||||||
int err = ERR_get_error();
|
int err = ERR_get_error();
|
||||||
if (0 != err) {
|
if (0 != err) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -5786,7 +5792,6 @@ void InitCryptoOnce() {
|
|||||||
|
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
OpenSSL_add_all_algorithms();
|
OpenSSL_add_all_algorithms();
|
||||||
SSL_load_error_strings();
|
|
||||||
|
|
||||||
crypto_lock_init();
|
crypto_lock_init();
|
||||||
CRYPTO_set_locking_callback(crypto_lock_cb);
|
CRYPTO_set_locking_callback(crypto_lock_cb);
|
||||||
|
@ -32,6 +32,10 @@ struct sockaddr;
|
|||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
|
// Set in node.cc by ParseArgs with the value of --openssl-config.
|
||||||
|
// Used in node_crypto.cc when initializing OpenSSL.
|
||||||
|
extern const char* openssl_config;
|
||||||
|
|
||||||
// Set in node.cc by ParseArgs when --preserve-symlinks is used.
|
// Set in node.cc by ParseArgs when --preserve-symlinks is used.
|
||||||
// Used in node_config.cc to set a constant on process.binding('config')
|
// Used in node_config.cc to set a constant on process.binding('config')
|
||||||
// that is used by lib/module.js
|
// that is used by lib/module.js
|
||||||
|
@ -88,12 +88,26 @@ testHelper(
|
|||||||
// OpenSSL config file should be able to turn on FIPS mode
|
// OpenSSL config file should be able to turn on FIPS mode
|
||||||
testHelper(
|
testHelper(
|
||||||
'stdout',
|
'stdout',
|
||||||
[],
|
[`--openssl-config=${CNF_FIPS_ON}`],
|
||||||
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
|
compiledWithFips() ? FIPS_ENABLED : FIPS_DISABLED,
|
||||||
'require("crypto").fips',
|
'require("crypto").fips',
|
||||||
|
process.env);
|
||||||
|
// OPENSSL_CONF should _not_ be able to turn on FIPS mode
|
||||||
|
testHelper(
|
||||||
|
'stdout',
|
||||||
|
[],
|
||||||
|
FIPS_DISABLED,
|
||||||
|
'require("crypto").fips',
|
||||||
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
|
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
|
||||||
|
|
||||||
// --enable-fips should take precedence over OpenSSL config file
|
// --enable-fips should take precedence over OpenSSL config file
|
||||||
|
testHelper(
|
||||||
|
compiledWithFips() ? 'stdout' : 'stderr',
|
||||||
|
['--enable-fips', `--openssl-config=${CNF_FIPS_OFF}`],
|
||||||
|
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
|
||||||
|
'require("crypto").fips',
|
||||||
|
process.env);
|
||||||
|
// OPENSSL_CONF should _not_ make a difference to --enable-fips
|
||||||
testHelper(
|
testHelper(
|
||||||
compiledWithFips() ? 'stdout' : 'stderr',
|
compiledWithFips() ? 'stdout' : 'stderr',
|
||||||
['--enable-fips'],
|
['--enable-fips'],
|
||||||
@ -102,6 +116,13 @@ testHelper(
|
|||||||
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
|
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
|
||||||
|
|
||||||
// --force-fips should take precedence over OpenSSL config file
|
// --force-fips should take precedence over OpenSSL config file
|
||||||
|
testHelper(
|
||||||
|
compiledWithFips() ? 'stdout' : 'stderr',
|
||||||
|
['--force-fips', `--openssl-config=${CNF_FIPS_OFF}`],
|
||||||
|
compiledWithFips() ? FIPS_ENABLED : OPTION_ERROR_STRING,
|
||||||
|
'require("crypto").fips',
|
||||||
|
process.env);
|
||||||
|
// Using OPENSSL_CONF should not make a difference to --force-fips
|
||||||
testHelper(
|
testHelper(
|
||||||
compiledWithFips() ? 'stdout' : 'stderr',
|
compiledWithFips() ? 'stdout' : 'stderr',
|
||||||
['--force-fips'],
|
['--force-fips'],
|
||||||
@ -116,7 +137,7 @@ testHelper(
|
|||||||
compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
|
compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
|
||||||
'(require("crypto").fips = true,' +
|
'(require("crypto").fips = true,' +
|
||||||
'require("crypto").fips)',
|
'require("crypto").fips)',
|
||||||
addToEnv('OPENSSL_CONF', ''));
|
process.env);
|
||||||
|
|
||||||
// setFipsCrypto should be able to turn FIPS mode on and off
|
// setFipsCrypto should be able to turn FIPS mode on and off
|
||||||
testHelper(
|
testHelper(
|
||||||
@ -126,25 +147,25 @@ testHelper(
|
|||||||
'(require("crypto").fips = true,' +
|
'(require("crypto").fips = true,' +
|
||||||
'require("crypto").fips = false,' +
|
'require("crypto").fips = false,' +
|
||||||
'require("crypto").fips)',
|
'require("crypto").fips)',
|
||||||
addToEnv('OPENSSL_CONF', ''));
|
process.env);
|
||||||
|
|
||||||
// setFipsCrypto takes precedence over OpenSSL config file, FIPS on
|
// setFipsCrypto takes precedence over OpenSSL config file, FIPS on
|
||||||
testHelper(
|
testHelper(
|
||||||
compiledWithFips() ? 'stdout' : 'stderr',
|
compiledWithFips() ? 'stdout' : 'stderr',
|
||||||
[],
|
[`--openssl-config=${CNF_FIPS_OFF}`],
|
||||||
compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
|
compiledWithFips() ? FIPS_ENABLED : FIPS_ERROR_STRING,
|
||||||
'(require("crypto").fips = true,' +
|
'(require("crypto").fips = true,' +
|
||||||
'require("crypto").fips)',
|
'require("crypto").fips)',
|
||||||
addToEnv('OPENSSL_CONF', CNF_FIPS_OFF));
|
process.env);
|
||||||
|
|
||||||
// setFipsCrypto takes precedence over OpenSSL config file, FIPS off
|
// setFipsCrypto takes precedence over OpenSSL config file, FIPS off
|
||||||
testHelper(
|
testHelper(
|
||||||
compiledWithFips() ? 'stdout' : 'stderr',
|
compiledWithFips() ? 'stdout' : 'stderr',
|
||||||
[],
|
[`--openssl-config=${CNF_FIPS_ON}`],
|
||||||
compiledWithFips() ? FIPS_DISABLED : FIPS_ERROR_STRING,
|
compiledWithFips() ? FIPS_DISABLED : FIPS_ERROR_STRING,
|
||||||
'(require("crypto").fips = false,' +
|
'(require("crypto").fips = false,' +
|
||||||
'require("crypto").fips)',
|
'require("crypto").fips)',
|
||||||
addToEnv('OPENSSL_CONF', CNF_FIPS_ON));
|
process.env);
|
||||||
|
|
||||||
// --enable-fips does not prevent use of setFipsCrypto API
|
// --enable-fips does not prevent use of setFipsCrypto API
|
||||||
testHelper(
|
testHelper(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user