@@ -204,7 +204,9 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) {
204
204
}
205
205
206
206
207
- static int CryptoPemCallback (char *buf, int size, int rwflag, void *u) {
207
+ // This callback is used by OpenSSL when it needs to query for the passphrase
208
+ // which may be used for encrypted PEM structures.
209
+ static int PasswordCallback (char *buf, int size, int rwflag, void *u) {
208
210
if (u) {
209
211
size_t buflen = static_cast <size_t >(size);
210
212
size_t len = strlen (static_cast <const char *>(u));
@@ -460,7 +462,7 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
460
462
461
463
EVP_PKEY* key = PEM_read_bio_PrivateKey (bio,
462
464
nullptr ,
463
- CryptoPemCallback ,
465
+ PasswordCallback ,
464
466
len == 1 ? nullptr : *passphrase);
465
467
466
468
if (!key) {
@@ -586,7 +588,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
586
588
// that we are interested in
587
589
ERR_clear_error ();
588
590
589
- x = PEM_read_bio_X509_AUX (in, nullptr , CryptoPemCallback , nullptr );
591
+ x = PEM_read_bio_X509_AUX (in, nullptr , PasswordCallback , nullptr );
590
592
591
593
if (x == nullptr ) {
592
594
SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB);
@@ -604,7 +606,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
604
606
goto done;
605
607
}
606
608
607
- while ((extra = PEM_read_bio_X509 (in, nullptr , CryptoPemCallback , nullptr ))) {
609
+ while ((extra = PEM_read_bio_X509 (in, nullptr , PasswordCallback , nullptr ))) {
608
610
if (sk_X509_push (extra_certs, extra))
609
611
continue ;
610
612
@@ -700,7 +702,7 @@ static X509_STORE* NewRootCertStore() {
700
702
if (root_certs_vector.empty ()) {
701
703
for (size_t i = 0 ; i < arraysize (root_certs); i++) {
702
704
BIO* bp = NodeBIO::NewFixed (root_certs[i], strlen (root_certs[i]));
703
- X509 *x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
705
+ X509 *x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
704
706
BIO_free (bp);
705
707
706
708
// Parse errors from the built-in roots are fatal.
@@ -743,7 +745,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
743
745
744
746
X509_STORE* cert_store = SSL_CTX_get_cert_store (sc->ctx_ );
745
747
while (X509* x509 =
746
- PEM_read_bio_X509 (bio, nullptr , CryptoPemCallback , nullptr )) {
748
+ PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
747
749
if (cert_store == root_cert_store) {
748
750
cert_store = NewRootCertStore ();
749
751
SSL_CTX_set_cert_store (sc->ctx_ , cert_store);
@@ -775,7 +777,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
775
777
return ;
776
778
777
779
X509_CRL* crl =
778
- PEM_read_bio_X509_CRL (bio, nullptr , CryptoPemCallback , nullptr );
780
+ PEM_read_bio_X509_CRL (bio, nullptr , PasswordCallback , nullptr );
779
781
780
782
if (crl == nullptr ) {
781
783
BIO_free_all (bio);
@@ -814,7 +816,7 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
814
816
}
815
817
816
818
while (X509* x509 =
817
- PEM_read_bio_X509 (bio, nullptr , CryptoPemCallback , nullptr )) {
819
+ PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
818
820
X509_STORE_add_cert (store, x509);
819
821
X509_free (x509);
820
822
}
@@ -4080,7 +4082,7 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
4080
4082
4081
4083
pkey = PEM_read_bio_PrivateKey (bp,
4082
4084
nullptr ,
4083
- CryptoPemCallback ,
4085
+ PasswordCallback ,
4084
4086
const_cast <char *>(passphrase));
4085
4087
4086
4088
// Errors might be injected into OpenSSL's error stack
@@ -4293,12 +4295,12 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4293
4295
// Split this out into a separate function once we have more than one
4294
4296
// consumer of public keys.
4295
4297
if (strncmp (key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0 ) {
4296
- pkey = PEM_read_bio_PUBKEY (bp, nullptr , CryptoPemCallback , nullptr );
4298
+ pkey = PEM_read_bio_PUBKEY (bp, nullptr , PasswordCallback , nullptr );
4297
4299
if (pkey == nullptr )
4298
4300
goto exit;
4299
4301
} else if (strncmp (key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0 ) {
4300
4302
RSA* rsa =
4301
- PEM_read_bio_RSAPublicKey (bp, nullptr , CryptoPemCallback , nullptr );
4303
+ PEM_read_bio_RSAPublicKey (bp, nullptr , PasswordCallback , nullptr );
4302
4304
if (rsa) {
4303
4305
pkey = EVP_PKEY_new ();
4304
4306
if (pkey)
@@ -4309,7 +4311,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4309
4311
goto exit;
4310
4312
} else {
4311
4313
// X.509 fallback
4312
- x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
4314
+ x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4313
4315
if (x509 == nullptr )
4314
4316
goto exit;
4315
4317
@@ -4427,7 +4429,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
4427
4429
goto exit;
4428
4430
} else if (operation == kPublic &&
4429
4431
strncmp (key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0 ) {
4430
- x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback , nullptr );
4432
+ x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4431
4433
if (x509 == nullptr )
4432
4434
goto exit;
4433
4435
@@ -4437,7 +4439,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
4437
4439
} else {
4438
4440
pkey = PEM_read_bio_PrivateKey (bp,
4439
4441
nullptr ,
4440
- CryptoPemCallback ,
4442
+ PasswordCallback ,
4441
4443
const_cast <char *>(passphrase));
4442
4444
if (pkey == nullptr )
4443
4445
goto exit;
0 commit comments