| Index: LayoutTests/crypto/import-aes-key-bad-length.html
|
| diff --git a/LayoutTests/crypto/import-aes-key-bad-length.html b/LayoutTests/crypto/import-aes-key-bad-length.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e9455d6dbc40671418a5b38724d3f6324072bfd2
|
| --- /dev/null
|
| +++ b/LayoutTests/crypto/import-aes-key-bad-length.html
|
| @@ -0,0 +1,59 @@
|
| +<!DOCTYPE html>
|
| +<html>
|
| +<head>
|
| +<script src="../resources/js-test.js"></script>
|
| +<script src="resources/common.js"></script>
|
| +</head>
|
| +<body>
|
| +<p id="description"></p>
|
| +<div id="console"></div>
|
| +
|
| +<script>
|
| +description("Tests importing an AES key from raw with wrong length");
|
| +
|
| +jsTestIsAsync = true;
|
| +
|
| +// -------------------------------------------------
|
| +// Failed key import.
|
| +// -------------------------------------------------
|
| +
|
| +// Supported key lengths are 16 (128-bit), 32 (256-bit), 24 (192-bit),
|
| +// Try key lengths that are off by 1 from the supported ones.
|
| +var kUnsupportedKeyLengths = [
|
| + 0, 1, 15, 17, 31, 33, 23, 25, 64
|
| +];
|
| +
|
| +// Not exhaustive
|
| +var kAesAlgorithms = [
|
| + "AES-CBC", "AES-GCM", "AES-KW"
|
| +];
|
| +
|
| +function testInvalidKeyImport(algorithmName, keyLengthBytes)
|
| +{
|
| + var algorithm = {name: algorithmName};
|
| + var keyData = new Uint8Array(keyLengthBytes);
|
| +
|
| + var usages = ['encrypt', 'decrypt'];
|
| + var extractable = false;
|
| +
|
| + return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usages).then(function(result) {
|
| + debug("FAIL: Successfully imported " + algorithmName + " key of length " + keyData.byteLength + " bytes");
|
| + }, function(result) {
|
| + debug("PASS: Failed to import " + algorithmName + " key of length " + keyData.byteLength + " bytes");
|
| + });
|
| +}
|
| +
|
| +var lastPromise = Promise.resolve(null);
|
| +
|
| +kAesAlgorithms.forEach(function(algorithmName) {
|
| + kUnsupportedKeyLengths.forEach(function(keyLengthBytes) {
|
| + lastPromise = lastPromise.then(testInvalidKeyImport.bind(null, algorithmName, keyLengthBytes));
|
| + });
|
| +});
|
| +
|
| +lastPromise.then(finishJSTest, failAndFinishJSTest);
|
| +
|
| +</script>
|
| +
|
| +</body>
|
| +</html>
|
|
|