-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Exposing KeyObject fields vs. native JWK support #26854
Copy link
Copy link
Closed
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
Metadata
Metadata
Assignees
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Now that node has a decent API to deal with cryptographic keys, users have requested features to access parts of keys, e.g. the modulus of an RSA key or the curve name of an EC key. @sam-github and I came up with the idea to add a
.fieldsproperty toKeyObjectwhich exposes those parts. Other users have encouraged this approach.I am currently working on a PR for that and the basics are working nicely:
One of the reasons users have requested this feature is to be able to implement JWK on top of the native crypto module without having to tap into OpenSSL. However, this would still only make that work in one direction (
KeyObject→ JWK), to create aKeyObjectfrom JWK, a different API would be necessary to construct keys from their fields.Another solution would be to natively support JWK. I am not an expert when it comes to JWK, but it shouldn't be difficult to implement as long as we don't need to include algorithm information in the key as WebCrypto does. This approach would extend
create***KeyandKeyObject.exportwith support for JWK.If JWK support is not the only reason to access parts of the key, it might still make sense to implement
.fieldssince JWK was designed for storing keys, not for interacting with its components. For example,.fieldscould make use of ES BigInts whereas JWK encodes everything as strings.So as I see it, there are four options: Implement both, implement one and not the other, or implement none of it. What do you think?
cc @nodejs/crypto @panva @mscdex