@@ -229,7 +229,9 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) {
229229}
230230
231231
232- static int CryptoPemCallback (char *buf, int size, int rwflag, void *u) {
232+ // This callback is used by OpenSSL when it needs to query for the passphrase
233+ // which may be used for encrypted PEM structures.
234+ static int PasswordCallback (char *buf, int size, int rwflag, void *u) {
233235 if (u) {
234236 size_t buflen = static_cast <size_t >(size);
235237 size_t len = strlen (static_cast <const char *>(u));
@@ -485,7 +487,7 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
485487
486488 EVP_PKEY* key = PEM_read_bio_PrivateKey (bio,
487489 nullptr ,
488- CryptoPemCallback ,
490+ PasswordCallback ,
489491 len == 1 ? nullptr : *passphrase);
490492
491493 if (!key) {
@@ -611,7 +613,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
611613 // that we are interested in
612614 ERR_clear_error ();
613615
614- x = PEM_read_bio_X509_AUX (in, nullptr , CryptoPemCallback , nullptr );
616+ x = PEM_read_bio_X509_AUX (in, nullptr , PasswordCallback , nullptr );
615617
616618 if (x == nullptr ) {
617619 SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB);
@@ -629,7 +631,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
629631 goto done;
630632 }
631633
632- while ((extra = PEM_read_bio_X509 (in, nullptr , CryptoPemCallback , nullptr ))) {
634+ while ((extra = PEM_read_bio_X509 (in, nullptr , PasswordCallback , nullptr ))) {
633635 if (sk_X509_push (extra_certs, extra))
634636 continue ;
635637
@@ -725,7 +727,7 @@ static X509_STORE* NewRootCertStore() {
725727 if (root_certs_vector.empty ()) {
726728 for (size_t i = 0 ; i < arraysize (root_certs); i++) {
727729 BIO* bp = NodeBIO::NewFixed (root_certs[i], strlen (root_certs[i]));
728- X509 *x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
730+ X509 *x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
729731 BIO_free (bp);
730732
731733 // Parse errors from the built-in roots are fatal.
@@ -768,7 +770,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
768770
769771 X509_STORE* cert_store = SSL_CTX_get_cert_store (sc->ctx_ );
770772 while (X509* x509 =
771- PEM_read_bio_X509 (bio, nullptr , CryptoPemCallback , nullptr )) {
773+ PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
772774 if (cert_store == root_cert_store) {
773775 cert_store = NewRootCertStore ();
774776 SSL_CTX_set_cert_store (sc->ctx_ , cert_store);
@@ -800,7 +802,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
800802 return ;
801803
802804 X509_CRL* crl =
803- PEM_read_bio_X509_CRL (bio, nullptr , CryptoPemCallback , nullptr );
805+ PEM_read_bio_X509_CRL (bio, nullptr , PasswordCallback , nullptr );
804806
805807 if (crl == nullptr ) {
806808 BIO_free_all (bio);
@@ -839,7 +841,7 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
839841 }
840842
841843 while (X509* x509 =
842- PEM_read_bio_X509 (bio, nullptr , CryptoPemCallback , nullptr )) {
844+ PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
843845 X509_STORE_add_cert (store, x509);
844846 X509_free (x509);
845847 }
@@ -4158,7 +4160,7 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
41584160
41594161 pkey = PEM_read_bio_PrivateKey (bp,
41604162 nullptr ,
4161- CryptoPemCallback ,
4163+ PasswordCallback ,
41624164 const_cast <char *>(passphrase));
41634165
41644166 // Errors might be injected into OpenSSL's error stack
@@ -4383,12 +4385,12 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
43834385 // Split this out into a separate function once we have more than one
43844386 // consumer of public keys.
43854387 if (strncmp (key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0 ) {
4386- pkey = PEM_read_bio_PUBKEY (bp, nullptr , CryptoPemCallback , nullptr );
4388+ pkey = PEM_read_bio_PUBKEY (bp, nullptr , PasswordCallback , nullptr );
43874389 if (pkey == nullptr )
43884390 goto exit;
43894391 } else if (strncmp (key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0 ) {
43904392 RSA* rsa =
4391- PEM_read_bio_RSAPublicKey (bp, nullptr , CryptoPemCallback , nullptr );
4393+ PEM_read_bio_RSAPublicKey (bp, nullptr , PasswordCallback , nullptr );
43924394 if (rsa) {
43934395 pkey = EVP_PKEY_new ();
43944396 if (pkey)
@@ -4399,7 +4401,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
43994401 goto exit;
44004402 } else {
44014403 // X.509 fallback
4402- x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
4404+ x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
44034405 if (x509 == nullptr )
44044406 goto exit;
44054407
@@ -4526,7 +4528,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
45264528 goto exit;
45274529 } else if (operation == kPublic &&
45284530 strncmp (key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0 ) {
4529- x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
4531+ x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
45304532 if (x509 == nullptr )
45314533 goto exit;
45324534
@@ -4536,7 +4538,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
45364538 } else {
45374539 pkey = PEM_read_bio_PrivateKey (bp,
45384540 nullptr ,
4539- CryptoPemCallback ,
4541+ PasswordCallback ,
45404542 const_cast <char *>(passphrase));
45414543 if (pkey == nullptr )
45424544 goto exit;
0 commit comments