Skip to content
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 SubtleCrypto.supports feature detection in Web Crypto API #57270

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

panva
Copy link
Member

@panva panva commented Mar 2, 2025

Early draft implementation of SubtleCrypto.supports.

While today we support all the methods and algorithms, this method will become really useful for interop when modern webcrypto algorithms are going to start popping up that will depend on new OpenSSL versions, such as ML-DSA that may not be immediately available in distributions with linked OpenSSL.

cc @twiss

This will remain a draft PR until this work is accepted by WICG as a proposal for the addition of its content to the Web Cryptography API.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Mar 2, 2025
@panva panva changed the title crypto: add SubleCrypto.supports feature detection in Web Crypto API crypto: add SubtleCrypto.supports feature detection in Web Crypto API Mar 2, 2025
@panva panva force-pushed the experimental-subtle-crypto-supports branch from cb66676 to b639d6e Compare March 2, 2025 12:08
@panva
Copy link
Member Author

panva commented Mar 2, 2025

#57273 will allow the implementation to share validation code with the actual algorithm operations.

@panva panva force-pushed the experimental-subtle-crypto-supports branch 4 times, most recently from 9b2493a to b46d505 Compare March 4, 2025 21:18
@jasnell
Copy link
Member

jasnell commented Mar 4, 2025

If I am understanding the implementation here correctly, "supports" is based largely on JS-level validation of the input arguments. It would be possible, however, for Node.js to be compiled against a different version of Openssl that does not actually have support for an algorithm that the JS side claims to support, correct? For instance, Ed448 is not supported by Node.js builds using BoringSSL but, unless I'm misunderstanding the implementation here, this might still claim that Ed448 is supported on such builds? Is that accurate or did I miss something?

Btw, very happy to see this!

@panva panva force-pushed the experimental-subtle-crypto-supports branch from b46d505 to 9416371 Compare March 4, 2025 21:28
@panva
Copy link
Member Author

panva commented Mar 4, 2025

@jasnell I did think of this. With everything being tied into the "normalize algorithm" routine, all it would take to make the algorithms conditional based on the underlying crypto lib support (both execution as well as their status in the supports API) is doing something similar to what we do for adding experimental algorithms here

Therefore if we get the signal from internalBinding('crypto') that something isn't supported, we can make supports as well as the actual SubtleCrypto methods fail/false in JS before it gets to C++

@panva panva force-pushed the experimental-subtle-crypto-supports branch from 0fec168 to 81f92eb Compare March 6, 2025 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants