@@ -229,8 +229,6 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) {
229
229
}
230
230
231
231
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
232
static int PasswordCallback (char *buf, int size, int rwflag, void *u) {
235
233
if (u) {
236
234
size_t buflen = static_cast <size_t >(size);
@@ -244,6 +242,16 @@ static int PasswordCallback(char *buf, int size, int rwflag, void *u) {
244
242
}
245
243
246
244
245
+ // This callback is used to avoid the default passphrase callback in OpenSSL
246
+ // which will typically prompt for the passphrase. The prompting is designed
247
+ // for the OpenSSL CLI, but works poorly for Node.js because it involves
248
+ // synchronous interaction with the controlling terminal, something we never
249
+ // want, and use this function to avoid it.
250
+ static int NoPasswordCallback (char *buf, int size, int rwflag, void *u) {
251
+ return 0 ;
252
+ }
253
+
254
+
247
255
void ThrowCryptoError (Environment* env,
248
256
unsigned long err, // NOLINT(runtime/int)
249
257
const char * default_message = nullptr ) {
@@ -613,7 +621,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
613
621
// that we are interested in
614
622
ERR_clear_error ();
615
623
616
- x = PEM_read_bio_X509_AUX (in, nullptr , PasswordCallback , nullptr );
624
+ x = PEM_read_bio_X509_AUX (in, nullptr , NoPasswordCallback , nullptr );
617
625
618
626
if (x == nullptr ) {
619
627
SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB);
@@ -631,7 +639,10 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
631
639
goto done;
632
640
}
633
641
634
- while ((extra = PEM_read_bio_X509 (in, nullptr , PasswordCallback, nullptr ))) {
642
+ while ((extra = PEM_read_bio_X509 (in,
643
+ nullptr ,
644
+ NoPasswordCallback,
645
+ nullptr ))) {
635
646
if (sk_X509_push (extra_certs, extra))
636
647
continue ;
637
648
@@ -728,7 +739,7 @@ static X509_STORE* NewRootCertStore() {
728
739
if (root_certs_vector.empty ()) {
729
740
for (size_t i = 0 ; i < arraysize (root_certs); i++) {
730
741
BIO* bp = NodeBIO::NewFixed (root_certs[i], strlen (root_certs[i]));
731
- X509 *x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
742
+ X509 *x509 = PEM_read_bio_X509 (bp, nullptr , NoPasswordCallback , nullptr );
732
743
BIO_free (bp);
733
744
734
745
// Parse errors from the built-in roots are fatal.
@@ -771,7 +782,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
771
782
772
783
X509_STORE* cert_store = SSL_CTX_get_cert_store (sc->ctx_ );
773
784
while (X509* x509 =
774
- PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
785
+ PEM_read_bio_X509 (bio, nullptr , NoPasswordCallback , nullptr )) {
775
786
if (cert_store == root_cert_store) {
776
787
cert_store = NewRootCertStore ();
777
788
SSL_CTX_set_cert_store (sc->ctx_ , cert_store);
@@ -803,7 +814,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
803
814
return ;
804
815
805
816
X509_CRL* crl =
806
- PEM_read_bio_X509_CRL (bio, nullptr , PasswordCallback , nullptr );
817
+ PEM_read_bio_X509_CRL (bio, nullptr , NoPasswordCallback , nullptr );
807
818
808
819
if (crl == nullptr ) {
809
820
BIO_free_all (bio);
@@ -842,7 +853,7 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
842
853
}
843
854
844
855
while (X509* x509 =
845
- PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
856
+ PEM_read_bio_X509 (bio, nullptr , NoPasswordCallback , nullptr )) {
846
857
X509_STORE_add_cert (store, x509);
847
858
X509_free (x509);
848
859
}
@@ -4387,7 +4398,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4387
4398
// Split this out into a separate function once we have more than one
4388
4399
// consumer of public keys.
4389
4400
if (strncmp (key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0 ) {
4390
- pkey = PEM_read_bio_PUBKEY (bp, nullptr , PasswordCallback , nullptr );
4401
+ pkey = PEM_read_bio_PUBKEY (bp, nullptr , NoPasswordCallback , nullptr );
4391
4402
if (pkey == nullptr )
4392
4403
goto exit ;
4393
4404
} else if (strncmp (key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0 ) {
@@ -4403,7 +4414,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4403
4414
goto exit ;
4404
4415
} else {
4405
4416
// X.509 fallback
4406
- x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4417
+ x509 = PEM_read_bio_X509 (bp, nullptr , NoPasswordCallback , nullptr );
4407
4418
if (x509 == nullptr )
4408
4419
goto exit ;
4409
4420
@@ -4530,7 +4541,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
4530
4541
goto exit ;
4531
4542
} else if (operation == kPublic &&
4532
4543
strncmp (key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0 ) {
4533
- x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4544
+ x509 = PEM_read_bio_X509 (bp, nullptr , NoPasswordCallback , nullptr );
4534
4545
if (x509 == nullptr )
4535
4546
goto exit ;
4536
4547
0 commit comments