@@ -204,8 +204,6 @@ static void crypto_lock_cb(int mode, int n, const char* file, int line) {
204
204
}
205
205
206
206
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
207
static int PasswordCallback (char *buf, int size, int rwflag, void *u) {
210
208
if (u) {
211
209
size_t buflen = static_cast <size_t >(size);
@@ -219,6 +217,16 @@ static int PasswordCallback(char *buf, int size, int rwflag, void *u) {
219
217
}
220
218
221
219
220
+ // This callback is used to avoid the default passphrase callback in OpenSSL
221
+ // which will typically prompt for the passphrase. The prompting is designed
222
+ // for the OpenSSL CLI, but works poorly for Node.js because it involves
223
+ // synchronous interaction with the controlling terminal, something we never
224
+ // want, and use this function to avoid it.
225
+ static int NoPasswordCallback (char *buf, int size, int rwflag, void *u) {
226
+ return 0 ;
227
+ }
228
+
229
+
222
230
void ThrowCryptoError (Environment* env,
223
231
unsigned long err, // NOLINT(runtime/int)
224
232
const char * default_message = nullptr ) {
@@ -588,7 +596,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
588
596
// that we are interested in
589
597
ERR_clear_error ();
590
598
591
- x = PEM_read_bio_X509_AUX (in, nullptr , PasswordCallback , nullptr );
599
+ x = PEM_read_bio_X509_AUX (in, nullptr , NoPasswordCallback , nullptr );
592
600
593
601
if (x == nullptr ) {
594
602
SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB);
@@ -606,7 +614,10 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
606
614
goto done;
607
615
}
608
616
609
- while ((extra = PEM_read_bio_X509 (in, nullptr , PasswordCallback, nullptr ))) {
617
+ while ((extra = PEM_read_bio_X509 (in,
618
+ nullptr ,
619
+ NoPasswordCallback,
620
+ nullptr ))) {
610
621
if (sk_X509_push (extra_certs, extra))
611
622
continue ;
612
623
@@ -702,7 +713,7 @@ static X509_STORE* NewRootCertStore() {
702
713
if (root_certs_vector.empty ()) {
703
714
for (size_t i = 0 ; i < arraysize (root_certs); i++) {
704
715
BIO* bp = NodeBIO::NewFixed (root_certs[i], strlen (root_certs[i]));
705
- X509 *x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
716
+ X509 *x509 = PEM_read_bio_X509 (bp, nullptr , NoPasswordCallback , nullptr );
706
717
BIO_free (bp);
707
718
708
719
// Parse errors from the built-in roots are fatal.
@@ -745,7 +756,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
745
756
746
757
X509_STORE* cert_store = SSL_CTX_get_cert_store (sc->ctx_ );
747
758
while (X509* x509 =
748
- PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
759
+ PEM_read_bio_X509 (bio, nullptr , NoPasswordCallback , nullptr )) {
749
760
if (cert_store == root_cert_store) {
750
761
cert_store = NewRootCertStore ();
751
762
SSL_CTX_set_cert_store (sc->ctx_ , cert_store);
@@ -777,7 +788,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
777
788
return ;
778
789
779
790
X509_CRL* crl =
780
- PEM_read_bio_X509_CRL (bio, nullptr , PasswordCallback , nullptr );
791
+ PEM_read_bio_X509_CRL (bio, nullptr , NoPasswordCallback , nullptr );
781
792
782
793
if (crl == nullptr ) {
783
794
BIO_free_all (bio);
@@ -816,7 +827,7 @@ static unsigned long AddCertsFromFile( // NOLINT(runtime/int)
816
827
}
817
828
818
829
while (X509* x509 =
819
- PEM_read_bio_X509 (bio, nullptr , PasswordCallback , nullptr )) {
830
+ PEM_read_bio_X509 (bio, nullptr , NoPasswordCallback , nullptr )) {
820
831
X509_STORE_add_cert (store, x509);
821
832
X509_free (x509);
822
833
}
@@ -4295,7 +4306,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4295
4306
// Split this out into a separate function once we have more than one
4296
4307
// consumer of public keys.
4297
4308
if (strncmp (key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0 ) {
4298
- pkey = PEM_read_bio_PUBKEY (bp, nullptr , PasswordCallback , nullptr );
4309
+ pkey = PEM_read_bio_PUBKEY (bp, nullptr , NoPasswordCallback , nullptr );
4299
4310
if (pkey == nullptr )
4300
4311
goto exit ;
4301
4312
} else if (strncmp (key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0 ) {
@@ -4311,7 +4322,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
4311
4322
goto exit ;
4312
4323
} else {
4313
4324
// X.509 fallback
4314
- x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4325
+ x509 = PEM_read_bio_X509 (bp, nullptr , NoPasswordCallback , nullptr );
4315
4326
if (x509 == nullptr )
4316
4327
goto exit ;
4317
4328
@@ -4429,7 +4440,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
4429
4440
goto exit ;
4430
4441
} else if (operation == kPublic &&
4431
4442
strncmp (key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0 ) {
4432
- x509 = PEM_read_bio_X509 (bp, nullptr , PasswordCallback , nullptr );
4443
+ x509 = PEM_read_bio_X509 (bp, nullptr , NoPasswordCallback , nullptr );
4433
4444
if (x509 == nullptr )
4434
4445
goto exit ;
4435
4446
0 commit comments