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[*/
16 // -----------------------------------------------------------------------------
18 "Import the same ECDSA key multiple times and ensure that it can be used.",
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;
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.
52 "Import the same RSA key multiple times and ensure that it can be used.",
55 name
: "RSASSA-PKCS1-v1_5",
57 publicExponent
: new Uint8Array([0x01, 0x00, 0x01]),
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;
95 <div id=
"start" onclick=
"start();">RUN ALL
</div>
97 <div id=
"resultDiv" class=
"content">
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>
115 <div id=
"foot"></div>