-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
crypto: improve accuracy of SubtleCrypto.supports #63104
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
Open
panva
wants to merge
4
commits into
nodejs:main
Choose a base branch
from
panva:subtle-supports-derive-bits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5710d4e
crypto: improve accuracy of SubtleCrypto.supports
panva cc76732
fixup! crypto: improve accuracy of SubtleCrypto.supports
panva 892a5df
fixup! crypto: improve accuracy of SubtleCrypto.supports
panva f1cbedb
fixup! crypto: improve accuracy of SubtleCrypto.supports
panva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
test/fixtures/wpt/WebCryptoAPI/supports-modern.tentative.https.any.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // META: title=WebCrypto API: supports method tests for algorithms in https://wicg.github.io/webcrypto-modern-algos/ | ||
| // META: script=util/helpers.js | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const modernAlgorithms = { | ||
| // Asymmetric algorithms | ||
| 'ML-DSA-44': { | ||
| operations: ['generateKey', 'importKey', 'sign', 'verify'], | ||
| }, | ||
| 'ML-DSA-65': { | ||
| operations: ['generateKey', 'importKey', 'sign', 'verify'], | ||
| }, | ||
| 'ML-DSA-87': { | ||
| operations: ['generateKey', 'importKey', 'sign', 'verify'], | ||
| }, | ||
| 'ML-KEM-512': { | ||
| operations: [ | ||
| 'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits', | ||
| 'decapsulateKey', 'decapsulateBits' | ||
| ], | ||
| }, | ||
| 'ML-KEM-768': { | ||
| operations: [ | ||
| 'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits', | ||
| 'decapsulateKey', 'decapsulateBits' | ||
| ], | ||
| }, | ||
| 'ML-KEM-1024': { | ||
| operations: [ | ||
| 'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits', | ||
| 'decapsulateKey', 'decapsulateBits' | ||
| ], | ||
| }, | ||
|
|
||
| // Symmetric algorithms | ||
| 'ChaCha20-Poly1305': { | ||
| operations: ['generateKey', 'importKey', 'encrypt', 'decrypt'], | ||
| encryptParams: {name: 'ChaCha20-Poly1305', iv: new Uint8Array(12)}, | ||
| }, | ||
|
|
||
| }; | ||
|
|
||
| const operations = [ | ||
| 'generateKey', | ||
| 'importKey', | ||
| 'sign', | ||
| 'verify', | ||
| 'encrypt', | ||
| 'decrypt', | ||
| 'deriveBits', | ||
| 'digest', | ||
| 'encapsulateKey', | ||
| 'encapsulateBits', | ||
| 'decapsulateKey', | ||
| 'decapsulateBits', | ||
| ]; | ||
|
|
||
| // Test that supports method exists and is a static method | ||
| test(() => { | ||
| assert_true( | ||
| typeof SubtleCrypto.supports === 'function', | ||
| 'SubtleCrypto.supports should be a function'); | ||
| }, 'SubtleCrypto.supports method exists'); | ||
|
|
||
|
|
||
| // Test standard WebCrypto algorithms for requested operations | ||
| for (const [algorithmName, algorithmInfo] of Object.entries(modernAlgorithms)) { | ||
| for (const operation of operations) { | ||
| promise_test(async (t) => { | ||
| const isSupported = algorithmInfo.operations.includes(operation); | ||
|
|
||
| // Use appropriate algorithm parameters for each operation | ||
| let algorithm; | ||
| let lengthOrAdditionalAlgorithm; | ||
| switch (operation) { | ||
| case 'generateKey': | ||
| algorithm = algorithmInfo.keyGenParams || algorithmName; | ||
| break; | ||
| case 'importKey': | ||
| algorithm = algorithmInfo.importParams || algorithmName; | ||
| break; | ||
| case 'sign': | ||
| case 'verify': | ||
| algorithm = algorithmInfo.signParams || algorithmName; | ||
| break; | ||
| case 'encrypt': | ||
| case 'decrypt': | ||
| algorithm = algorithmInfo.encryptParams || algorithmName; | ||
| break; | ||
| case 'deriveBits': | ||
| algorithm = algorithmInfo.deriveBitsParams || algorithmName; | ||
| if (algorithm?.public instanceof Promise) { | ||
| algorithm.public = (await algorithm.public).publicKey; | ||
| } | ||
| if (algorithmName === 'PBKDF2' || algorithmName === 'HKDF') { | ||
| lengthOrAdditionalAlgorithm = 256; | ||
| } | ||
| break; | ||
| case 'digest': | ||
| algorithm = algorithmName; | ||
| break; | ||
| case 'encapsulateKey': | ||
| case 'encapsulateBits': | ||
| case 'decapsulateKey': | ||
| case 'decapsulateBits': | ||
| algorithm = algorithmName; | ||
| if (operation === 'encapsulateKey' || operation === 'decapsulateKey') { | ||
| lengthOrAdditionalAlgorithm = { name: 'AES-GCM', length: 256 }; | ||
| } | ||
| break; | ||
| default: | ||
| algorithm = algorithmName; | ||
| } | ||
|
|
||
| const result = SubtleCrypto.supports(operation, algorithm, lengthOrAdditionalAlgorithm); | ||
|
|
||
| if (isSupported) { | ||
| assert_true(result, `${algorithmName} should support ${operation}`); | ||
| } else { | ||
| assert_false( | ||
| result, `${algorithmName} should not support ${operation}`); | ||
| } | ||
| }, `supports(${operation}, ${algorithmName})`); | ||
| } | ||
| } | ||
|
|
||
| // Test some algorithm objects with valid parameters | ||
| test(() => { | ||
| assert_true( | ||
| SubtleCrypto.supports('encrypt', { | ||
| name: 'ChaCha20-Poly1305', | ||
| iv: new Uint8Array(12), | ||
| tagLength: 128, | ||
| }), | ||
| 'ChaCha20-Poly1305 encrypt with valid tagLength'); | ||
| }, 'supports returns true for algorithm objects with valid parameters'); | ||
|
|
||
| // Test some algorithm objects with invalid parameters | ||
| test(() => { | ||
| assert_false( | ||
| SubtleCrypto.supports('encrypt', { | ||
| name: 'ChaCha20-Poly1305', | ||
| iv: new Uint8Array(12), | ||
| tagLength: 100, | ||
| }), | ||
| 'ChaCha20-Poly1305 encrypt with invalid tagLength'); | ||
|
|
||
| assert_false( | ||
| SubtleCrypto.supports('encrypt', { | ||
| name: 'ChaCha20-Poly1305', | ||
| iv: new Uint8Array(10), | ||
| tagLength: 128, | ||
| }), | ||
| 'ChaCha20-Poly1305 encrypt with invalid iv'); | ||
| }, 'supports returns false for algorithm objects with invalid parameters'); | ||
|
|
||
|
|
||
| done(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not a huge fan of suppressing errors like this. If this is part of the spec that this method should not throw, a comment here would be good.