@@ -116,10 +116,10 @@ static const char* const root_certs[] = {
116
116
117
117
static const char system_cert_path[] = NODE_OPENSSL_SYSTEM_CERT_PATH;
118
118
119
- static std::string extra_root_certs_file; // NOLINT(runtime/string)
120
-
121
119
static X509_STORE* root_cert_store;
122
120
121
+ static bool extra_root_certs_loaded = false ;
122
+
123
123
// Just to generate static methods
124
124
template void SSLWrap<TLSWrap>::AddMethods(Environment* env,
125
125
Local<FunctionTemplate> t);
@@ -832,11 +832,6 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
832
832
}
833
833
834
834
835
- void UseExtraCaCerts (const std::string& file) {
836
- extra_root_certs_file = file;
837
- }
838
-
839
-
840
835
static unsigned long AddCertsFromFile ( // NOLINT(runtime/int)
841
836
X509_STORE* store,
842
837
const char * file) {
@@ -863,30 +858,44 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
863
858
return err;
864
859
}
865
860
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) {
869
863
ClearErrorOnReturn clear_error_on_return;
870
864
871
- if (! root_cert_store) {
865
+ if (root_cert_store == nullptr ) {
872
866
root_cert_store = NewRootCertStore ();
873
867
874
- if (!extra_root_certs_file .empty ()) {
868
+ if (!file .empty ()) {
875
869
unsigned long err = AddCertsFromFile ( // NOLINT(runtime/int)
876
870
root_cert_store,
877
- extra_root_certs_file .c_str ());
871
+ file .c_str ());
878
872
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 ;
887
879
}
888
880
}
889
881
}
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
+ }
890
899
891
900
// Increment reference count so global store is not deleted along with CTX.
892
901
X509_STORE_up_ref (root_cert_store);
@@ -5624,6 +5633,7 @@ void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) {
5624
5633
}
5625
5634
#endif /* NODE_FIPS_MODE */
5626
5635
5636
+
5627
5637
void Initialize (Local<Object> target,
5628
5638
Local<Value> unused,
5629
5639
Local<Context> context,
@@ -5644,6 +5654,9 @@ void Initialize(Local<Object> target,
5644
5654
env->SetMethodNoSideEffect (target, " certVerifySpkac" , VerifySpkac);
5645
5655
env->SetMethodNoSideEffect (target, " certExportPublicKey" , ExportPublicKey);
5646
5656
env->SetMethodNoSideEffect (target, " certExportChallenge" , ExportChallenge);
5657
+ // Exposed for testing purposes only.
5658
+ env->SetMethodNoSideEffect (target, " isExtraRootCertsFileLoaded" ,
5659
+ IsExtraRootCertsFileLoaded);
5647
5660
5648
5661
env->SetMethodNoSideEffect (target, " ECDHConvertKey" , ConvertKey);
5649
5662
#ifndef OPENSSL_NO_ENGINE
0 commit comments