mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
crypto: fix regression in RSA-PSS keygen
Fixes: https://github.com/nodejs/node/issues/39936 Refs: https://github.com/nodejs/node/pull/35093 PR-URL: https://github.com/nodejs/node/pull/39937 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
fc01dd916e
commit
585199497f
2 files changed
+26
-2
No files matched your search
@@ -25,10 +25,11 @@ struct RsaKeyPairParams final : public MemoryRetainer {
|
||||
unsigned int modulus_bits;
|
||||
unsigned int exponent;
|
||||
|
||||
// The following used for RSA-PSS
|
||||
// The following options are used for RSA-PSS. If any of them are set, a
|
||||
// RSASSA-PSS-params sequence will be added to the key.
|
||||
const EVP_MD* md = nullptr;
|
||||
const EVP_MD* mgf1_md = nullptr;
|
||||
int saltlen = 0;
|
||||
int saltlen = -1;
|
||||
|
||||
SET_NO_MEMORY_INFO()
|
||||
SET_MEMORY_INFO_NAME(RsaKeyPairParams)
|
||||
|
||||
@@ -346,6 +346,29 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
// 'rsa-pss' should not add a RSASSA-PSS-params sequence by default.
|
||||
// Regression test for: https://github.com/nodejs/node/issues/39936
|
||||
|
||||
generateKeyPair('rsa-pss', {
|
||||
modulusLength: 512
|
||||
}, common.mustSucceed((publicKey, privateKey) => {
|
||||
const expectedKeyDetails = {
|
||||
modulusLength: 512,
|
||||
publicExponent: 65537n
|
||||
};
|
||||
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
|
||||
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
|
||||
|
||||
// To allow backporting the fix to versions that do not support
|
||||
// asymmetricKeyDetails for RSA-PSS params, also verify that the exported
|
||||
// AlgorithmIdentifier member of the SubjectPublicKeyInfo has the expected
|
||||
// length of 11 bytes (as opposed to > 11 bytes if node added params).
|
||||
const spki = publicKey.export({ format: 'der', type: 'spki' });
|
||||
assert.strictEqual(spki[3], 11, spki.toString('hex'));
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const privateKeyEncoding = {
|
||||
type: 'pkcs8',
|
||||
|
||||
Reference in new issue
Block a user