OLD | NEW |
| (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("Tests structured cloning of AES keys"); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 // Tests the 32 permutations of keys generated by: | |
17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
KeyData | |
18 // | |
19 // For practical reasons these tests are not exhaustive. | |
20 | |
21 var k128BitData = "30112233445566778899aabbccddeeff" | |
22 var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0
e0f"; | |
23 | |
24 var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM']; | |
25 var kPossibleExtractable = [true, false]; | |
26 var kPossibleKeyUsages = [['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrap
Key', 'unwrapKey']]; | |
27 var kPossibleKeyData = [k128BitData, k256BitData]; | |
28 | |
29 function runTest(algorithmName, extractable, keyUsages, keyData) | |
30 { | |
31 var importData = hexStringToUint8Array(keyData); | |
32 var importAlgorithm = { name: algorithmName }; | |
33 | |
34 var results = {}; | |
35 | |
36 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab
le, keyUsages).then(function(importedKey) { | |
37 results.importedKey = importedKey; | |
38 importedKey.extraProperty = 'hi'; | |
39 return cloneKey(importedKey); | |
40 }).then(function(clonedKey) { | |
41 results.clonedKey = clonedKey; | |
42 if (extractable) | |
43 return crypto.subtle.exportKey('raw', clonedKey); | |
44 return null; | |
45 }).then(function(clonedKeyData) { | |
46 importedKey = results.importedKey; | |
47 clonedKey = results.clonedKey; | |
48 | |
49 shouldEvaluateAs("importedKey.extraProperty", "hi"); | |
50 shouldEvaluateAs("importedKey.type", "secret"); | |
51 shouldEvaluateAs("importedKey.extractable", extractable); | |
52 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); | |
53 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8); | |
54 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); | |
55 | |
56 shouldNotBe("importedKey", "clonedKey"); | |
57 | |
58 shouldBeUndefined("clonedKey.extraProperty"); | |
59 shouldEvaluateAs("clonedKey.type", "secret"); | |
60 shouldEvaluateAs("clonedKey.extractable", extractable); | |
61 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); | |
62 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8); | |
63 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); | |
64 | |
65 logSerializedKey(importedKey); | |
66 | |
67 if (extractable) | |
68 bytesShouldMatchHexString("Cloned key exported data", keyData, clone
dKeyData); | |
69 | |
70 debug(""); | |
71 }); | |
72 } | |
73 | |
74 var lastPromise = Promise.resolve(null); | |
75 | |
76 kPossibleAlgorithms.forEach(function(algorithmName) { | |
77 kPossibleExtractable.forEach(function(extractable) { | |
78 kPossibleKeyUsages.forEach(function(keyUsages) { | |
79 kPossibleKeyData.forEach(function(keyData) { | |
80 lastPromise = lastPromise.then(runTest.bind(null, algorithmName,
extractable, keyUsages, keyData)); | |
81 }); | |
82 }); | |
83 }); | |
84 }); | |
85 | |
86 lastPromise.then(finishJSTest, failAndFinishJSTest); | |
87 | |
88 </script> | |
89 | |
90 </body> | |
91 </html> | |
OLD | NEW |