Skip to content

Commit 19259f4

Browse files
danbevMylesBorins
authored andcommitted
src: rename CryptoPemCallback -> PasswordCallback
While reading through node_crypto.cc I think the code could perhaps be be a made a little clearer if CryptPemCallback was renamed. I admit that I'm very new to the code base and openssl but having a name like PasswordCallback or something similar would have helped me so I'm suggesting this change. PR-URL: #12787 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1d50980 commit 19259f4

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/node_crypto.cc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) {
204204
}
205205

206206

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) {
208210
if (u) {
209211
size_t buflen = static_cast<size_t>(size);
210212
size_t len = strlen(static_cast<const char*>(u));
@@ -460,7 +462,7 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {
460462

461463
EVP_PKEY* key = PEM_read_bio_PrivateKey(bio,
462464
nullptr,
463-
CryptoPemCallback,
465+
PasswordCallback,
464466
len == 1 ? nullptr : *passphrase);
465467

466468
if (!key) {
@@ -586,7 +588,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
586588
// that we are interested in
587589
ERR_clear_error();
588590

589-
x = PEM_read_bio_X509_AUX(in, nullptr, CryptoPemCallback, nullptr);
591+
x = PEM_read_bio_X509_AUX(in, nullptr, PasswordCallback, nullptr);
590592

591593
if (x == nullptr) {
592594
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,
604606
goto done;
605607
}
606608

607-
while ((extra = PEM_read_bio_X509(in, nullptr, CryptoPemCallback, nullptr))) {
609+
while ((extra = PEM_read_bio_X509(in, nullptr, PasswordCallback, nullptr))) {
608610
if (sk_X509_push(extra_certs, extra))
609611
continue;
610612

@@ -700,7 +702,7 @@ static X509_STORE* NewRootCertStore() {
700702
if (root_certs_vector.empty()) {
701703
for (size_t i = 0; i < arraysize(root_certs); i++) {
702704
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);
704706
BIO_free(bp);
705707

706708
// Parse errors from the built-in roots are fatal.
@@ -743,7 +745,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
743745

744746
X509_STORE* cert_store = SSL_CTX_get_cert_store(sc->ctx_);
745747
while (X509* x509 =
746-
PEM_read_bio_X509(bio, nullptr, CryptoPemCallback, nullptr)) {
748+
PEM_read_bio_X509(bio, nullptr, PasswordCallback, nullptr)) {
747749
if (cert_store == root_cert_store) {
748750
cert_store = NewRootCertStore();
749751
SSL_CTX_set_cert_store(sc->ctx_, cert_store);
@@ -775,7 +777,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
775777
return;
776778

777779
X509_CRL* crl =
778-
PEM_read_bio_X509_CRL(bio, nullptr, CryptoPemCallback, nullptr);
780+
PEM_read_bio_X509_CRL(bio, nullptr, PasswordCallback, nullptr);
779781

780782
if (crl == nullptr) {
781783
BIO_free_all(bio);
@@ -814,7 +816,7 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
814816
}
815817

816818
while (X509* x509 =
817-
PEM_read_bio_X509(bio, nullptr, CryptoPemCallback, nullptr)) {
819+
PEM_read_bio_X509(bio, nullptr, PasswordCallback, nullptr)) {
818820
X509_STORE_add_cert(store, x509);
819821
X509_free(x509);
820822
}
@@ -4080,7 +4082,7 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
40804082

40814083
pkey = PEM_read_bio_PrivateKey(bp,
40824084
nullptr,
4083-
CryptoPemCallback,
4085+
PasswordCallback,
40844086
const_cast<char*>(passphrase));
40854087

40864088
// Errors might be injected into OpenSSL's error stack
@@ -4293,12 +4295,12 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
42934295
// Split this out into a separate function once we have more than one
42944296
// consumer of public keys.
42954297
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);
42974299
if (pkey == nullptr)
42984300
goto exit;
42994301
} else if (strncmp(key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0) {
43004302
RSA* rsa =
4301-
PEM_read_bio_RSAPublicKey(bp, nullptr, CryptoPemCallback, nullptr);
4303+
PEM_read_bio_RSAPublicKey(bp, nullptr, PasswordCallback, nullptr);
43024304
if (rsa) {
43034305
pkey = EVP_PKEY_new();
43044306
if (pkey)
@@ -4309,7 +4311,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
43094311
goto exit;
43104312
} else {
43114313
// X.509 fallback
4312-
x509 = PEM_read_bio_X509(bp, nullptr, CryptoPemCallback, nullptr);
4314+
x509 = PEM_read_bio_X509(bp, nullptr, PasswordCallback, nullptr);
43134315
if (x509 == nullptr)
43144316
goto exit;
43154317

@@ -4427,7 +4429,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
44274429
goto exit;
44284430
} else if (operation == kPublic &&
44294431
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);
44314433
if (x509 == nullptr)
44324434
goto exit;
44334435

@@ -4437,7 +4439,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
44374439
} else {
44384440
pkey = PEM_read_bio_PrivateKey(bp,
44394441
nullptr,
4440-
CryptoPemCallback,
4442+
PasswordCallback,
44414443
const_cast<char*>(passphrase));
44424444
if (pkey == nullptr)
44434445
goto exit;

0 commit comments

Comments
 (0)