mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
crypto: ability to select cert store at runtime
PR-URL: https://github.com/nodejs/node/pull/8334 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
This commit is contained in:
@@ -257,6 +257,24 @@ 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`.
|
||||
|
||||
### `--use-openssl-ca`, `--use-bundled-ca`
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
Use OpenSSL's default CA store or use bundled Mozilla CA store as supplied by
|
||||
current NodeJS version. The default store is selectable at build-time.
|
||||
|
||||
Using OpenSSL store allows for external modifications of the store. For most
|
||||
Linux and BSD distributions, this store is maintained by the distribution
|
||||
maintainers and system administrators. OpenSSL CA store location is dependent on
|
||||
configuration of the OpenSSL library but this can be altered at runtime using
|
||||
environmental variables.
|
||||
|
||||
The bundled CA store, as supplied by NodeJS, is a snapshot of Mozilla CA store
|
||||
that is fixed at release time. It is identical on all supported platforms.
|
||||
|
||||
See `SSL_CERT_DIR` and `SSL_CERT_FILE`.
|
||||
|
||||
### `--icu-data-dir=file`
|
||||
<!-- YAML
|
||||
@@ -350,6 +368,24 @@ misformatted, but any errors are otherwise ignored.
|
||||
Note that neither the well known nor extra certificates are used when the `ca`
|
||||
options property is explicitly specified for a TLS or HTTPS client or server.
|
||||
|
||||
### `SSL_CERT_DIR=dir`
|
||||
|
||||
If `--use-openssl-ca` is enabled, this overrides and sets OpenSSL's directory
|
||||
containing trusted certificates.
|
||||
|
||||
Note: Be aware that unless the child environment is explicitly set, this
|
||||
evironment variable will be inherited by any child processes, and if they use
|
||||
OpenSSL, it may cause them to trust the same CAs as node.
|
||||
|
||||
### `SSL_CERT_FILE=file`
|
||||
|
||||
If `--use-openssl-ca` is enabled, this overrides and sets OpenSSL's file
|
||||
containing trusted certificates.
|
||||
|
||||
Note: Be aware that unless the child environment is explicitly set, this
|
||||
evironment variable will be inherited by any child processes, and if they use
|
||||
OpenSSL, it may cause them to trust the same CAs as node.
|
||||
|
||||
[emit_warning]: process.html#process_process_emitwarning_warning_name_ctor
|
||||
[Buffer]: buffer.html#buffer_buffer
|
||||
[debugger]: debugger.html
|
||||
|
||||
25
doc/node.1
25
doc/node.1
@@ -180,6 +180,22 @@ 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
|
||||
.BR \-\-use\-openssl\-ca,\-\-use\-bundled\-ca
|
||||
Use OpenSSL's default CA store or use bundled Mozilla CA store as supplied by
|
||||
current NodeJS version. The default store is selectable at build-time.
|
||||
|
||||
Using OpenSSL store allows for external modifications of the store. For most
|
||||
Linux and BSD distributions, this store is maintained by the distribution
|
||||
maintainers and system administrators. OpenSSL CA store location is dependent on
|
||||
configuration of the OpenSSL library but this can be altered at runtime using
|
||||
environmental variables.
|
||||
|
||||
The bundled CA store, as supplied by NodeJS, is a snapshot of Mozilla CA store
|
||||
that is fixed at release time. It is identical on all supported platforms.
|
||||
|
||||
See \fBSSL_CERT_DIR\fR and \fBSSL_CERT_FILE\fR.
|
||||
|
||||
.TP
|
||||
.BR \-\-icu\-data\-dir =\fIfile\fR
|
||||
Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR)
|
||||
@@ -228,6 +244,15 @@ asynchronous when outputting to a TTY on platforms which support async stdio.
|
||||
Setting this will void any guarantee that stdio will not be interleaved or
|
||||
dropped at program exit. \fBAvoid use.\fR
|
||||
|
||||
.TP
|
||||
.BR SSL_CERT_DIR = \fIdir\fR
|
||||
If \fB\-\-use\-openssl\-ca\fR is enabled, this overrides and sets OpenSSL's directory
|
||||
containing trusted certificates.
|
||||
|
||||
.TP
|
||||
.BR SSL_CERT_FILE = \fIfile\fR
|
||||
If \fB\-\-use\-openssl\-ca\fR is enabled, this overrides and sets OpenSSL's
|
||||
file containing trusted certificates.
|
||||
|
||||
.SH BUGS
|
||||
Bugs are tracked in GitHub Issues:
|
||||
|
||||
22
src/node.cc
22
src/node.cc
@@ -163,6 +163,14 @@ static const char* icu_data_dir = nullptr;
|
||||
bool no_deprecation = false;
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
// use OpenSSL's cert store instead of bundled certs
|
||||
bool ssl_openssl_cert_store =
|
||||
#if defined(NODE_OPENSSL_CERT_STORE)
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
|
||||
# if NODE_FIPS_MODE
|
||||
// used by crypto module
|
||||
bool enable_fips_crypto = false;
|
||||
@@ -3508,6 +3516,16 @@ static void PrintHelp() {
|
||||
#if HAVE_OPENSSL
|
||||
" --tls-cipher-list=val use an alternative default TLS cipher "
|
||||
"list\n"
|
||||
" --use-bundled-ca use bundled CA store"
|
||||
#if !defined(NODE_OPENSSL_CERT_STORE)
|
||||
" (default)"
|
||||
#endif
|
||||
"\n"
|
||||
" --use-openssl-ca use OpenSSL's default CA store"
|
||||
#if defined(NODE_OPENSSL_CERT_STORE)
|
||||
" (default)"
|
||||
#endif
|
||||
"\n"
|
||||
#if NODE_FIPS_MODE
|
||||
" --enable-fips enable FIPS crypto at startup\n"
|
||||
" --force-fips force FIPS crypto (cannot be disabled)\n"
|
||||
@@ -3681,6 +3699,10 @@ static void ParseArgs(int* argc,
|
||||
#if HAVE_OPENSSL
|
||||
} else if (strncmp(arg, "--tls-cipher-list=", 18) == 0) {
|
||||
default_cipher_list = arg + 18;
|
||||
} else if (strncmp(arg, "--use-openssl-ca", 16) == 0) {
|
||||
ssl_openssl_cert_store = true;
|
||||
} else if (strncmp(arg, "--use-bundled-ca", 16) == 0) {
|
||||
ssl_openssl_cert_store = false;
|
||||
#if NODE_FIPS_MODE
|
||||
} else if (strcmp(arg, "--enable-fips") == 0) {
|
||||
enable_fips_crypto = true;
|
||||
|
||||
@@ -180,9 +180,12 @@ typedef intptr_t ssize_t;
|
||||
namespace node {
|
||||
|
||||
NODE_EXTERN extern bool no_deprecation;
|
||||
#if HAVE_OPENSSL && NODE_FIPS_MODE
|
||||
#if HAVE_OPENSSL
|
||||
NODE_EXTERN extern bool ssl_openssl_cert_store;
|
||||
# if NODE_FIPS_MODE
|
||||
NODE_EXTERN extern bool enable_fips_crypto;
|
||||
NODE_EXTERN extern bool force_fips_crypto;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
NODE_EXTERN int Start(int argc, char *argv[]);
|
||||
|
||||
@@ -707,14 +707,14 @@ static X509_STORE* NewRootCertStore() {
|
||||
}
|
||||
|
||||
X509_STORE* store = X509_STORE_new();
|
||||
#if defined(NODE_OPENSSL_CERT_STORE)
|
||||
X509_STORE_set_default_paths(store);
|
||||
#else
|
||||
for (X509 *cert : root_certs_vector) {
|
||||
X509_up_ref(cert);
|
||||
X509_STORE_add_cert(store, cert);
|
||||
if (ssl_openssl_cert_store) {
|
||||
X509_STORE_set_default_paths(store);
|
||||
} else {
|
||||
for (X509 *cert : root_certs_vector) {
|
||||
X509_up_ref(cert);
|
||||
X509_STORE_add_cert(store, cert);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user