blob: 5e267ef766b0f23569b1ca269164a17e7281ff63 [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 exporting a generated RSA keypair with hash.");
jsTestIsAsync = true;
var extractable = true;
var algorithm = {
name: "RSASSA-PKCS1-v1_5",
modulusLength: "2048",
publicExponent: new Uint8Array([1, 0, 1]), // 2^16 + 1 (65537)
hash: { name: "SHA-256" }
};
debug("\nGenerating RSA-PKCS1-v1.5 keyPair...");
crypto.subtle.generateKey(algorithm, extractable, ['sign', 'verify'])
.then(function(result) {
key = result;
shouldThrow('crypto.subtle.exportKey(null, key)');
shouldThrow('crypto.subtle.exportKey(undefined, key)');
shouldThrow('crypto.subtle.exportKey({}, key)');
shouldThrow('crypto.subtle.exportKey("", key)');
shouldThrow('crypto.subtle.exportKey("foobar", key)');
shouldBeDefined('key.publicKey.algorithm.hash.name');
shouldBeDefined('key.privateKey.algorithm.hash.name');
debug("\nExporting public key as JWK...");
return crypto.subtle.exportKey("jwk", key.publicKey);
}).then(function(result) {
exportedJWK = JSON.parse(bytesToASCIIString(result));
shouldBe("exportedJWK.kty", "'RSA'");
shouldBe("exportedJWK.alg", "'RS256'");
shouldBe("exportedJWK.ext", "true");
shouldBe("exportedJWK.use", "undefined");
shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
debug("\nExporting private key as JWK...");
return crypto.subtle.exportKey("jwk", key.privateKey);
}).then(function(result) {
exportedJWK = JSON.parse(bytesToASCIIString(result));
shouldBe("exportedJWK.kty", "'RSA'");
shouldBe("exportedJWK.alg", "'RS256'");
shouldBe("exportedJWK.ext", "true");
shouldBe("exportedJWK.use", "undefined");
shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>