@@ -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
@@ -861,6 +861,7 @@ static std::vector<X509*>& GetExtraCACertificates() {
861861}
862862
863863static void LoadCACertificates (void * data) {
864+ Environment* env = static_cast <Environment*>(data);
864865 per_process::Debug (DebugCategory::CRYPTO,
865866 " Started loading bundled root certificates off-thread\n " );
866867 GetBundledRootCertificates ();
@@ -873,7 +874,7 @@ static void LoadCACertificates(void* data) {
873874
874875 {
875876 Mutex::ScopedLock cli_lock (node::per_process::cli_options_mutex);
876- if (!per_process::cli_options ->use_system_ca ) {
877+ if (!env-> options () ->use_system_ca ) {
877878 return ;
878879 }
879880 }
@@ -917,7 +918,8 @@ void StartLoadingCertificatesOffThread(
917918 return ;
918919 }
919920 tried_cert_loading_off_thread.store (true );
920- int r = uv_thread_create (&cert_loading_thread, LoadCACertificates, nullptr );
921+ Environment* env = Environment::GetCurrent (args);
922+ int r = uv_thread_create (&cert_loading_thread, LoadCACertificates, env);
921923 cert_loading_thread_started.store (r == 0 );
922924 if (r != 0 ) {
923925 FPrintF (stderr,
@@ -947,13 +949,13 @@ void StartLoadingCertificatesOffThread(
947949// with all the other flags.
948950// 7. Certificates from --use-bundled-ca, --use-system-ca and
949951// NODE_EXTRA_CA_CERTS are cached after first load. Certificates
950- // from --use-system -ca are not cached and always reloaded from
952+ // from --use-openssl -ca are not cached and always reloaded from
951953// disk.
952954// 8. If users have reset the root cert store by calling
953955// tls.setDefaultCACertificates(), the store will be populated with
954956// the certificates provided by users.
955957// TODO(joyeecheung): maybe these rules need a bit of consolidation?
956- X509_STORE* NewRootCertStore () {
958+ X509_STORE* NewRootCertStore (Environment* env ) {
957959 X509_STORE* store = X509_STORE_new ();
958960 CHECK_NOT_NULL (store);
959961
@@ -982,7 +984,7 @@ X509_STORE* NewRootCertStore() {
982984 for (X509* cert : GetBundledRootCertificates ()) {
983985 CHECK_EQ (1 , X509_STORE_add_cert (store, cert));
984986 }
985- if (per_process::cli_options ->use_system_ca ) {
987+ if (env-> options () ->use_system_ca ) {
986988 for (X509* cert : GetSystemStoreCACertificates ()) {
987989 CHECK_EQ (1 , X509_STORE_add_cert (store, cert));
988990 }
@@ -1189,7 +1191,7 @@ void ResetRootCertStore(const FunctionCallbackInfo<Value>& args) {
11891191
11901192 // TODO(joyeecheung): we can probably just reset it to nullptr
11911193 // and let the next call to NewRootCertStore() create a new one.
1192- root_cert_store = NewRootCertStore () ;
1194+ root_cert_store = nullptr ;
11931195}
11941196
11951197void GetSystemCACertificates (const FunctionCallbackInfo<Value>& args) {
@@ -1700,11 +1702,12 @@ void SecureContext::SetX509StoreFlag(unsigned long flags) {
17001702}
17011703
17021704X509_STORE* SecureContext::GetCertStoreOwnedByThisSecureContext () {
1705+ Environment* env = this ->env ();
17031706 if (own_cert_store_cache_ != nullptr ) return own_cert_store_cache_;
17041707
17051708 X509_STORE* cert_store = SSL_CTX_get_cert_store (ctx_.get ());
1706- if (cert_store == GetOrCreateRootCertStore ()) {
1707- cert_store = NewRootCertStore ();
1709+ if (cert_store == GetOrCreateRootCertStore (env )) {
1710+ cert_store = NewRootCertStore (env );
17081711 SSL_CTX_set_cert_store (ctx_.get (), cert_store);
17091712 }
17101713
@@ -1777,7 +1780,8 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
17771780
17781781void SecureContext::SetRootCerts () {
17791782 ClearErrorOnReturn clear_error_on_return;
1780- auto store = GetOrCreateRootCertStore ();
1783+ Environment* env = this ->env ();
1784+ auto store = GetOrCreateRootCertStore (env);
17811785
17821786 // Increment reference count so global store is not deleted along with CTX.
17831787 X509_STORE_up_ref (store);
0 commit comments