Skip to content

Commit 28781a1

Browse files
tniessenRafaelGSS
authored andcommitted
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: #44307 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6857ee8 commit 28781a1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/crypto/crypto_rsa.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Maybe<bool> RsaKeyGenTraits::AdditionalConfig(
153153
Utf8Value digest(env->isolate(), args[*offset]);
154154
params->params.md = EVP_get_digestbyname(*digest);
155155
if (params->params.md == nullptr) {
156-
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "md specifies an invalid digest");
156+
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest);
157157
return Nothing<bool>();
158158
}
159159
}
@@ -163,8 +163,8 @@ Maybe<bool> RsaKeyGenTraits::AdditionalConfig(
163163
Utf8Value digest(env->isolate(), args[*offset + 1]);
164164
params->params.mgf1_md = EVP_get_digestbyname(*digest);
165165
if (params->params.mgf1_md == nullptr) {
166-
THROW_ERR_CRYPTO_INVALID_DIGEST(env,
167-
"mgf1_md specifies an invalid digest");
166+
THROW_ERR_CRYPTO_INVALID_DIGEST(
167+
env, "Invalid MGF1 digest: %s", *digest);
168168
return Nothing<bool>();
169169
}
170170
}

test/parallel/test-crypto-keygen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
16611661
}, common.mustNotCall()), {
16621662
name: 'TypeError',
16631663
code: 'ERR_CRYPTO_INVALID_DIGEST',
1664-
message: 'md specifies an invalid digest'
1664+
message: 'Invalid digest: sha2'
16651665
});
16661666

16671667
assert.throws(() => generateKeyPair('rsa-pss', {
@@ -1670,7 +1670,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
16701670
}, common.mustNotCall()), {
16711671
name: 'TypeError',
16721672
code: 'ERR_CRYPTO_INVALID_DIGEST',
1673-
message: 'mgf1_md specifies an invalid digest'
1673+
message: 'Invalid MGF1 digest: sha2'
16741674
});
16751675
}
16761676

0 commit comments

Comments
 (0)