Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / crypto / test / test_WebCrypto_Structured_Cloning.html
blob7272b4839d7e9f373be5e7b059c7e96c2738aef8
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 <!-- Utilities for manipulating ABVs -->
11 <script src="util.js"></script>
13 <!-- A simple wrapper around IndexedDB -->
14 <script src="simpledb.js"></script>
16 <!-- Test vectors drawn from the literature -->
17 <script src="./test-vectors.js"></script>
19 <!-- General testing framework -->
20 <script src="./test-array.js"></script>
22 <script>/* <![CDATA[*/
23 "use strict";
25 // -----------------------------------------------------------------------------
26 TestArray.addTest(
27 "Structured Cloning: AES-CTR",
28 function() {
29 var that = this;
30 var data = crypto.getRandomValues(new Uint8Array(128));
31 var iv = crypto.getRandomValues(new Uint8Array(16));
32 var alg = {name: "AES-CTR", length: 128, iv};
34 var counter = new Uint8Array(16);
35 var algEncrypt = {name: "AES-CTR", length: 128, counter};
37 crypto.subtle.generateKey(alg, true, ["encrypt"])
38 .then(util.cloneExportCompareKeys)
39 .then(x => crypto.subtle.encrypt(algEncrypt, x, data))
40 .then(complete(that), error(that));
44 // -----------------------------------------------------------------------------
45 TestArray.addTest(
46 "Structured Cloning: AES-CBC",
47 function() {
48 var that = this;
49 var data = crypto.getRandomValues(new Uint8Array(128));
50 var iv = crypto.getRandomValues(new Uint8Array(16));
51 var alg = {name: "AES-CBC", length: 128, iv};
53 crypto.subtle.generateKey(alg, true, ["encrypt"])
54 .then(util.cloneExportCompareKeys)
55 .then(x => crypto.subtle.encrypt(alg, x, data))
56 .then(complete(that), error(that));
60 // -----------------------------------------------------------------------------
61 TestArray.addTest(
62 "Structured Cloning: AES-GCM",
63 function() {
64 var that = this;
65 var data = crypto.getRandomValues(new Uint8Array(128));
66 var iv = crypto.getRandomValues(new Uint8Array(16));
67 var alg = {name: "AES-GCM", length: 128, iv};
69 crypto.subtle.generateKey(alg, true, ["encrypt"])
70 .then(util.cloneExportCompareKeys)
71 .then(x => crypto.subtle.encrypt(alg, x, data))
72 .then(complete(that), error(that));
76 // -----------------------------------------------------------------------------
77 TestArray.addTest(
78 "Structured Cloning: AES-KW",
79 function() {
80 var that = this;
81 var alg = {name: "AES-KW", length: 128};
83 crypto.subtle.generateKey(alg, true, ["wrapKey"])
84 .then(util.cloneExportCompareKeys)
85 .then(x => crypto.subtle.wrapKey("raw", x, x, "AES-KW"))
86 .then(complete(that), error(that));
90 // -----------------------------------------------------------------------------
91 TestArray.addTest(
92 "Structured Cloning: HMAC",
93 function() {
94 var that = this;
95 var data = crypto.getRandomValues(new Uint8Array(128));
96 var alg = {name: "HMAC", length: 256, hash: "SHA-256"};
98 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
99 .then(util.cloneExportCompareKeys)
100 .then(x => crypto.subtle.sign("HMAC", x, data))
101 .then(complete(that), error(that));
105 // -----------------------------------------------------------------------------
106 TestArray.addTest(
107 "Structured Cloning: PBKDF2",
108 function() {
109 var that = this;
110 var key = new TextEncoder().encode("password");
112 var alg = {
113 name: "PBKDF2",
114 hash: "SHA-1",
115 salt: crypto.getRandomValues(new Uint8Array(8)),
116 iterations: 4096,
119 crypto.subtle.importKey("raw", key, "PBKDF2", true, ["deriveBits"])
120 .then(util.cloneExportCompareKeys)
121 .then(x => crypto.subtle.deriveBits(alg, x, 160))
122 .then(complete(that), error(that));
126 // -----------------------------------------------------------------------------
127 TestArray.addTest(
128 "Structured Cloning: HKDF",
129 function() {
130 var that = this;
131 var key = new TextEncoder().encode("password");
133 var alg = {
134 name: "HKDF",
135 hash: "SHA-256",
136 salt: new Uint8Array(),
137 info: new Uint8Array(),
140 crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"])
141 .then(util.clone)
142 .then(x => crypto.subtle.deriveBits(alg, x, 16))
143 .then(complete(that), error(that));
147 // -----------------------------------------------------------------------------
148 TestArray.addTest(
149 "Structured Cloning: RSA-OAEP",
150 function() {
151 var that = this;
152 var data = crypto.getRandomValues(new Uint8Array(128));
154 var alg = {
155 name: "RSA-OAEP",
156 hash: "SHA-256",
157 modulusLength: 2048,
158 publicExponent: new Uint8Array([1, 0, 1]),
161 crypto.subtle.generateKey(alg, true, ["encrypt", "decrypt"])
162 .then(util.cloneExportCompareKeys)
163 .then(x => {
164 return crypto.subtle.encrypt(alg, x.publicKey, data)
165 .then(ct => crypto.subtle.decrypt(alg, x.privateKey, ct));
167 .then(complete(that), error(that));
171 // -----------------------------------------------------------------------------
172 TestArray.addTest(
173 "Structured Cloning: RSASSA-PKCS1-v1_5",
174 function() {
175 var that = this;
176 var data = crypto.getRandomValues(new Uint8Array(128));
178 var alg = {
179 name: "RSASSA-PKCS1-v1_5",
180 hash: "SHA-256",
181 modulusLength: 2048,
182 publicExponent: new Uint8Array([1, 0, 1]),
185 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
186 .then(util.cloneExportCompareKeys)
187 .then(x => {
188 return crypto.subtle.sign(alg, x.privateKey, data)
189 .then(sig => crypto.subtle.verify(alg, x.publicKey, sig, data));
191 .then(complete(that, x => x), error(that));
195 // -----------------------------------------------------------------------------
196 TestArray.addTest(
197 "Structured Cloning: RSA-PSS",
198 function() {
199 var that = this;
200 var data = crypto.getRandomValues(new Uint8Array(128));
202 var alg = {
203 name: "RSA-PSS",
204 hash: "SHA-256",
205 modulusLength: 2048,
206 publicExponent: new Uint8Array([1, 0, 1]),
207 saltLength: 20,
210 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
211 .then(util.cloneExportCompareKeys)
212 .then(x => {
213 return crypto.subtle.sign(alg, x.privateKey, data)
214 .then(sig => crypto.subtle.verify(alg, x.publicKey, sig, data));
216 .then(complete(that, x => x), error(that));
220 // -----------------------------------------------------------------------------
221 /* TestArray.addTest(
222 "Structured Cloning: DH",
223 function() {
224 var that = this;
225 var alg = {name: "DH", prime: tv.dh.prime, generator: new Uint8Array([2])};
227 crypto.subtle.generateKey(alg, true, ["deriveBits"])
228 .then(util.cloneExportCompareKeys)
229 .then(x => {
230 var alg = {name: "DH", public: x.publicKey};
231 return crypto.subtle.deriveBits(alg, x.privateKey, 16);
233 .then(complete(that), error(that));
235 );*/
237 // -----------------------------------------------------------------------------
238 /* TestArray.addTest(
239 "Structured Cloning: ECDH",
240 function() {
241 var that = this;
242 var alg = {name: "ECDH", namedCurve: "P-256"};
244 crypto.subtle.generateKey(alg, true, ["deriveBits"])
245 .then(util.cloneExportCompareKeys)
246 .then(x => {
247 var alg = {name: "ECDH", public: x.publicKey};
248 return crypto.subtle.deriveBits(alg, x.privateKey, 16);
250 .then(complete(that), error(that));
252 );*/
254 // -----------------------------------------------------------------------------
255 /* TestArray.addTest(
256 "Structured Cloning: ECDSA",
257 function() {
258 var that = this;
259 var data = crypto.getRandomValues(new Uint8Array(128));
260 var alg = {name: "ECDSA", namedCurve: "P-256", hash: "SHA-256"};
262 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
263 .then(util.cloneExportCompareKeys)
264 .then(x => {
265 return crypto.subtle.sign(alg, x.privateKey, data)
266 .then(sig => crypto.subtle.verify(alg, x.publicKey, sig, data));
268 .then(complete(that), error(that));
270 );*/
271 /* ]]>*/</script>
272 </head>
274 <body>
276 <div id="content">
277 <div id="head">
278 <b>Web</b>Crypto<br>
279 </div>
281 <div id="start" onclick="start();">RUN ALL</div>
283 <div id="resultDiv" class="content">
284 Summary:
285 <span class="pass"><span id="passN">0</span> passed, </span>
286 <span class="fail"><span id="failN">0</span> failed, </span>
287 <span class="pending"><span id="pendingN">0</span> pending.</span>
288 <br/>
289 <br/>
291 <table id="results">
292 <tr>
293 <th>Test</th>
294 <th>Result</th>
295 <th>Time</th>
296 </tr>
297 </table>
299 </div>
301 <div id="foot"></div>
302 </div>
304 </body>
305 </html>