| Index: LayoutTests/crypto/hmac-import-jwk.html
|
| diff --git a/LayoutTests/crypto/hmac-import-jwk.html b/LayoutTests/crypto/hmac-import-jwk.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..93f7273521fcfccf07c6b6a8691c0539a77c4226
|
| --- /dev/null
|
| +++ b/LayoutTests/crypto/hmac-import-jwk.html
|
| @@ -0,0 +1,54 @@
|
| +<!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("Test importing a JWK key for HMAC.");
|
| +
|
| +jsTestIsAsync = true;
|
| +
|
| +var nonExtractable = false;
|
| +var extractable = true;
|
| +
|
| +var hmacKey = {
|
| + "kty": "oct",
|
| + "alg": "HS256",
|
| + "use": "sig",
|
| + "ext": false,
|
| + "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
|
| +};
|
| +
|
| +var hmacKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(hmacKey));
|
| +
|
| +debug("Importing a key...\n");
|
| +crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, {name: "HMAC", hash: {name: "SHA-256"}}, nonExtractable, ["sign", "verify"]).then(function(result) {
|
| + key = result;
|
| +
|
| + shouldBe("key.type", "'secret'");
|
| + shouldBe("key.extractable", "false");
|
| + shouldBe("key.algorithm.name", "'HMAC'");
|
| + shouldBe("key.algorithm.length", "256");
|
| + shouldBe("key.usages", '["sign", "verify"]');
|
| +
|
| + debug("\nUsing the key to sign message 'foo'...");
|
| + return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
|
| +}).then(function(result) {
|
| + signature = result;
|
| + shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
|
| +
|
| + debug("\nVerifying the signature...");
|
| + return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
|
| +}).then(function(result) {
|
| + verificationResult = result;
|
| + shouldBe("verificationResult", "true");
|
| +}).then(finishJSTest, failAndFinishJSTest);
|
| +</script>
|
| +
|
| +</body>
|
| +</html>
|
|
|