blob: 010e09a0664009bded57e9157dd35a25710457db [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 deriving HMAC Keys with imported ECDH base key");
jsTestIsAsync = true;
var extractable = true;
var jwkPrivateKey = {
kty: "EC",
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
d: "ppxBSov3N8_AUcisAuvmLV4yE8e_L_BLE8bZb9Z1Xjg",
};
var jwkPublicKey = {
kty: "EC",
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
};
crypto.subtle.importKey("jwk", jwkPrivateKey, { name: "ECDH", namedCurve: "P-256" }, extractable, ["deriveKey"]).then(function(result) {
privateKey = result;
return crypto.subtle.importKey("jwk", jwkPublicKey, { name: "ECDH", namedCurve: "P-256" }, extractable, [ ]);
}).then(function(result) {
publicKey = result;
return crypto.subtle.deriveKey({ name:"ECDH", public:publicKey }, privateKey, {name: "hmac", hash: "sha-1", length: 128}, extractable, ['sign', 'verify']);
}).then(function(result) {
derivedKey = result;
shouldBe("derivedKey.type", "'secret'");
shouldBe("derivedKey.extractable", "true");
shouldBe("derivedKey.algorithm.name", "'HMAC'");
shouldBe("derivedKey.algorithm.length", "128");
shouldBe("derivedKey.algorithm.hash.name", "'SHA-1'");
shouldBe("derivedKey.usages", "['sign', 'verify']");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>