diff options
author | Tobias Nießen <tniessen@tnie.de> | 2020-01-21 16:52:29 +0300 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2020-01-23 17:16:26 +0300 |
commit | ab6ab9c271ac7c77e03c81f21428739ba4e7f2f6 (patch) | |
tree | a218ac49d866dbaeede25a78d1f5cc9149ca319c /src/node_crypto.cc | |
parent | 96058f33a9c72796930a77c97018fda2cbb5ed03 (diff) |
tls: simplify errors using ThrowCryptoError
PR-URL: https://github.com/nodejs/node/pull/31436
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index f03c1e31b99..df823c48c18 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -733,19 +733,14 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) { if (!key) { unsigned long err = ERR_get_error(); // NOLINT(runtime/int) - if (!err) { - return env->ThrowError("PEM_read_bio_PrivateKey"); - } - return ThrowCryptoError(env, err); + return ThrowCryptoError(env, err, "PEM_read_bio_PrivateKey"); } int rv = SSL_CTX_use_PrivateKey(sc->ctx_.get(), key.get()); if (!rv) { unsigned long err = ERR_get_error(); // NOLINT(runtime/int) - if (!err) - return env->ThrowError("SSL_CTX_use_PrivateKey"); - return ThrowCryptoError(env, err); + return ThrowCryptoError(env, err, "SSL_CTX_use_PrivateKey"); } } @@ -971,10 +966,7 @@ void SecureContext::SetCert(const FunctionCallbackInfo<Value>& args) { if (!rv) { unsigned long err = ERR_get_error(); // NOLINT(runtime/int) - if (!err) { - return env->ThrowError("SSL_CTX_use_certificate_chain"); - } - return ThrowCryptoError(env, err); + return ThrowCryptoError(env, err, "SSL_CTX_use_certificate_chain"); } } @@ -1183,11 +1175,7 @@ void SecureContext::SetCipherSuites(const FunctionCallbackInfo<Value>& args) { const node::Utf8Value ciphers(args.GetIsolate(), args[0]); if (!SSL_CTX_set_ciphersuites(sc->ctx_.get(), *ciphers)) { unsigned long err = ERR_get_error(); // NOLINT(runtime/int) - if (!err) { - // This would be an OpenSSL bug if it happened. - return env->ThrowError("Failed to set ciphers"); - } - return ThrowCryptoError(env, err); + return ThrowCryptoError(env, err, "Failed to set ciphers"); } #endif } @@ -1205,10 +1193,6 @@ void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) { const node::Utf8Value ciphers(args.GetIsolate(), args[0]); if (!SSL_CTX_set_cipher_list(sc->ctx_.get(), *ciphers)) { unsigned long err = ERR_get_error(); // NOLINT(runtime/int) - if (!err) { - // This would be an OpenSSL bug if it happened. - return env->ThrowError("Failed to set ciphers"); - } if (strlen(*ciphers) == 0 && ERR_GET_REASON(err) == SSL_R_NO_CIPHER_MATCH) { // TLS1.2 ciphers were deliberately cleared, so don't consider @@ -1217,7 +1201,7 @@ void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) { // that's actually an error. return; } - return ThrowCryptoError(env, err); + return ThrowCryptoError(env, err, "Failed to set ciphers"); } } @@ -3027,9 +3011,7 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) { // Not clear why sometimes we throw error, and sometimes we call // onerror(). Both cause .destroy(), but onerror does a bit more. unsigned long err = ERR_get_error(); // NOLINT(runtime/int) - if (!err) - return env->ThrowError("CertCbDone"); - return ThrowCryptoError(env, err); + return ThrowCryptoError(env, err, "CertCbDone"); } } else { // Failure: incorrect SNI context object |