Skip to content

Commit 9d18397

Browse files
Fredrik Söderquistchromium-wpt-export-bot
authored andcommitted
Use EqualIgnoringAsciiCase() in LookupAlgorithmIdByName()
The "Normalizing an algorithm" algorithm[1] says that names should be matched ASCII case-insensitive [2]. Currently the lookup sort of does that, but the verifying comparison still uses a full Unicode case-folding comparison. Because of how the lookup is structured the lookup for some algorithm names could still accept non-ASCII. Replace the final DeprecatedEqualIgnoringCase() comparison with EqualIgnoringAsciiCase(). [1] https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm [2] https://w3c.github.io/webcrypto/#case-insensitive Bug: 40476285 Change-Id: If1ee6a3c1e75f271c171b44f8de31fe688546b0c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7633022 Reviewed-by: Kent Tamura <tkent@chromium.org> Commit-Queue: Fredrik Söderquist <fs@opera.com> Cr-Commit-Position: refs/heads/main@{#1594550}
1 parent 3db1450 commit 9d18397

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// META: title=WebCryptoAPI: Algorithm normalization matches names ASCII case-insensitively
2+
// U+212A is the Kelvin Sign
3+
4+
function makeSalt() {
5+
return crypto.getRandomValues(new Uint8Array(32));
6+
}
7+
8+
async function makeKey(algorithm) {
9+
const keyData = new Uint8Array([]);
10+
return crypto.subtle.importKey("raw", keyData, algorithm, false, ["deriveBits"]);
11+
}
12+
13+
promise_test(async (t) => {
14+
const algorithm = {
15+
name: "H\u212ADF",
16+
hash: "SHA-256",
17+
salt: makeSalt(),
18+
info: new TextEncoder().encode(''),
19+
};
20+
const key = await makeKey("HKDF");
21+
const p = crypto.subtle.deriveBits(algorithm, key, 256);
22+
return promise_rejects_dom(t, "NotSupportedError", p, algorithm.name);
23+
}, `"H<U+212A>DF" does not match "HKDF"`);
24+
25+
promise_test(async (t) => {
26+
const algorithm = {
27+
name: "PB\u212ADF2",
28+
hash: "SHA-256",
29+
iterations: 1,
30+
salt: makeSalt(),
31+
};
32+
const key = await makeKey("PBKDF2");
33+
const p = crypto.subtle.deriveBits(algorithm, key, 256);
34+
return promise_rejects_dom(t, "NotSupportedError", p, algorithm.name);
35+
}, `"PB<U+212A>DF2" does not match "PBKDF2"`);
36+
37+
promise_test(async (t) => {
38+
const algorithm = {name: "AES-\u212AW", length: 256};
39+
const p = crypto.subtle.generateKey(algorithm, false, ["wrapKey"]);
40+
return promise_rejects_dom(t, "NotSupportedError", p, algorithm.name);
41+
}, `"AES-<U+212A>W" does not match "AES-KW"`);
42+
43+
promise_test(async (t) => {
44+
const algorithm = {
45+
name: "RSASSA-P\u212ACS1-V1_5",
46+
modulusLength: 2048,
47+
publicExponent: new Uint8Array([3]),
48+
hash: "SHA-256",
49+
};
50+
const p = crypto.subtle.generateKey(algorithm, false, ["sign"]);
51+
return promise_rejects_dom(t, "NotSupportedError", p, algorithm.name);
52+
}, `"RSASSA-P<U+212A>CS1-V1_5" does not match "RSASSA-PKCS1-V1_5"`);

0 commit comments

Comments
 (0)