@@ -229,7 +229,9 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) {
229
229
}
230
230
231
231
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) {
233
235
if (u) {
234
236
size_t buflen = static_cast <size_t >(size);
235
237
size_t len = strlen (static_cast <const char *>(u));
@@ -485,7 +487,7 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
485
487
486
488
EVP_PKEY* key = PEM_read_bio_PrivateKey (bio,
487
489
nullptr ,
488
- CryptoPemCallback ,
490
+ PasswordCallback ,
489
491
len == 1 ? nullptr : *passphrase);
490
492
491
493
if (!key) {
@@ -611,7 +613,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
611
613
// that we are interested in
612
614
ERR_clear_error ();
613
615
614
- x = PEM_read_bio_X509_AUX (in, nullptr , CryptoPemCallback , nullptr );
616
+ x = PEM_read_bio_X509_AUX (in, nullptr , PasswordCallback , nullptr );
615
617
616
618
if (x == nullptr ) {
617
619
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,
629
631
goto done;
630
632
}
631
633
632
- while ((extra = PEM_read_bio_X509 (in, nullptr , CryptoPemCallback , nullptr ))) {
634
+ while ((extra = PEM_read_bio_X509 (in, nullptr , PasswordCallback , nullptr ))) {
633
635
if (sk_X509_push (extra_certs, extra))
634
636
continue ;
635
637
@@ -725,7 +727,7 @@ static X509_STORE* NewRootCertStore() {
725
727
if (root_certs_vector.empty ()) {
726
728
for (size_t i = 0 ; i < arraysize (root_certs); i++) {
727
729
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 );
729
731
BIO_free (bp);
730
732
731
733
// Parse errors from the built-in roots are fatal.
@@ -768,7 +770,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
768
770
769
771
X509_STORE* cert_store = SSL_CTX_get_cert_store (sc->ctx_ );
770
772
while (X509* x509 =
771
- PEM_read_bio_X509 (bio, nullptr , CryptoPemCallback , nullptr )) {
773
+ PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
772
774
if (cert_store == root_cert_store) {
773
775
cert_store = NewRootCertStore ();
774
776
SSL_CTX_set_cert_store (sc->ctx_ , cert_store);
@@ -800,7 +802,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
800
802
return ;
801
803
802
804
X509_CRL* crl =
803
- PEM_read_bio_X509_CRL (bio, nullptr , CryptoPemCallback , nullptr );
805
+ PEM_read_bio_X509_CRL (bio, nullptr , PasswordCallback , nullptr );
804
806
805
807
if (crl == nullptr ) {
806
808
BIO_free_all (bio);
@@ -839,7 +841,7 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
839
841
}
840
842
841
843
while (X509* x509 =
842
- PEM_read_bio_X509 (bio, nullptr , CryptoPemCallback , nullptr )) {
844
+ PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
843
845
X509_STORE_add_cert (store, x509);
844
846
X509_free (x509);
845
847
}
@@ -4158,7 +4160,7 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
4158
4160
4159
4161
pkey = PEM_read_bio_PrivateKey (bp,
4160
4162
nullptr ,
4161
- CryptoPemCallback ,
4163
+ PasswordCallback ,
4162
4164
const_cast <char *>(passphrase));
4163
4165
4164
4166
// Errors might be injected into OpenSSL's error stack
@@ -4383,12 +4385,12 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4383
4385
// Split this out into a separate function once we have more than one
4384
4386
// consumer of public keys.
4385
4387
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 );
4387
4389
if (pkey == nullptr )
4388
4390
goto exit ;
4389
4391
} else if (strncmp (key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0 ) {
4390
4392
RSA* rsa =
4391
- PEM_read_bio_RSAPublicKey (bp, nullptr , CryptoPemCallback , nullptr );
4393
+ PEM_read_bio_RSAPublicKey (bp, nullptr , PasswordCallback , nullptr );
4392
4394
if (rsa) {
4393
4395
pkey = EVP_PKEY_new ();
4394
4396
if (pkey)
@@ -4399,7 +4401,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4399
4401
goto exit ;
4400
4402
} else {
4401
4403
// X.509 fallback
4402
- x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
4404
+ x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4403
4405
if (x509 == nullptr )
4404
4406
goto exit ;
4405
4407
@@ -4526,7 +4528,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
4526
4528
goto exit ;
4527
4529
} else if (operation == kPublic &&
4528
4530
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 );
4530
4532
if (x509 == nullptr )
4531
4533
goto exit ;
4532
4534
@@ -4536,7 +4538,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
4536
4538
} else {
4537
4539
pkey = PEM_read_bio_PrivateKey (bp,
4538
4540
nullptr ,
4539
- CryptoPemCallback ,
4541
+ PasswordCallback ,
4540
4542
const_cast <char *>(passphrase));
4541
4543
if (pkey == nullptr )
4542
4544
goto exit ;
0 commit comments