Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Last update:
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/288c467d35/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/0c413fb56b/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/03a1476844/WebCryptoAPI
- webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ function runTests(algorithmName) {
testFormat(format, algorithm, data, keyData.length * 8, usages, extractable);
});
testEmptyUsages(format, algorithm, data, keyData.length * 8, extractable);

// Verify the key data is copied only after the algorithm is
// normalized (per spec, "get a copy of the bytes held by the
// keyData parameter" follows "normalize an algorithm"). A
// getter on the algorithm name mutates the key data during
// normalization; the imported key must reflect the restored
// bytes. Checked for BufferSource formats (jwk key data is
// not a BufferSource) when the key is extractable, so the
// imported bytes can be read back and compared.
if (extractable && format !== "jwk") {
allValidUsages(vector.legalUsages).forEach(function(usages) {
testKeyDataAlteredDuringCall(format, algorithm, keyData, keyData.length * 8, usages);
});
}
});
});

Expand Down Expand Up @@ -111,6 +125,35 @@ function runTests(algorithmName) {
}, "Empty Usages: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, extractable, usages));
}

// Test that importKey copies the key data only after the algorithm has been
// normalized. The spec normalizes the algorithm (which can run author
// getters on the algorithm dictionary) before getting a copy of the bytes
// held by the keyData parameter. Here a getter on the algorithm's name
// mutates the key data during normalization and then restores it, so a
// spec-compliant implementation imports the restored (original) bytes.
function testKeyDataAlteredDuringCall(format, algorithm, keyData, keySize, usages) {
promise_test(function(test) {
var alteredKeyData = copyBuffer(keyData);
alteredKeyData[0] = 255 - alteredKeyData[0];
var algorithmWithGetter = {
...algorithm,
get name() {
alteredKeyData[0] = keyData[0];
return algorithm.name;
}
};
return subtle.importKey(format, alteredKeyData, algorithmWithGetter, true, usages).
then(function(key) {
return subtle.exportKey(format, key);
}).
then(function(result) {
assert_true(equalBuffers(keyData, result), "Imported key reflects the key data as it was after normalization");
}, function(err) {
assert_unreached("Threw an unexpected error: " + err.toString());
});
}, "Key data altered during call: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, true, usages));
}



// Helper methods follow:
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"path": "web-locks"
},
"WebCryptoAPI": {
"commit": "0c413fb56b9da8bf27502c866a3d60f93981804d",
"commit": "03a14768441c1ce2a31678d0dc080e81dc449d0a",
"path": "WebCryptoAPI"
},
"webidl": {
Expand Down
Loading