blob: 27da942168baf6eb94d46f589a8e1f79ab76873f [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 a key with malformed parameters");
var jwkKey = {
kty: "oct",
k: "YWJjZGVmZ2gxMjM0NTY3OA",
alg: "A128CBC"
};
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMrgJB55WL46tJSLGt7");
var jwkPrivateKey = {
kty: "RSA",
alg: "RSA1_5",
use: "enc",
key_ops: ["decrypt"],
ext: true,
n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
e: "AQAB",
d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ",
p: "4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0",
q: "xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc",
dp: "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk",
dq: "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE",
qi: "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk",
};
var extractable = true;
// Not enough arguments.
shouldReject('crypto.subtle.importKey()');
shouldReject('crypto.subtle.importKey(1)');
shouldReject('crypto.subtle.importKey(1, 2)');
shouldReject('crypto.subtle.importKey(1, 2, 3)');
shouldReject('crypto.subtle.importKey(1, 2, 3, 4)');
// Wrong formats.
shouldReject('crypto.subtle.importKey(1, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey(true, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey(null, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey(undefined, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey(Symbol(), rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey({ }, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("foo", rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
// Wrong KeyData.
shouldReject('crypto.subtle.importKey("raw", jwkKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", 1, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", true, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", null, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", undefined, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", Symbol(), "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", { }, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("raw", "foo", "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", 1, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", true, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", Symbol(), "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", { }, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", "foo", "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", undefined, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
shouldReject('crypto.subtle.importKey("jwk", null, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
// Null usages.
shouldReject('crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, [ ])');
shouldReject('crypto.subtle.importKey("jwk", jwkPrivateKey, "rsaes-pkcs1-v1_5", extractable, [ ])');
// JWK: missing kty.
shouldReject('crypto.subtle.importKey("jwk", {kty: undefined}, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
// JWK: wrong key_ops.
shouldReject('crypto.subtle.importKey("jwk", {kty: "oct", key_ops: ["foo"]}, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>