-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: add keyObject.params for asymmetric keys #30045
Conversation
This API exposes key parameters. 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. Refs: nodejs/webcrypto#16
I'm wondering about why this approach would be preferred over working out
Given that all keys have an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not implemented the publicExponent property yet, mostly because I am not sure whether to use a number or a BigInt.
The precedence here is tlssocket.getPeerCertificate()
which returns it as a hex string.
// TODO(tniessen): This should really be EVP_PKEY_get0_RSA, but OpenSSL does | ||
// not support that for RSA-PSS. | ||
rsa = reinterpret_cast<RSA*>(EVP_PKEY_get0(pkey)); | ||
SetParam(env(), params, "modulusLength", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: add the string to PER_ISOLATE_STRING_PROPERTIES
in env.h. Ditto the other strings.
I think it is possible to see
|
Fair enough, i can see how this method can be labeled as "log safe" / not containing private information.
Other than the philosophical discussion about types and property names - what's the difficult part and how could i help to move it forward? PEM, DER and JWK are all treated as first-class under webcrypto's |
|
||
class AsymmetricKeyObject extends KeyObject { | ||
get asymmetricKeyType() { | ||
return this[kAsymmetricKeyType] || | ||
(this[kAsymmetricKeyType] = this[kHandle].getAsymmetricKeyType()); | ||
} | ||
|
||
get params() { | ||
return this[kParams] || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, but could you rewrite this as:
if (this[kParams] === undefined)
this[kParams] = this[kHandle].getAsymmetricParams();
return this[kParams];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to suggest something similar at first but it's locally consistent, get asymmetricKeyType()
uses the same style.
@tniessen is there still something to do here, since this already got two LGs? |
Yes, I still need to implement some properties. I am working on a different PR to fix a few crypto issues and need to make sure these two are compatible. Sorry about the delay. |
I have a potential use case for exposing
Currently I think my best option is to export the keys and parse the DER/PEM, which is a bit of a headache. |
8ae28ff
to
2935f72
Compare
@tniessen is it possible to pick this up? Especially getting the |
@panva In theory, sure, I just don't know if this makes a whole lot of sense now that WebCrypto is in core. What do you think? |
I think @jasnell will concur, that WebCrypto API is not meant as a replacement for the much more flexible and performant WebCrypto API helps in writing isomorphic modules for different runtimes but it comes at a huge performance cost and inflexibility especially because of its I'm not sure how likely WebCrypto API is to be backported to lts/12 and lts/14 but I would still choose to use |
I 100% agree. The WebCrypto API is not meant to replace the existing crypto system. |
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 nodejs#30045
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 nodejs#30045
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 PR-URL: #36188 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
This API exposes key parameters. 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.
I have not implemented the
publicExponent
property yet, mostly because I am not sure whether to use anumber
or aBigInt
. In practice, most (all?) public exponents will fit into 32 bits and thus easily intoNumber.MAX_SAFE_INTEGER
, andgenerateKeyPair
currently only accepts safe integers, too. However, in theory, public exponents can be almost arbitrarily long, even though it can introduce efficiency and security concerns. I would like to hear opinions from @nodejs/crypto (or others).Refs: nodejs/webcrypto#16
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes