@@ -101,11 +101,11 @@ static thread_local X509_STORE* root_cert_store = nullptr;
101101// from this set.
102102static thread_local std::unique_ptr<X509Set> root_certs_from_users;
103103
104- X509_STORE* GetOrCreateRootCertStore () {
104+ X509_STORE* GetOrCreateRootCertStore (Environment* env ) {
105105 if (root_cert_store != nullptr ) {
106106 return root_cert_store;
107107 }
108- root_cert_store = NewRootCertStore ();
108+ root_cert_store = NewRootCertStore (env );
109109 return root_cert_store;
110110}
111111
@@ -838,6 +838,7 @@ static std::vector<X509*>& GetExtraCACertificates() {
838838}
839839
840840static void LoadCACertificates (void * data) {
841+ Environment* env = static_cast <Environment*>(data);
841842 per_process::Debug (DebugCategory::CRYPTO,
842843 " Started loading bundled root certificates off-thread\n " );
843844 GetBundledRootCertificates ();
@@ -850,7 +851,7 @@ static void LoadCACertificates(void* data) {
850851
851852 {
852853 Mutex::ScopedLock cli_lock (node::per_process::cli_options_mutex);
853- if (!per_process::cli_options ->use_system_ca ) {
854+ if (!env-> options () ->use_system_ca ) {
854855 return ;
855856 }
856857 }
@@ -894,7 +895,8 @@ void StartLoadingCertificatesOffThread(
894895 return ;
895896 }
896897 tried_cert_loading_off_thread.store (true );
897- int r = uv_thread_create (&cert_loading_thread, LoadCACertificates, nullptr );
898+ Environment* env = Environment::GetCurrent (args);
899+ int r = uv_thread_create (&cert_loading_thread, LoadCACertificates, env);
898900 cert_loading_thread_started.store (r == 0 );
899901 if (r != 0 ) {
900902 FPrintF (stderr,
@@ -924,13 +926,13 @@ void StartLoadingCertificatesOffThread(
924926// with all the other flags.
925927// 7. Certificates from --use-bundled-ca, --use-system-ca and
926928// NODE_EXTRA_CA_CERTS are cached after first load. Certificates
927- // from --use-system -ca are not cached and always reloaded from
929+ // from --use-openssl -ca are not cached and always reloaded from
928930// disk.
929931// 8. If users have reset the root cert store by calling
930932// tls.setDefaultCACertificates(), the store will be populated with
931933// the certificates provided by users.
932934// TODO(joyeecheung): maybe these rules need a bit of consolidation?
933- X509_STORE* NewRootCertStore () {
935+ X509_STORE* NewRootCertStore (Environment* env ) {
934936 X509_STORE* store = X509_STORE_new ();
935937 CHECK_NOT_NULL (store);
936938
@@ -959,7 +961,7 @@ X509_STORE* NewRootCertStore() {
959961 for (X509* cert : GetBundledRootCertificates ()) {
960962 CHECK_EQ (1 , X509_STORE_add_cert (store, cert));
961963 }
962- if (per_process::cli_options ->use_system_ca ) {
964+ if (env-> options () ->use_system_ca ) {
963965 for (X509* cert : GetSystemStoreCACertificates ()) {
964966 CHECK_EQ (1 , X509_STORE_add_cert (store, cert));
965967 }
@@ -1166,7 +1168,7 @@ void ResetRootCertStore(const FunctionCallbackInfo<Value>& args) {
11661168
11671169 // TODO(joyeecheung): we can probably just reset it to nullptr
11681170 // and let the next call to NewRootCertStore() create a new one.
1169- root_cert_store = NewRootCertStore () ;
1171+ root_cert_store = nullptr ;
11701172}
11711173
11721174void GetSystemCACertificates (const FunctionCallbackInfo<Value>& args) {
@@ -1676,11 +1678,12 @@ void SecureContext::SetX509StoreFlag(unsigned long flags) {
16761678}
16771679
16781680X509_STORE* SecureContext::GetCertStoreOwnedByThisSecureContext () {
1681+ Environment* env = this ->env ();
16791682 if (own_cert_store_cache_ != nullptr ) return own_cert_store_cache_;
16801683
16811684 X509_STORE* cert_store = SSL_CTX_get_cert_store (ctx_.get ());
1682- if (cert_store == GetOrCreateRootCertStore ()) {
1683- cert_store = NewRootCertStore ();
1685+ if (cert_store == GetOrCreateRootCertStore (env )) {
1686+ cert_store = NewRootCertStore (env );
16841687 SSL_CTX_set_cert_store (ctx_.get (), cert_store);
16851688 }
16861689
@@ -1753,7 +1756,8 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
17531756
17541757void SecureContext::SetRootCerts () {
17551758 ClearErrorOnReturn clear_error_on_return;
1756- auto store = GetOrCreateRootCertStore ();
1759+ Environment* env = this ->env ();
1760+ auto store = GetOrCreateRootCertStore (env);
17571761
17581762 // Increment reference count so global store is not deleted along with CTX.
17591763 X509_STORE_up_ref (store);
0 commit comments