Skip to content

Commit 388da8e

Browse files
tniessenguangwong
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: nodejs/node#44307 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8d9bbe4 commit 388da8e

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
@@ -1549,7 +1549,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
15491549
}, common.mustNotCall()), {
15501550
name: 'TypeError',
15511551
code: 'ERR_CRYPTO_INVALID_DIGEST',
1552-
message: 'md specifies an invalid digest'
1552+
message: 'Invalid digest: sha2'
15531553
});
15541554

15551555
assert.throws(() => generateKeyPair('rsa-pss', {
@@ -1558,7 +1558,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
15581558
}, common.mustNotCall()), {
15591559
name: 'TypeError',
15601560
code: 'ERR_CRYPTO_INVALID_DIGEST',
1561-
message: 'mgf1_md specifies an invalid digest'
1561+
message: 'Invalid MGF1 digest: sha2'
15621562
});
15631563
}
15641564

0 commit comments

Comments
 (0)