Skip to content

Commit 17dc7de

Browse files
committed
crypto: make --use-system-ca per-env rather than per-process
1 parent 47d8b88 commit 17dc7de

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

src/crypto/crypto_common.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ MaybeLocal<Value> GetValidationErrorReason(Environment* env, int err) {
6161
(err == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE) ||
6262
(err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ||
6363
((err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT) &&
64-
!per_process::cli_options->use_system_ca);
64+
!env->options()->use_system_ca);
6565

6666
if (suggest_system_ca) {
6767
reason.append("; if the root CA is installed locally, "

src/crypto/crypto_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ static void LoadCACertificates(void* data) {
873873

874874
{
875875
Mutex::ScopedLock cli_lock(node::per_process::cli_options_mutex);
876-
if (!per_process::cli_options->use_system_ca) {
876+
if (!per_process::cli_options->per_isolate->per_env->use_system_ca) {
877877
return;
878878
}
879879
}
@@ -982,7 +982,7 @@ X509_STORE* NewRootCertStore() {
982982
for (X509* cert : GetBundledRootCertificates()) {
983983
CHECK_EQ(1, X509_STORE_add_cert(store, cert));
984984
}
985-
if (per_process::cli_options->use_system_ca) {
985+
if (per_process::cli_options->per_isolate->per_env->use_system_ca) {
986986
for (X509* cert : GetSystemStoreCACertificates()) {
987987
CHECK_EQ(1, X509_STORE_add_cert(store, cert));
988988
}

src/node.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -871,15 +871,6 @@ static ExitCode InitializeNodeWithArgsInternal(
871871
// default value.
872872
V8::SetFlagsFromString("--rehash-snapshot");
873873

874-
#if HAVE_OPENSSL
875-
// TODO(joyeecheung): make this a per-env option and move the normalization
876-
// into HandleEnvOptions.
877-
std::string use_system_ca;
878-
if (credentials::SafeGetenv("NODE_USE_SYSTEM_CA", &use_system_ca) &&
879-
use_system_ca == "1") {
880-
per_process::cli_options->use_system_ca = true;
881-
}
882-
#endif // HAVE_OPENSSL
883874
HandleEnvOptions(per_process::cli_options->per_isolate->per_env);
884875

885876
std::string node_options;

src/node_options.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
10161016
&EnvironmentOptions::trace_env_native_stack,
10171017
kAllowedInEnvvar);
10181018

1019+
AddOption("--use-system-ca",
1020+
"use system's CA store",
1021+
&EnvironmentOptions::use_system_ca,
1022+
kAllowedInEnvvar);
1023+
10191024
AddOption(
10201025
"--trace-require-module",
10211026
"Print access to require(esm). Options are 'all' (print all usage) and "
@@ -1356,10 +1361,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
13561361
,
13571362
&PerProcessOptions::use_openssl_ca,
13581363
kAllowedInEnvvar);
1359-
AddOption("--use-system-ca",
1360-
"use system's CA store",
1361-
&PerProcessOptions::use_system_ca,
1362-
kAllowedInEnvvar);
13631364
AddOption("--use-bundled-ca",
13641365
"use bundled CA store"
13651366
#if !defined(NODE_OPENSSL_CERT_STORE)
@@ -2098,6 +2099,10 @@ void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options,
20982099

20992100
env_options->use_env_proxy = opt_getter("NODE_USE_ENV_PROXY") == "1";
21002101

2102+
#if HAVE_OPENSSL
2103+
env_options->use_system_ca = opt_getter("NODE_USE_SYSTEM_CA") == "1";
2104+
#endif // HAVE_OPENSSL
2105+
21012106
if (env_options->redirect_warnings.empty())
21022107
env_options->redirect_warnings = opt_getter("NODE_REDIRECT_WARNINGS");
21032108
}

src/node_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class EnvironmentOptions : public Options {
221221
bool trace_env = false;
222222
bool trace_env_js_stack = false;
223223
bool trace_env_native_stack = false;
224+
bool use_system_ca = false;
224225
std::string trace_require_module;
225226
bool extra_info_on_fatal_exception = true;
226227
std::string unhandled_rejections;
@@ -357,7 +358,6 @@ class PerProcessOptions : public Options {
357358
bool ssl_openssl_cert_store = false;
358359
#endif
359360
bool use_openssl_ca = false;
360-
bool use_system_ca = false;
361361
bool use_bundled_ca = false;
362362
bool enable_fips_crypto = false;
363363
bool force_fips_crypto = false;

0 commit comments

Comments
 (0)