src: turn SSL_CTX_new CHECK/segfault into JS exception

These operations do not usually fail, but can do so when OpenSSL
is not configured properly (I ran into this while dynamically linking
against OpenSSL with FIPS). JS exceptions are way more useful
than CHECK failures or plain segfaults.

PR-URL: https://github.com/nodejs/node/pull/42799
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen authored and Michaël Zasso committed 2022-07-11 17:13:08 +02:00
1 parent b69396a41a
commit 7778ebecaa
2 files changed
+9 -2

No files matched your search

+6 -2
View File
@@ -198,10 +198,14 @@ void CipherBase::GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
SSLCtxPointer ctx(SSL_CTX_new(TLS_method()));
CHECK(ctx);
if (!ctx) {
return ThrowCryptoError(env, ERR_get_error(), "SSL_CTX_new");
}
SSLPointer ssl(SSL_new(ctx.get()));
CHECK(ssl);
if (!ssl) {
return ThrowCryptoError(env, ERR_get_error(), "SSL_new");
}
STACK_OF(SSL_CIPHER)* ciphers = SSL_get_ciphers(ssl.get());
+3
View File
@@ -508,6 +508,9 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
}
sc->ctx_.reset(SSL_CTX_new(method));
if (!sc->ctx_) {
return ThrowCryptoError(env, ERR_get_error(), "SSL_CTX_new");
}
SSL_CTX_set_app_data(sc->ctx_.get(), sc);
// Disable SSLv2 in the case when method == TLS_method() and the