Skip to content

Commit 9220d4e

Browse files
test: update WPT for WebCryptoAPI to c9e955840a
PR-URL: #62147 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 17c76c1 commit 9220d4e

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
lines changed

test/fixtures/wpt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Last update:
3434
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3535
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
3636
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
37-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/42e47329fd/WebCryptoAPI
37+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/c9e955840a/WebCryptoAPI
3838
- webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl
3939
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
4040
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
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"`);

test/fixtures/wpt/WebCryptoAPI/wrapKey_unwrapKey/wrapKey_unwrapKey.https.any.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
name: "AES-KW",
4141
importParameters: {name: "AES-KW", length: 128},
4242
wrapParameters: {name: "AES-KW"}
43+
},
44+
{
45+
name: 'ChaCha20-Poly1305',
46+
importParameters: {name: "ChaCha20-Poly1305"},
47+
wrapParameters: {name: "ChaCha20-Poly1305", iv: new Uint8Array(12), additionalData: new Uint8Array(16)}
4348
}
4449
];
4550

@@ -57,7 +62,8 @@
5762
{algorithm: {name: "AES-CBC", length: 128}, usages: ["encrypt", "decrypt"]},
5863
{algorithm: {name: "AES-GCM", length: 128}, usages: ["encrypt", "decrypt"]},
5964
{algorithm: {name: "AES-KW", length: 128}, usages: ["wrapKey", "unwrapKey"]},
60-
{algorithm: {name: "HMAC", length: 128, hash: "SHA-256"}, usages: ["sign", "verify"]}
65+
{algorithm: {name: "HMAC", length: 128, hash: "SHA-256"}, usages: ["sign", "verify"]},
66+
{algorithm: {name: "ChaCha20-Poly1305"}, usages: ['encrypt', 'decrypt']}
6167
];
6268

6369
// Import all the keys needed, then iterate over all combinations
@@ -106,9 +112,15 @@
106112
.then(function(key) {
107113
wrappers["RSA-OAEP"].unwrappingKey = key;
108114
}));
115+
} else if (params.name === "ChaCha20-Poly1305") {
116+
var algorithm = {name: params.name};
117+
promises.push(subtle.importKey("raw", wrappingKeyData["SYMMETRIC256"].raw, algorithm, true, ["wrapKey", "unwrapKey"])
118+
.then(function(key) {
119+
wrappers[params.name] = {wrappingKey: key, unwrappingKey: key, parameters: params};
120+
}));
109121
} else {
110122
var algorithm = {name: params.name};
111-
promises.push(subtle.importKey("raw", wrappingKeyData["SYMMETRIC"].raw, algorithm, true, ["wrapKey", "unwrapKey"])
123+
promises.push(subtle.importKey("raw", wrappingKeyData["SYMMETRIC128"].raw, algorithm, true, ["wrapKey", "unwrapKey"])
112124
.then(function(key) {
113125
wrappers[params.name] = {wrappingKey: key, unwrappingKey: key, parameters: params};
114126
}));
@@ -151,9 +163,12 @@
151163
var keyData = toWrapKeyDataFromAlg(params.algorithm.name);
152164
promises.push(importAndExport("spki", keyData.spki, params.algorithm, params.publicUsages, "public key "));
153165
promises.push(importAndExport("pkcs8", keyData.pkcs8, params.algorithm, params.privateUsages, "private key "));
166+
} else if (params.algorithm.name === "ChaCha20-Poly1305") {
167+
keys[params.algorithm.name] = {};
168+
promises.push(importAndExport("raw", toWrapKeyData["SYMMETRIC256"].raw, params.algorithm, params.usages, ""));
154169
} else {
155170
keys[params.algorithm.name] = {};
156-
promises.push(importAndExport("raw", toWrapKeyData["SYMMETRIC"].raw, params.algorithm, params.usages, ""));
171+
promises.push(importAndExport("raw", toWrapKeyData["SYMMETRIC128"].raw, params.algorithm, params.usages, ""));
157172
}
158173
});
159174
// Using allSettled to skip unsupported test cases.
@@ -432,6 +447,9 @@
432447
case "ECDH" :
433448
deriveParams = {name: "ECDH"};
434449
break;
450+
case "ChaCha20-Poly1305":
451+
cryptParams = {name: "ChaCha20-Poly1305", iv: new Uint8Array(12)};
452+
break;
435453
default:
436454
throw new Error("Unsupported algorithm for key comparison");
437455
}

test/fixtures/wpt/WebCryptoAPI/wrapKey_unwrapKey/wrapKey_unwrapKey_vectors.js

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"path": "web-locks"
9797
},
9898
"WebCryptoAPI": {
99-
"commit": "42e47329fdc92c80d58c2816eb66cb2cf2b32a89",
99+
"commit": "c9e955840a21be6e492225a4a53fc4828d8933b9",
100100
"path": "WebCryptoAPI"
101101
},
102102
"webidl": {

0 commit comments

Comments
 (0)