@@ -985,24 +985,6 @@ static X509_STORE* NewRootCertStore() {
985985}
986986
987987
988- void GetRootCertificates (const FunctionCallbackInfo<Value>& args) {
989- Environment* env = Environment::GetCurrent (args);
990- Local<Value> result[arraysize (root_certs)];
991-
992- for (size_t i = 0 ; i < arraysize (root_certs); i++) {
993- if (!String::NewFromOneByte (
994- env->isolate (),
995- reinterpret_cast <const uint8_t *>(root_certs[i]),
996- NewStringType::kNormal ).ToLocal (&result[i])) {
997- return ;
998- }
999- }
1000-
1001- args.GetReturnValue ().Set (
1002- Array::New (env->isolate (), result, arraysize (root_certs)));
1003- }
1004-
1005-
1006988void SecureContext::AddCACert (const FunctionCallbackInfo<Value>& args) {
1007989 Environment* env = Environment::GetCurrent (args);
1008990
@@ -2645,6 +2627,21 @@ static inline Local<Value> BIOToStringOrBuffer(Environment* env,
26452627 }
26462628}
26472629
2630+ static MaybeLocal<Value> X509ToPEM (Environment* env, X509 * cert) {
2631+ BIOPointer bio (BIO_new (BIO_s_mem ()));
2632+ if (!bio) {
2633+ ThrowCryptoError (env, ERR_get_error (), " BIO_new" );
2634+ return MaybeLocal<Value>();
2635+ }
2636+
2637+ if (PEM_write_bio_X509 (bio.get (), cert) == 0 ) {
2638+ ThrowCryptoError (env, ERR_get_error (), " PEM_write_bio_X509" );
2639+ return MaybeLocal<Value>();
2640+ }
2641+
2642+ return BIOToStringOrBuffer (env, bio.get (), kKeyFormatPEM );
2643+ }
2644+
26482645static bool WritePublicKeyInner (EVP_PKEY * pkey,
26492646 const BIOPointer& bio,
26502647 const PublicKeyEncodingConfig& config) {
@@ -6513,6 +6510,36 @@ void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
65136510}
65146511
65156512
6513+ void GetRootCertificates (const FunctionCallbackInfo<Value>& args) {
6514+ Environment* env = Environment::GetCurrent (args);
6515+
6516+ if (root_cert_store == nullptr )
6517+ root_cert_store = NewRootCertStore ();
6518+
6519+ stack_st_X509_OBJECT* objs = X509_STORE_get0_objects (root_cert_store);
6520+ int num_objs = sk_X509_OBJECT_num (objs);
6521+
6522+ std::vector<Local<Value>> result;
6523+ result.reserve (num_objs);
6524+
6525+ for (int i = 0 ; i < num_objs; i++) {
6526+ X509_OBJECT * obj = sk_X509_OBJECT_value (objs, i);
6527+ if (X509_OBJECT_get_type (obj) == X509_LU_X509 ) {
6528+ X509 * cert = X509_OBJECT_get0_X509 (obj);
6529+
6530+ Local<Value> value;
6531+ if (!X509ToPEM (env, cert).ToLocal (&value))
6532+ return ;
6533+
6534+ result.push_back (value);
6535+ }
6536+ }
6537+
6538+ args.GetReturnValue ().Set (
6539+ Array::New (env->isolate (), result.data (), result.size ()));
6540+ }
6541+
6542+
65166543// Convert the input public key to compressed, uncompressed, or hybrid formats.
65176544void ConvertKey (const FunctionCallbackInfo<Value>& args) {
65186545 MarkPopErrorOnReturn mark_pop_error_on_return;
0 commit comments