@@ -116,10 +116,10 @@ static const char* const root_certs[] = {
116116
117117static const char system_cert_path[] = NODE_OPENSSL_SYSTEM_CERT_PATH;
118118
119- static std::string extra_root_certs_file; // NOLINT(runtime/string)
120-
121119static X509_STORE* root_cert_store;
122120
121+ static bool extra_root_certs_loaded = false ;
122+
123123// Just to generate static methods
124124template void SSLWrap<TLSWrap>::AddMethods(Environment* env,
125125 Local<FunctionTemplate> t);
@@ -832,11 +832,6 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
832832}
833833
834834
835- void UseExtraCaCerts (const std::string& file) {
836- extra_root_certs_file = file;
837- }
838-
839-
840835static unsigned long AddCertsFromFile ( // NOLINT(runtime/int)
841836 X509_STORE* store,
842837 const char * file) {
@@ -863,30 +858,44 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
863858 return err;
864859}
865860
866- void SecureContext::AddRootCerts (const FunctionCallbackInfo<Value>& args) {
867- SecureContext* sc;
868- ASSIGN_OR_RETURN_UNWRAP (&sc, args.Holder ());
861+
862+ void UseExtraCaCerts (const std::string& file) {
869863 ClearErrorOnReturn clear_error_on_return;
870864
871- if (! root_cert_store) {
865+ if (root_cert_store == nullptr ) {
872866 root_cert_store = NewRootCertStore ();
873867
874- if (!extra_root_certs_file .empty ()) {
868+ if (!file .empty ()) {
875869 unsigned long err = AddCertsFromFile ( // NOLINT(runtime/int)
876870 root_cert_store,
877- extra_root_certs_file .c_str ());
871+ file .c_str ());
878872 if (err) {
879- // We do not call back into JS after this line anyway, so ignoring
880- // the return value of ProcessEmitWarning does not affect how a
881- // possible exception would be propagated.
882- ProcessEmitWarning (sc->env (),
883- " Ignoring extra certs from `%s`, "
884- " load failed: %s\n " ,
885- extra_root_certs_file.c_str (),
886- ERR_error_string (err, nullptr ));
873+ fprintf (stderr,
874+ " Warning: Ignoring extra certs from `%s`, load failed: %s\n " ,
875+ file.c_str (),
876+ ERR_error_string (err, nullptr ));
877+ } else {
878+ extra_root_certs_loaded = true ;
887879 }
888880 }
889881 }
882+ }
883+
884+
885+ static void IsExtraRootCertsFileLoaded (
886+ const FunctionCallbackInfo<Value>& args) {
887+ return args.GetReturnValue ().Set (extra_root_certs_loaded);
888+ }
889+
890+
891+ void SecureContext::AddRootCerts (const FunctionCallbackInfo<Value>& args) {
892+ SecureContext* sc;
893+ ASSIGN_OR_RETURN_UNWRAP (&sc, args.Holder ());
894+ ClearErrorOnReturn clear_error_on_return;
895+
896+ if (root_cert_store == nullptr ) {
897+ root_cert_store = NewRootCertStore ();
898+ }
890899
891900 // Increment reference count so global store is not deleted along with CTX.
892901 X509_STORE_up_ref (root_cert_store);
@@ -5624,6 +5633,7 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
56245633}
56255634#endif /* NODE_FIPS_MODE */
56265635
5636+
56275637void Initialize (Local<Object> target,
56285638 Local<Value> unused,
56295639 Local<Context> context,
@@ -5644,6 +5654,9 @@ void Initialize(Local<Object> target,
56445654 env->SetMethodNoSideEffect (target, " certVerifySpkac" , VerifySpkac);
56455655 env->SetMethodNoSideEffect (target, " certExportPublicKey" , ExportPublicKey);
56465656 env->SetMethodNoSideEffect (target, " certExportChallenge" , ExportChallenge);
5657+ // Exposed for testing purposes only.
5658+ env->SetMethodNoSideEffect (target, " isExtraRootCertsFileLoaded" ,
5659+ IsExtraRootCertsFileLoaded);
56475660
56485661 env->SetMethodNoSideEffect (target, " ECDHConvertKey" , ConvertKey);
56495662#ifndef OPENSSL_NO_ENGINE
0 commit comments