blob: 22b9ad07b5d2861b15748a0c0ab696ca8fa62fb3 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../../resources/js-test-pre.js"></script>
<script src="../../resources/common.js"></script>
</head>
<body>
<script>
description("Test sending rsa crypto keys via postMessage to a worker.");
jsTestIsAsync = true;
var publicKeyJSON = {
kty: "RSA",
alg: "RSA1_5",
n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
e: "AQAB"
};
var privateKeyJSON = {
kty: "RSA",
alg: "RSA1_5",
n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
e: "AQAB",
d: "eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6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xTk"
};
var algorithmKeyGen = {
name: "RSAES-PKCS1-v1_5",
// RsaKeyGenParams
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
};
var count = 0;
var worker = new Worker("resources/rsa-postMessage-worker.js");
worker.onmessage = function(evt) {
if (!evt.data.result) {
testFailed("Check failed in worker: " + evt.data.message);
finishJSTest();
} else {
if (publicKey = evt.data.publicKey) {
testPassed("All checks passed in worker for public key");
shouldBe("publicKey.type", "'public'");
shouldBe("publicKey.extractable", "true");
shouldBe("publicKey.algorithm.name", "'RSAES-PKCS1-v1_5'");
shouldBe("publicKey.algorithm.modulusLength", "2048");
shouldBe("bytesToHexString(publicKey.algorithm.publicExponent)", "'010001'");
shouldBeUndefined("publicKey.algorithm.hash");
shouldBe("publicKey.usages", "['encrypt']");
crypto.subtle.exportKey("jwk", publicKey).then(function(result) {
count = count + 1;
exportedKey = result;
shouldBe("exportedKey.n", "publicKeyJSON.n");
shouldBe("exportedKey.e", "publicKeyJSON.e");
if (count == 2)
finishJSTest();
});
} else if (privateKey = evt.data.privateKey) {
testPassed("All checks passed in worker for private key");
shouldBe("privateKey.type", "'private'");
shouldBe("privateKey.extractable", "true");
shouldBe("privateKey.algorithm.name", "'RSAES-PKCS1-v1_5'");
shouldBe("privateKey.algorithm.modulusLength", "2048");
shouldBe("bytesToHexString(privateKey.algorithm.publicExponent)", "'010001'");
shouldBeUndefined("privateKey.algorithm.hash");
shouldBe("privateKey.usages", "['decrypt']");
crypto.subtle.exportKey("jwk", privateKey).then(function(result) {
count = count + 1;
exportedKey = result;
shouldBe("exportedKey.n", "privateKeyJSON.n");
shouldBe("exportedKey.e", "privateKeyJSON.e");
shouldBe("exportedKey.d", "privateKeyJSON.d");
shouldBe("exportedKey.p", "privateKeyJSON.p");
shouldBe("exportedKey.q", "privateKeyJSON.q");
shouldBe("exportedKey.dp", "privateKeyJSON.dp");
shouldBe("exportedKey.dq", "privateKeyJSON.dq");
shouldBe("exportedKey.qi", "privateKeyJSON.qi");
if (count == 2)
finishJSTest();
});
}
}
}
crypto.subtle.importKey("jwk", publicKeyJSON, algorithmKeyGen, true, ['encrypt']).then(function(localPublicKey) {
worker.postMessage({ publicKey: localPublicKey });
crypto.subtle.importKey("jwk", privateKeyJSON, algorithmKeyGen, true, ['decrypt']).then(function(localPrivateKey) {
worker.postMessage({ privateKey: localPrivateKey });
});
});
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>