blob: 0857ca45a02afba7e67d1e0f169ef6e21882bf5a [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test encrypting using AES-CBC/AES-CFB with malformed parameters");
jsTestIsAsync = true;
var extractable = false;
var plainText = asciiToUint8Array("Hello, World!");
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["encrypt"]).then(function(result) {
key = result;
// Malformed AlgorithmIdentifiers
shouldReject('crypto.subtle.encrypt("aes-cbc", key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc"}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: true}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: 1}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: null}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: undefined}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: Symbol()}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: { }}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: "foo"}, key, plainText)');
// Wrong iv length
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: asciiToUint8Array("")}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: asciiToUint8Array("j")}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cbc", iv: asciiToUint8Array("jnOw99oOZFLIEPMrd")}, key, plainText)');
finishJSTest();
});
crypto.subtle.importKey("raw", rawKey, "aes-cfb-8", extractable, ["encrypt"]).then(function(result) {
key = result;
// Malformed AlgorithmIdentifiers
shouldReject('crypto.subtle.encrypt("aes-cfb-8", key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cfb-8"}, key, plainText)');
// Wrong iv length
shouldReject('crypto.subtle.encrypt({name: "aes-cfb-8", iv: asciiToUint8Array("")}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cfb-8", iv: asciiToUint8Array("j")}, key, plainText)');
shouldReject('crypto.subtle.encrypt({name: "aes-cfb-8", iv: asciiToUint8Array("jnOw99oOZFLIEPMrd")}, key, plainText)');
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>