Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / crypto / test / test_WebCrypto_Import_Multiple_Identical_Keys.html
blob22c198d62a3c8334ffe8f2c13367e0cc943b40a8
1 <!DOCTYPE html>
2 <html>
4 <head>
5 <title>WebCrypto Test Suite</title>
6 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
7 <link rel="stylesheet" href="./test_WebCrypto.css"/>
8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <!-- General testing framework -->
11 <script src="./test-array.js"></script>
13 <script>/* <![CDATA[*/
14 "use strict";
16 // -----------------------------------------------------------------------------
17 TestArray.addTest(
18 "Import the same ECDSA key multiple times and ensure that it can be used.",
19 function() {
20 var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
21 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
22 .then(function(keyPair) {
23 return crypto.subtle.exportKey("jwk", keyPair.privateKey);
25 .then(function(exportedKey) {
26 let keyImportPromises = [];
27 for (let i = 0; i < 20; i++) {
28 keyImportPromises.push(
29 crypto.subtle.importKey("jwk", exportedKey, alg, false, ["sign"]));
31 return Promise.all(keyImportPromises);
33 .then(function(importedKeys) {
34 let signPromises = [];
35 let data = crypto.getRandomValues(new Uint8Array(32));
36 for (let key of importedKeys) {
37 signPromises.push(crypto.subtle.sign(alg, key, data));
39 return Promise.all(signPromises);
41 .then(complete(this, function(signatures) {
42 return signatures.length == 20;
43 }), error(this));
47 // -----------------------------------------------------------------------------
48 // This is the same test, but with an RSA key. This test framework stringifies
49 // each test so it can be sent to and ran in a worker, which unfortunately
50 // means we can't factor out common code here.
51 TestArray.addTest(
52 "Import the same RSA key multiple times and ensure that it can be used.",
53 function() {
54 var alg = {
55 name: "RSASSA-PKCS1-v1_5",
56 modulusLength: 2048,
57 publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
58 hash: "SHA-256",
60 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
61 .then(function(keyPair) {
62 return crypto.subtle.exportKey("jwk", keyPair.privateKey);
64 .then(function(exportedKey) {
65 let keyImportPromises = [];
66 for (let i = 0; i < 20; i++) {
67 keyImportPromises.push(
68 crypto.subtle.importKey("jwk", exportedKey, alg, false, ["sign"]));
70 return Promise.all(keyImportPromises);
72 .then(function(importedKeys) {
73 let signPromises = [];
74 let data = crypto.getRandomValues(new Uint8Array(32));
75 for (let key of importedKeys) {
76 signPromises.push(crypto.subtle.sign(alg, key, data));
78 return Promise.all(signPromises);
80 .then(complete(this, function(signatures) {
81 return signatures.length == 20;
82 }), error(this));
85 /* ]]>*/</script>
86 </head>
88 <body>
90 <div id="content">
91 <div id="head">
92 <b>Web</b>Crypto<br>
93 </div>
95 <div id="start" onclick="start();">RUN ALL</div>
97 <div id="resultDiv" class="content">
98 Summary:
99 <span class="pass"><span id="passN">0</span> passed, </span>
100 <span class="fail"><span id="failN">0</span> failed, </span>
101 <span class="pending"><span id="pendingN">0</span> pending.</span>
102 <br/>
103 <br/>
105 <table id="results">
106 <tr>
107 <th>Test</th>
108 <th>Result</th>
109 <th>Time</th>
110 </tr>
111 </table>
113 </div>
115 <div id="foot"></div>
116 </div>
118 </body>
119 </html>