From be469d85da927b27b5b35f6e23f3e573309e2ae1 Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Thu, 25 May 2023 00:40:39 +0800 Subject: [PATCH] src: check node_extra_ca_certs after openssl cfg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I recently discovered that the custom NodeJS specific OpenSSL config section in openssl.cnf would not be respected, if the environment variable `NODE_EXTRA_CA_CERTS` was set. This happens even if it contains an invalid value, i.e no actual certs are read. Someone suggested moving the checking of extra ca certs to after the OpenSSL config is read, and this seems to work. PR-URL: https://github.com/nodejs/node/pull/48159 Reviewed-By: Richard Lau Reviewed-By: Tobias Nießen Reviewed-By: Minwoo Jung Reviewed-By: Michael Dawson --- src/node.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node.cc b/src/node.cc index acab0cb3d960b6..b29dc57d6011b5 100644 --- a/src/node.cc +++ b/src/node.cc @@ -961,11 +961,6 @@ InitializeOncePerProcessInternal(const std::vector& args, return ret; }; - { - std::string extra_ca_certs; - if (credentials::SafeGetenv("NODE_EXTRA_CA_CERTS", &extra_ca_certs)) - crypto::UseExtraCaCerts(extra_ca_certs); - } // In the case of FIPS builds we should make sure // the random source is properly initialized first. #if OPENSSL_VERSION_MAJOR >= 3 @@ -1052,6 +1047,12 @@ InitializeOncePerProcessInternal(const std::vector& args, CHECK(crypto::CSPRNG(buffer, length).is_ok()); return true; }); + + { + std::string extra_ca_certs; + if (credentials::SafeGetenv("NODE_EXTRA_CA_CERTS", &extra_ca_certs)) + crypto::UseExtraCaCerts(extra_ca_certs); + } #endif // HAVE_OPENSSL && !defined(OPENSSL_IS_BORINGSSL) }