From 63206e9e552bdb89cecd0758aa75fa2b6f6997ee Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Wed, 7 Sep 2022 09:47:39 -0400 Subject: [PATCH] crypto: don't claim errors come from within OpenSSL Prior to OpenSSL 3.0, OpenSSL's error system maintained numeric function codes for what function the error came from, which caused a number of problems. OpenSSL 3.0 has dropped these (the function code parameter is ignored). But even in OpenSSL 1.1.1, specifying them in Node doesn't make sense. The errors don't come from the functions Node is claiming they do. --- src/crypto/crypto_dh.cc | 15 +++++---------- src/crypto/crypto_hash.cc | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc index dd69323b80076d..2ab11a57947f94 100644 --- a/src/crypto/crypto_dh.cc +++ b/src/crypto/crypto_dh.cc @@ -154,13 +154,11 @@ bool DiffieHellman::Init(BignumPointer&& bn_p, int g) { bool DiffieHellman::Init(const char* p, int p_len, int g) { dh_.reset(DH_new()); if (p_len <= 0) { - ERR_put_error(ERR_LIB_BN, BN_F_BN_GENERATE_PRIME_EX, - BN_R_BITS_TOO_SMALL, __FILE__, __LINE__); + ERR_put_error(ERR_LIB_BN, 0, BN_R_BITS_TOO_SMALL, __FILE__, __LINE__); return false; } if (g <= 1) { - ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, - DH_R_BAD_GENERATOR, __FILE__, __LINE__); + ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); return false; } BIGNUM* bn_p = @@ -178,21 +176,18 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) { bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) { dh_.reset(DH_new()); if (p_len <= 0) { - ERR_put_error(ERR_LIB_BN, BN_F_BN_GENERATE_PRIME_EX, - BN_R_BITS_TOO_SMALL, __FILE__, __LINE__); + ERR_put_error(ERR_LIB_BN, 0, BN_R_BITS_TOO_SMALL, __FILE__, __LINE__); return false; } if (g_len <= 0) { - ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, - DH_R_BAD_GENERATOR, __FILE__, __LINE__); + ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); return false; } BIGNUM* bn_g = BN_bin2bn(reinterpret_cast(g), g_len, nullptr); if (BN_is_zero(bn_g) || BN_is_one(bn_g)) { BN_free(bn_g); - ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, - DH_R_BAD_GENERATOR, __FILE__, __LINE__); + ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); return false; } BIGNUM* bn_p = diff --git a/src/crypto/crypto_hash.cc b/src/crypto/crypto_hash.cc index 200603a85ef33e..f46dd58c07459c 100644 --- a/src/crypto/crypto_hash.cc +++ b/src/crypto/crypto_hash.cc @@ -124,7 +124,7 @@ bool Hash::HashInit(const EVP_MD* md, Maybe xof_md_len) { // This is a little hack to cause createHash to fail when an incorrect // hashSize option was passed for a non-XOF hash function. if ((EVP_MD_flags(md) & EVP_MD_FLAG_XOF) == 0) { - EVPerr(EVP_F_EVP_DIGESTFINALXOF, EVP_R_NOT_XOF_OR_INVALID_LENGTH); + EVPerr(0, EVP_R_NOT_XOF_OR_INVALID_LENGTH); return false; } md_len_ = xof_md_len.FromJust();