From 98d2e5696a6b4ecaa64adeb94b69fab42e664dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 23 Aug 2021 12:34:30 +0000 Subject: [PATCH 1/4] crypto: add RSA-PSS params to asymmetricKeyDetails Fixes: https://github.com/nodejs/node/issues/39837 Refs: https://github.com/openssl/openssl/pull/10568 --- doc/api/crypto.md | 9 +- src/crypto/crypto_rsa.cc | 82 ++++++++++++++++++- src/env.h | 3 + test/fixtures/keys/Makefile | 8 ++ .../rsa_pss_private_2048_sha1_sha1_20.pem | 28 +++++++ .../keys/rsa_pss_public_2048_sha1_sha1_20.pem | 9 ++ test/parallel/test-crypto-key-objects.js | 52 ++++++++++++ test/parallel/test-crypto-keygen.js | 10 ++- 8 files changed, 193 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/keys/rsa_pss_private_2048_sha1_sha1_20.pem create mode 100644 test/fixtures/keys/rsa_pss_public_2048_sha1_sha1_20.pem diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 73f5ecd9506aa7..df424b8abf9126 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1913,6 +1913,9 @@ added: v15.7.0 * {Object} * `modulusLength`: {number} Key size in bits (RSA, DSA). * `publicExponent`: {bigint} Public exponent (RSA). + * `hashAlgorithm`: {string} Name of the message digest (RSA-PSS). + * `mgf1Hash`: {string} Name of the message digest used by MGF1 (RSA-PSS). + * `saltLength`: {number} Salt length in bytes (RSA-PSS). * `divisorLength`: {number} Size of `q` in bits (DSA). * `namedCurve`: {string} Name of the curve (EC). @@ -1921,8 +1924,10 @@ this object contains information about the key. None of the information obtained through this property can be used to uniquely identify a key or to compromise the security of the key. -RSA-PSS parameters, DH, or any future key type details might be exposed via this -API using additional attributes. +For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence, +the `hashAlgorithm`, `mgf1Hash`, and `saltLength` properties will be set. + +Other key details might be exposed via this API using additional attributes. ### `keyObject.asymmetricKeyType` * {Object} - * `modulusLength`: {number} Key size in bits (RSA, DSA). - * `publicExponent`: {bigint} Public exponent (RSA). + * `modulusLength`: {number} Key size in bits (RSA, RSA-PSS, DSA). + * `publicExponent`: {bigint} Public exponent (RSA, RSA-PSS). * `hashAlgorithm`: {string} Name of the message digest (RSA-PSS). - * `mgf1Hash`: {string} Name of the message digest used by MGF1 (RSA-PSS). - * `saltLength`: {number} Salt length in bytes (RSA-PSS). + * `mgf1HashAlgorithm`: {string} Name of the message digest used by + MGF1 (RSA-PSS). + * `saltLength`: {number} Minimal salt length in bytes (RSA-PSS). * `divisorLength`: {number} Size of `q` in bits (DSA). * `namedCurve`: {string} Name of the curve (EC). @@ -1925,7 +1931,8 @@ through this property can be used to uniquely identify a key or to compromise the security of the key. For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence, -the `hashAlgorithm`, `mgf1Hash`, and `saltLength` properties will be set. +the `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` properties will be +set. Other key details might be exposed via this API using additional attributes. diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index 803e068cc77f7b..1bbf9a1753e4e2 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -599,7 +599,7 @@ Maybe GetRsaKeyDetail( if (target ->Set( env->context(), - env->mgf1_hash_string(), + env->mgf1_hash_algorithm_string(), OneByteString(env->isolate(), OBJ_nid2ln(mgf1_hash_nid))) .IsNothing()) { return Nothing(); diff --git a/src/env.h b/src/env.h index 7c108f74fb994e..4fd5be8e15029b 100644 --- a/src/env.h +++ b/src/env.h @@ -317,7 +317,7 @@ constexpr size_t kFsStatsBufferLength = V(message_port_string, "messagePort") \ V(message_string, "message") \ V(messageerror_string, "messageerror") \ - V(mgf1_hash_string, "mgf1Hash") \ + V(mgf1_hash_algorithm_string, "mgf1HashAlgorithm") \ V(minttl_string, "minttl") \ V(module_string, "module") \ V(modulus_string, "modulus") \ diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index 427f87c0bcd27b..c2c47a9ce72f12 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -652,7 +652,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', modulusLength: 2048, publicExponent: 65537n, hashAlgorithm: 'sha1', - mgf1Hash: 'sha1', + mgf1HashAlgorithm: 'sha1', saltLength: 20 }; @@ -727,7 +727,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', modulusLength: 2048, publicExponent: 65537n, hashAlgorithm: 'sha512', - mgf1Hash: 'sha256', + mgf1HashAlgorithm: 'sha256', saltLength: 20 }; From 55eb06b0458fd9882d8cc86e825ba169c671abae Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 29 Aug 2021 10:21:26 +0200 Subject: [PATCH 3/4] fixup! crypto: add RSA-PSS params to asymmetricKeyDetails --- test/parallel/test-crypto-keygen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index f96fdb5f000c5a..3392284f8d1963 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -311,7 +311,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); modulusLength: 512, publicExponent: 65537n, hashAlgorithm: 'sha256', - mgf1Hash: 'sha256', + mgf1HashAlgorithm: 'sha256', saltLength: 16 }); @@ -321,7 +321,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); modulusLength: 512, publicExponent: 65537n, hashAlgorithm: 'sha256', - mgf1Hash: 'sha256', + mgf1HashAlgorithm: 'sha256', saltLength: 16 }); From 63bd37abc4cb164a4b53c72af43601090e18c930 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 29 Aug 2021 16:21:52 +0200 Subject: [PATCH 4/4] fixup! crypto: add RSA-PSS params to asymmetricKeyDetails --- doc/api/crypto.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 001d550a24951b..b54ad3019cd17b 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1916,8 +1916,8 @@ changes: --> * {Object} - * `modulusLength`: {number} Key size in bits (RSA, RSA-PSS, DSA). - * `publicExponent`: {bigint} Public exponent (RSA, RSA-PSS). + * `modulusLength`: {number} Key size in bits (RSA, DSA). + * `publicExponent`: {bigint} Public exponent (RSA). * `hashAlgorithm`: {string} Name of the message digest (RSA-PSS). * `mgf1HashAlgorithm`: {string} Name of the message digest used by MGF1 (RSA-PSS).