Skip to content

Commit fc09f06

Browse files
test: update WPT for WebCryptoAPI to a6a0a0292a
1 parent 97af3d7 commit fc09f06

5 files changed

Lines changed: 95 additions & 10 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
emptyExpected: digestedData[alg].empty,
5252
label: upCase + " with " + size + " source data",
5353
mutations: true,
54-
transferBeforeCall: true,
5554
});
5655
vectors.push({
5756
algorithm: {name: downCase},

test/fixtures/wpt/WebCryptoAPI/digest/digest.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,10 @@ function runDigestTests(subtle, sourceData, getVectors) {
5858

5959
promise_test(function () {
6060
var buffer = new Uint8Array(sourceData[size]);
61-
var algorithm = vector.transferBeforeCall
62-
? vector.algorithm
63-
: withNameGetter(vector.algorithm, function () {
64-
buffer.buffer.transfer();
65-
return algorithmName(vector.algorithm);
66-
});
67-
if (vector.transferBeforeCall) {
61+
var algorithm = withNameGetter(vector.algorithm, function () {
6862
buffer.buffer.transfer();
69-
}
63+
return algorithmName(vector.algorithm);
64+
});
7065
return subtle.digest(algorithm, buffer).then(function (result) {
7166
assert_true(
7267
equalBuffers(result, vector.emptyExpected),
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// META: title=WebCryptoAPI: exportKey() and wrapKey() check export support first
2+
3+
// HKDF and PBKDF2 are not registered for the export key operation, and their
4+
// keys can only be imported as non-extractable. Both error conditions are
5+
// therefore always true at once, which makes the order observable.
6+
//
7+
// exportKey: step 6 (NotSupportedError) precedes step 7 (InvalidAccessError).
8+
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-exportKey
9+
//
10+
// wrapKey: step 11 (NotSupportedError) precedes step 12 (InvalidAccessError).
11+
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-wrapKey
12+
13+
function importDeriveKey(name) {
14+
return crypto.subtle.importKey('raw', new Uint8Array([]), name, false,
15+
['deriveBits']);
16+
}
17+
18+
function importAesKey(name, usages) {
19+
return crypto.subtle.importKey('raw', new Uint8Array(16), name, false,
20+
usages);
21+
}
22+
23+
for (const name of ['HKDF', 'PBKDF2']) {
24+
promise_test(async (t) => {
25+
const key = await importDeriveKey(name);
26+
return promise_rejects_dom(t, 'NotSupportedError',
27+
crypto.subtle.exportKey('raw', key));
28+
}, `exportKey() with a ${name} key throws NotSupportedError`);
29+
30+
promise_test(async (t) => {
31+
const key = await importDeriveKey(name);
32+
const wrappingKey = await importAesKey('AES-KW', ['wrapKey']);
33+
return promise_rejects_dom(
34+
t, 'NotSupportedError',
35+
crypto.subtle.wrapKey('raw', key, wrappingKey, 'AES-KW'));
36+
}, `wrapKey() with a ${name} key throws NotSupportedError`);
37+
}
38+
39+
// An algorithm that does support the export key operation must still report
40+
// the extractable check.
41+
promise_test(async (t) => {
42+
const key = await importAesKey('AES-CBC', ['encrypt']);
43+
return promise_rejects_dom(t, 'InvalidAccessError',
44+
crypto.subtle.exportKey('raw', key));
45+
}, 'exportKey() with a non-extractable AES-CBC key throws InvalidAccessError');
46+
47+
promise_test(async (t) => {
48+
const key = await importAesKey('AES-CBC', ['encrypt']);
49+
const wrappingKey = await importAesKey('AES-KW', ['wrapKey']);
50+
return promise_rejects_dom(
51+
t, 'InvalidAccessError',
52+
crypto.subtle.wrapKey('raw', key, wrappingKey, 'AES-KW'));
53+
}, 'wrapKey() with a non-extractable AES-CBC key throws InvalidAccessError');
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// META: title=WebCryptoAPI: BufferSource arguments and members reject shared buffers
2+
3+
// None of the BufferSource arguments of SubtleCrypto, or of the dictionaries it
4+
// takes, are [AllowShared], so a SharedArrayBuffer, or a view onto one, has to
5+
// throw a TypeError.
6+
//
7+
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`.
8+
const sharedBuffer = new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 }).buffer;
9+
10+
function generateAesGcmKey() {
11+
return crypto.subtle.generateKey({ name: "AES-GCM", length: 128 }, false, ["encrypt"]);
12+
}
13+
14+
for (const [kind, buffer] of [["SharedArrayBuffer", sharedBuffer],
15+
["Uint8Array(SharedArrayBuffer)", new Uint8Array(sharedBuffer)]]) {
16+
promise_test(t => {
17+
return promise_rejects_js(t, TypeError, crypto.subtle.digest("SHA-256", buffer));
18+
}, `digest() data is a ${kind}`);
19+
20+
promise_test(async t => {
21+
const key = await generateAesGcmKey();
22+
await promise_rejects_js(t, TypeError,
23+
crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12) }, key, buffer));
24+
}, `encrypt() data is a ${kind}`);
25+
26+
promise_test(async t => {
27+
const key = await generateAesGcmKey();
28+
await promise_rejects_js(t, TypeError,
29+
crypto.subtle.encrypt({ name: "AES-GCM", iv: buffer }, key, new Uint8Array(1)));
30+
}, `encrypt() AesGcmParams.iv is a ${kind}`);
31+
32+
promise_test(async t => {
33+
const key = await generateAesGcmKey();
34+
await promise_rejects_js(t, TypeError,
35+
crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12), additionalData: buffer },
36+
key, new Uint8Array(1)));
37+
}, `encrypt() AesGcmParams.additionalData is a ${kind}`);
38+
}

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"path": "web-locks"
101101
},
102102
"WebCryptoAPI": {
103-
"commit": "55ce71bb9deaf4b8a30fe80f95558a10699fb433",
103+
"commit": "a6a0a0292a4706866328488ffaaace00400edcc6",
104104
"path": "WebCryptoAPI"
105105
},
106106
"webidl": {

0 commit comments

Comments
 (0)