From 2efd015efb24d581e3c93d245f1194c8fc6302cb Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Fri, 20 Nov 2020 12:59:13 +0100 Subject: [PATCH 1/4] crypto: add keyObject.asymmetricKeyDetails for asymmetric keys This API exposes key details. It is conceptually different from the previously discussed keyObject.fields property since it does not give access to information that could compromise the security of the key, and the obtained information cannot be used to uniquely identify a key. The intended purpose is to determine "security properties" of keys, e.g. to generate a new key pair with the same parameters, or to decide whether a key is secure enough. closes #30045 --- doc/api/crypto.md | 21 +++++++++ lib/internal/crypto/keys.js | 23 ++++++++++ src/crypto/crypto_keys.cc | 3 +- test/parallel/test-crypto-key-objects.js | 1 + test/parallel/test-crypto-keygen.js | 56 ++++++++++++++++++++++-- 5 files changed, 98 insertions(+), 6 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index b7977120fa4924..0789e2ca483076 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1284,6 +1284,27 @@ passing keys as strings or `Buffer`s due to improved security features. The receiver obtains a cloned `KeyObject`, and the `KeyObject` does not need to be listed in the `transferList` argument. +### `keyObject.asymmetricKeyDetails` + + +* {Object} + +This property exists only on asymmetric keys. Depending on the type of the key, +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. + +For `'rsa'` and `'rsa-pss'` keys, this object has the properties `modulusLength` +and `publicExponent`. + +For `'dsa'` keys, this object has the properties `modulusLength` and +`divisorLength`. + +For `'ec'` keys with a known curve, this object has the string property +`namedCurve`. + ### `keyObject.asymmetricKeyType` * {Object} + * `modulusLength`: {number} Key size in bits (RSA, DSA). + * `publicExponent`: {number} Public exponent (RSA). + * `divisorLength`: {number} Size of `q` in bits (DSA). + * `namedCurve`: {string} Name of the curve (EC). This property exists only on asymmetric keys. Depending on the type of the key, 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. -For `'rsa'` and `'rsa-pss'` keys, this object has the properties `modulusLength` -and `publicExponent`. - -For `'dsa'` keys, this object has the properties `modulusLength` and -`divisorLength`. - -For `'ec'` keys with a known curve, this object has the string property -`namedCurve`. - ### `keyObject.asymmetricKeyType`