Skip to content

Conversation

panva
Copy link
Member

@panva panva commented Mar 2, 2025

Implementation of SubtleCrypto.supports.

While today we support all the methods and algorithms of Web Cryptography, this method will become really useful for interop when modern webcrypto algorithms start popping up

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.

@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 3 times, most recently from 81f92eb to ddc4c47 Compare March 8, 2025 09:09
@panva panva added the webcrypto label Mar 8, 2025
@panva panva force-pushed the experimental-subtle-crypto-supports branch 8 times, most recently from f746637 to ce9da32 Compare March 8, 2025 18:35
@panva panva force-pushed the experimental-subtle-crypto-supports branch from ce9da32 to f74d019 Compare March 16, 2025 20:05
@panva panva force-pushed the experimental-subtle-crypto-supports branch 2 times, most recently from 3ab9692 to b2b84c1 Compare May 27, 2025 12:17
@panva panva force-pushed the experimental-subtle-crypto-supports branch 2 times, most recently from a8db595 to cefc73c Compare July 15, 2025 15:17
@panva panva force-pushed the experimental-subtle-crypto-supports branch from cefc73c to 1828437 Compare July 30, 2025 14:02
@panva panva added commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. semver-minor PRs that contain new features and should be released in the next minor version. labels Jul 30, 2025
@panva panva force-pushed the experimental-subtle-crypto-supports branch 2 times, most recently from 9ce00de to efe1d34 Compare July 30, 2025 14:25
@panva panva force-pushed the experimental-subtle-crypto-supports branch 2 times, most recently from 139d485 to c5e41fc Compare July 30, 2025 19:54
@panva panva removed the commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. label Jul 30, 2025
@panva panva closed this Aug 2, 2025
@panva panva deleted the experimental-subtle-crypto-supports branch August 2, 2025 15:55
> Stability: 1.0 - Early development. SubleCrypto.supports is an experimental
> implementation based on [Modern Algorithms in the Web Cryptography API][]

This example derives a key from a password using Argon2, if available,
Copy link
Member

@jasnell jasnell Aug 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more introductory text here at the start would be good, otherwise at first glance someone might thing this section is only about Argon2. Something like, The `SubtleCrypto.supports(...)` API provides a way of detecting if a particular algorithm or set of options are supported.

@@ -923,7 +924,153 @@ class SubtleCrypto {
constructor() {
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

static supports(operation, algorithm, lengthOrAdditionalAlgorithm = null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here that explains the heuristics or points to the spec would be good as a reminder that this is implementing to a spec.

@panva
Copy link
Member Author

panva commented Aug 2, 2025

Thank you @jasnell, i'll incorporate these comments in a bigger PR for WebCrypto modern algos once https://redirect.github.com/nodejs/node/pull/59259 and https://redirect.github.com/nodejs/node/pull/59284 land

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. semver-minor PRs that contain new features and should be released in the next minor version. webcrypto
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants