From 566d80f622359b3a33e4ba2359753cb7f52c10ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 22 Aug 2022 17:18:30 +0200 Subject: [PATCH] crypto: improve RSA-PSS digest error messages md and mgf1_md are internal variable names and should not appear in JS error messages. Also include the invalid digest name in the error message. PR-URL: https://github.com/nodejs/node/pull/44307 Reviewed-By: Filip Skokan Reviewed-By: Richard Lau Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Luigi Pinca --- src/crypto/crypto_rsa.cc | 6 +++--- test/parallel/test-crypto-keygen.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index bd732a70a8ffe6..97007527efd564 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -153,7 +153,7 @@ Maybe RsaKeyGenTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[*offset]); params->params.md = EVP_get_digestbyname(*digest); if (params->params.md == nullptr) { - THROW_ERR_CRYPTO_INVALID_DIGEST(env, "md specifies an invalid digest"); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest); return Nothing(); } } @@ -163,8 +163,8 @@ Maybe RsaKeyGenTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[*offset + 1]); params->params.mgf1_md = EVP_get_digestbyname(*digest); if (params->params.mgf1_md == nullptr) { - THROW_ERR_CRYPTO_INVALID_DIGEST(env, - "mgf1_md specifies an invalid digest"); + THROW_ERR_CRYPTO_INVALID_DIGEST( + env, "Invalid MGF1 digest: %s", *digest); return Nothing(); } } diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index b9274b2b22e6a0..235bc583b969f2 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -1549,7 +1549,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); }, common.mustNotCall()), { name: 'TypeError', code: 'ERR_CRYPTO_INVALID_DIGEST', - message: 'md specifies an invalid digest' + message: 'Invalid digest: sha2' }); assert.throws(() => generateKeyPair('rsa-pss', { @@ -1558,7 +1558,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); }, common.mustNotCall()), { name: 'TypeError', code: 'ERR_CRYPTO_INVALID_DIGEST', - message: 'mgf1_md specifies an invalid digest' + message: 'Invalid MGF1 digest: sha2' }); }