Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: LayoutTests/crypto/rsa-oaep-key-manipulation.html

Issue 310513004: Import WebKit RSA-OAEP LayoutTests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add another test Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10
11 <script>
12 description("Test generating, importing and exporting RSA keys for RSA-OAEP. Tes t that they can't be used with another algorithm.");
13
14 jsTestIsAsync = true;
15
16 var algorithmKeyGen = {
17 name: "RSA-OAEP",
18 hash: {name: "sha-1"},
19 // RsaKeyGenParams
20 modulusLength: 2048,
21 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
22 };
23 var extractable = true;
24
25 debug("Generating a key pair...");
26 crypto.subtle.generateKey(algorithmKeyGen, extractable, ["encrypt", "decrypt", " wrapKey", "unwrapKey"]).then(function(result) {
27 keyPair = result;
28 shouldBe("keyPair.toString()", "'[object KeyPair]'");
29 shouldBe("keyPair.publicKey.type", "'public'");
30 shouldBe("keyPair.publicKey.algorithm.name", "'RSA-OAEP'");
31 shouldBe("keyPair.publicKey.algorithm.modulusLength", "2048");
32 shouldBe("keyPair.publicKey.usages", '["encrypt", "wrapKey"]');
33 shouldBe("bytesToHexString(keyPair.publicKey.algorithm.publicExponent)", "'0 10001'");
34 shouldBe("keyPair.publicKey.algorithm.hash.name", "'SHA-1'");
35 shouldBe("keyPair.privateKey.type", "'private'");
36 shouldBe("keyPair.privateKey.algorithm.name", "'RSA-OAEP'");
37 shouldBe("keyPair.privateKey.algorithm.modulusLength", "2048");
38 shouldBe("keyPair.privateKey.usages", '["decrypt", "unwrapKey"]');
39 shouldBe("bytesToHexString(keyPair.privateKey.algorithm.publicExponent)", "' 010001'");
40 shouldBe("keyPair.privateKey.algorithm.hash.name", "'SHA-1'");
41
42 debug("\nTesting that the keys can't be used with different algorithms...");
43 iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
44
45 return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, keyPair.privateKey, hexStringToUint8Array("00"));
46 }, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
47 logError(result);
48 return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, keyPair.publicKey, h exStringToUint8Array("00"));
49 }, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
50 logError(result);
51 debug("\nTrying to export keys to raw...");
52 return crypto.subtle.exportKey('raw', keyPair.publicKey);
53 }, failAndFinishJSTest).then(failAndFinishJSTest, function(result) {
54 logError(result);
55 testPassed("Promise rejected for exporting public key");
56 return crypto.subtle.exportKey('raw', keyPair.privateKey);
57 }).then(failAndFinishJSTest, function(result) {
58 logError(result);
59 testPassed("Promise rejected for exporting private key");
60
61 debug("\nExporting public key to JWK...");
62 return crypto.subtle.exportKey("jwk", keyPair.publicKey);
63 }).then(function(result) {
64 jwkPublicKeyArray = result;
65 jwkPublicKey = JSON.parse(bytesToASCIIString(jwkPublicKeyArray));
66 shouldBe("jwkPublicKey.alg", "'RSA-OAEP'");
67 shouldBe("jwkPublicKey.ext", "true");
68 shouldBe("jwkPublicKey.key_ops", "['encrypt', 'wrapKey']");
69 shouldBe("jwkPublicKey.use", "undefined");
70 shouldBe("jwkPublicKey.kty", "'RSA'");
71 shouldBe("bytesToHexString(Base64URL.parse(jwkPublicKey.e))", "'010001'");
72
73 debug("\nImporting it back...");
74 return crypto.subtle.importKey("jwk", jwkPublicKeyArray, { name: "RSA-OAEP", hash: {name: "sha-1"} }, extractable, ["encrypt", "wrapKey"]);
75 }).then(function(result) {
76 exportedPublicKey = result;
77 shouldBe("exportedPublicKey.type", "'public'");
78 shouldBe("exportedPublicKey.algorithm.name", "'RSA-OAEP'");
79 shouldBe("exportedPublicKey.algorithm.modulusLength", "2048");
80 shouldBe("bytesToHexString(exportedPublicKey.algorithm.publicExponent)", "'0 10001'");
81 shouldBe("exportedPublicKey.algorithm.hash.name", "'SHA-1'");
82 shouldBe("exportedPublicKey.extractable", "true");
83 shouldBe("exportedPublicKey.usages", "['encrypt','wrapKey']");
84
85 }).then(finishJSTest, failAndFinishJSTest);
86
87 </script>
88
89 </body>
90 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698