| Index: LayoutTests/crypto/rsa-oaep-key-manipulation.html
|
| diff --git a/LayoutTests/crypto/rsa-oaep-key-manipulation.html b/LayoutTests/crypto/rsa-oaep-key-manipulation.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..dc616182dff133d2406616f1131eac074879edf8
|
| --- /dev/null
|
| +++ b/LayoutTests/crypto/rsa-oaep-key-manipulation.html
|
| @@ -0,0 +1,90 @@
|
| +<!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 generating, importing and exporting RSA keys for RSA-OAEP. Test that they can't be used with another algorithm.");
|
| +
|
| +jsTestIsAsync = true;
|
| +
|
| +var algorithmKeyGen = {
|
| + name: "RSA-OAEP",
|
| + hash: {name: "sha-1"},
|
| + // RsaKeyGenParams
|
| + modulusLength: 2048,
|
| + publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
|
| +};
|
| +var extractable = true;
|
| +
|
| +debug("Generating a key pair...");
|
| +crypto.subtle.generateKey(algorithmKeyGen, extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]).then(function(result) {
|
| + keyPair = result;
|
| + shouldBe("keyPair.toString()", "'[object KeyPair]'");
|
| + shouldBe("keyPair.publicKey.type", "'public'");
|
| + shouldBe("keyPair.publicKey.algorithm.name", "'RSA-OAEP'");
|
| + shouldBe("keyPair.publicKey.algorithm.modulusLength", "2048");
|
| + shouldBe("keyPair.publicKey.usages", '["encrypt", "wrapKey"]');
|
| + shouldBe("bytesToHexString(keyPair.publicKey.algorithm.publicExponent)", "'010001'");
|
| + shouldBe("keyPair.publicKey.algorithm.hash.name", "'SHA-1'");
|
| + shouldBe("keyPair.privateKey.type", "'private'");
|
| + shouldBe("keyPair.privateKey.algorithm.name", "'RSA-OAEP'");
|
| + shouldBe("keyPair.privateKey.algorithm.modulusLength", "2048");
|
| + shouldBe("keyPair.privateKey.usages", '["decrypt", "unwrapKey"]');
|
| + shouldBe("bytesToHexString(keyPair.privateKey.algorithm.publicExponent)", "'010001'");
|
| + shouldBe("keyPair.privateKey.algorithm.hash.name", "'SHA-1'");
|
| +
|
| + debug("\nTesting that the keys can't be used with different algorithms...");
|
| + iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
|
| +
|
| + return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, keyPair.privateKey, hexStringToUint8Array("00"));
|
| +}, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
|
| + logError(result);
|
| + return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, keyPair.publicKey, hexStringToUint8Array("00"));
|
| +}, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
|
| + logError(result);
|
| + debug("\nTrying to export keys to raw...");
|
| + return crypto.subtle.exportKey('raw', keyPair.publicKey);
|
| +}, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
|
| + logError(result);
|
| + testPassed("Promise rejected for exporting public key");
|
| + return crypto.subtle.exportKey('raw', keyPair.privateKey);
|
| +}).then(failAndFinishJSTest, function(result) {
|
| + logError(result);
|
| + testPassed("Promise rejected for exporting private key");
|
| +
|
| + debug("\nExporting public key to JWK...");
|
| + return crypto.subtle.exportKey("jwk", keyPair.publicKey);
|
| +}).then(function(result) {
|
| + jwkPublicKeyArray = result;
|
| + jwkPublicKey = JSON.parse(bytesToASCIIString(jwkPublicKeyArray));
|
| + shouldBe("jwkPublicKey.alg", "'RSA-OAEP'");
|
| + shouldBe("jwkPublicKey.ext", "true");
|
| + shouldBe("jwkPublicKey.key_ops", "['encrypt', 'wrapKey']");
|
| + shouldBe("jwkPublicKey.use", "undefined");
|
| + shouldBe("jwkPublicKey.kty", "'RSA'");
|
| + shouldBe("bytesToHexString(Base64URL.parse(jwkPublicKey.e))", "'010001'");
|
| +
|
| + debug("\nImporting it back...");
|
| + return crypto.subtle.importKey("jwk", jwkPublicKeyArray, { name: "RSA-OAEP", hash: {name: "sha-1"} }, extractable, ["encrypt", "wrapKey"]);
|
| +}).then(function(result) {
|
| + exportedPublicKey = result;
|
| + shouldBe("exportedPublicKey.type", "'public'");
|
| + shouldBe("exportedPublicKey.algorithm.name", "'RSA-OAEP'");
|
| + shouldBe("exportedPublicKey.algorithm.modulusLength", "2048");
|
| + shouldBe("bytesToHexString(exportedPublicKey.algorithm.publicExponent)", "'010001'");
|
| + shouldBe("exportedPublicKey.algorithm.hash.name", "'SHA-1'");
|
| + shouldBe("exportedPublicKey.extractable", "true");
|
| + shouldBe("exportedPublicKey.usages", "['encrypt','wrapKey']");
|
| +
|
| +}).then(finishJSTest, failAndFinishJSTest);
|
| +
|
| +</script>
|
| +
|
| +</body>
|
| +</html>
|
|
|