blob: 57232214d35372fbc3f2e7aecebe1562f4cf22e6 [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 importing an HMAC key with malformed parameters");
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMrgJB55WL46tJSLGt7");
var extractable = true;
var k = "YWJjZGVmZ2gxMjM0NTY3OA";
// wrong length
shouldReject('crypto.subtle.importKey("raw", asciiToUint8Array(""), {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("raw", rawKey, {name: "hmac", hash: "sha-1", length: 257}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("raw", rawKey, {name: "hmac", hash: "sha-1", length: 248}, extractable, ["sign", "verify"])');
// Jwk: Wrong kty
shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA"}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
// Jwk: missing k
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct"}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
// Jwk: wrong hash and alg
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS224"}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS256"}, {name: "hmac", hash: "sha-224"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS384"}, {name: "hmac", hash: "sha-256"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS512"}, {name: "hmac", hash: "sha-384"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS1"}, {name: "hmac", hash: "sha-512"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: ""}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: ""}, {name: "hmac", hash: "sha-224"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: ""}, {name: "hmac", hash: "sha-256"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: ""}, {name: "hmac", hash: "sha-384"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: ""}, {name: "hmac", hash: "sha-512"}, extractable, ["sign", "verify"])');
// Jwk: wrong k format
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: "!!!", alg: "foo"}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: "", alg: "foo"}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
// Jwk: wrong use
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS1", use: "enc"}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS1", use: ""}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
// Jwk: wrong key_ops
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS1", key_ops: ["sign"]}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS1", key_ops: [ ]}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
// Jwk: wrong ext
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", k: k, alg: "HS1", ext: false}, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"])');
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>