OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
| 6 <script src="resources/keys.js"></script> |
6 </head> | 7 </head> |
7 <body> | 8 <body> |
8 <p id="description"></p> | 9 <p id="description"></p> |
9 <div id="console"></div> | 10 <div id="console"></div> |
10 | 11 |
11 <script> | 12 <script> |
12 description("Tests structured cloning of RSA keys (without a hash)"); | 13 description("Tests structured cloning of RSA keys (without a hash)"); |
13 | 14 |
14 jsTestIsAsync = true; | 15 jsTestIsAsync = true; |
15 | 16 |
16 // Tests the 16 permutations of keys generated by: | 17 // Tests the 16 permutations of keys generated by: |
17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
KeyData | 18 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
KeyData |
18 // | 19 // |
19 // For practical reasons these tests are not exhaustive. | 20 // For practical reasons these tests are not exhaustive. |
20 | 21 |
21 var kPossibleAlgorithms = ['RSAES-PKCS1-v1_5']; | 22 var kPossibleAlgorithms = ['RSAES-PKCS1-v1_5']; |
22 var kPossibleExtractable = [true, false]; | 23 var kPossibleExtractable = [true, false]; |
23 var kPossibleKeyUsages = [[], ['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', '
wrapKey', 'unwrapKey']]; | 24 var kPossibleKeyUsages = [[], ['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', '
wrapKey', 'unwrapKey']]; |
24 | 25 |
25 var kPossibleKeyData = [ | 26 var kPossibleKeyData = [ |
26 { | 27 kKeyData.rsa2, |
27 modululusLengthBits: 1024, | 28 kKeyData.rsa3 |
28 publicExponent: "010001", | |
29 | |
30 spkiData: "30819f300d06092a864886f70d010101050003818d0030818902818100b2"
+ | |
31 "89c62ecc3ddf64154817203439eaa0dc07a65954429a7b6098a77235673d" + | |
32 "96df1f06bd3c1ae73990867199e678bf95b3728fcd4686136e6ee9dd4c09" + | |
33 "eb490eb7cb953c388668b759263f61d6a7dfcabf27b5c9d6972455b12b66" + | |
34 "d483843286d6b871f35f912a773c97c1932255fcee05ce7b8af213879f01" + | |
35 "7de4232a306a410203010001" | |
36 }, | |
37 { | |
38 modululusLengthBits: 2048, | |
39 publicExponent: "010001", | |
40 | |
41 spkiData: "30820122300d06092a864886f70d01010105000382010f003082010a0282"
+ | |
42 "010100b4c8b631194aef0154b1479ab7a534b60ca878981108680f0ae6b7" + | |
43 "c88cb6010f6dbf9f665646208410575cb923b26bf874a24b4cd801c9bba9" + | |
44 "67062ae506cdcf307add4380d0d93077a4c1f0fc06d498dc729f811335c5" + | |
45 "30b90fe9bf9f3979ccec050a48e8923045b19368e1e89ea4157538e8059e" + | |
46 "53320f47c155f1741310a93ed153a7f3af2d46c388b95d82518527a02b7b" + | |
47 "d9ab7edc4bcb737677f679c5c6de5e1ebed3a29d6b99b8eace2d59ceb533" + | |
48 "e001cf39c5671495d51d3ee34406ea4fdb0c626dee68da256b8a12f9f650" + | |
49 "59ccc85a2190ce1385152d62785e00cae702e77c4c597b86a6268adbf043" + | |
50 "dda68881c790f1517671fb7d198fca5ba97bef0203010001" | |
51 } | |
52 ]; | 29 ]; |
53 | 30 |
54 function runTest(algorithmName, extractable, keyUsages, keyData) | 31 function runTest(algorithmName, extractable, keyUsages, keyData) |
55 { | 32 { |
56 var importData = hexStringToUint8Array(keyData.spkiData); | 33 var importData = hexStringToUint8Array(keyData.spki); |
57 var importAlgorithm = { name: algorithmName }; | 34 var importAlgorithm = { name: algorithmName }; |
58 | 35 |
59 var results = {}; | 36 var results = {}; |
60 | 37 |
61 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta
ble, keyUsages).then(function(importedKey) { | 38 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta
ble, keyUsages).then(function(importedKey) { |
62 results.importedKey = importedKey; | 39 results.importedKey = importedKey; |
63 importedKey.extraProperty = 'hi'; | 40 importedKey.extraProperty = 'hi'; |
64 return cloneKey(importedKey); | 41 return cloneKey(importedKey); |
65 }).then(function(clonedKey) { | 42 }).then(function(clonedKey) { |
66 results.clonedKey = clonedKey; | 43 results.clonedKey = clonedKey; |
67 if (extractable) | 44 if (extractable) |
68 return crypto.subtle.exportKey('spki', clonedKey); | 45 return crypto.subtle.exportKey('spki', clonedKey); |
69 return null; | 46 return null; |
70 }).then(function(clonedKeyData) { | 47 }).then(function(clonedKeyData) { |
71 importedKey = results.importedKey; | 48 importedKey = results.importedKey; |
72 clonedKey = results.clonedKey; | 49 clonedKey = results.clonedKey; |
73 | 50 |
74 shouldEvaluateAs("importedKey.extraProperty", "hi"); | 51 shouldEvaluateAs("importedKey.extraProperty", "hi"); |
75 shouldEvaluateAs("importedKey.type", "public"); | 52 shouldEvaluateAs("importedKey.type", "public"); |
76 shouldEvaluateAs("importedKey.extractable", extractable); | 53 shouldEvaluateAs("importedKey.extractable", extractable); |
77 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); | 54 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); |
78 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modululu
sLengthBits); | 55 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL
engthBits); |
79 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat
a.publicExponent, importedKey.algorithm.publicExponent); | 56 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat
a.publicExponent, importedKey.algorithm.publicExponent); |
80 shouldBeUndefined("importedKey.algorithm.hash"); | 57 shouldBeUndefined("importedKey.algorithm.hash"); |
81 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); | 58 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); |
82 | 59 |
83 shouldBeTrue("importedKey != clonedKey"); | 60 shouldBeTrue("importedKey != clonedKey"); |
84 | 61 |
85 shouldBeUndefined("clonedKey.extraProperty"); | 62 shouldBeUndefined("clonedKey.extraProperty"); |
86 shouldEvaluateAs("clonedKey.type", "public"); | 63 shouldEvaluateAs("clonedKey.type", "public"); |
87 shouldEvaluateAs("clonedKey.extractable", extractable); | 64 shouldEvaluateAs("clonedKey.extractable", extractable); |
88 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); | 65 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); |
89 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modululusL
engthBits); | 66 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLen
gthBits); |
90 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData.
publicExponent, clonedKey.algorithm.publicExponent); | 67 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData.
publicExponent, clonedKey.algorithm.publicExponent); |
91 shouldBeUndefined("clonedKey.algorithm.hash"); | 68 shouldBeUndefined("clonedKey.algorithm.hash"); |
92 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); | 69 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); |
93 | 70 |
94 logSerializedKey(importedKey); | 71 logSerializedKey(importedKey); |
95 | 72 |
96 if (extractable) | 73 if (extractable) |
97 bytesShouldMatchHexString("Cloned key exported data", keyData.spkiDa
ta, clonedKeyData); | 74 bytesShouldMatchHexString("Cloned key exported data", keyData.spki,
clonedKeyData); |
98 | 75 |
99 debug(""); | 76 debug(""); |
100 }); | 77 }); |
101 } | 78 } |
102 | 79 |
103 var lastPromise = Promise.resolve(null); | 80 var lastPromise = Promise.resolve(null); |
104 | 81 |
105 kPossibleAlgorithms.forEach(function(algorithmName) { | 82 kPossibleAlgorithms.forEach(function(algorithmName) { |
106 kPossibleExtractable.forEach(function(extractable) { | 83 kPossibleExtractable.forEach(function(extractable) { |
107 kPossibleKeyUsages.forEach(function(keyUsages) { | 84 kPossibleKeyUsages.forEach(function(keyUsages) { |
108 kPossibleKeyData.forEach(function(keyData) { | 85 kPossibleKeyData.forEach(function(keyData) { |
109 lastPromise = lastPromise.then(runTest.bind(null, algorithmNam
e, extractable, keyUsages, keyData)); | 86 lastPromise = lastPromise.then(runTest.bind(null, algorithmNam
e, extractable, keyUsages, keyData)); |
110 }); | 87 }); |
111 }); | 88 }); |
112 }); | 89 }); |
113 }); | 90 }); |
114 | 91 |
115 lastPromise.then(finishJSTest, failAndFinishJSTest); | 92 lastPromise.then(finishJSTest, failAndFinishJSTest); |
116 | 93 |
117 </script> | 94 </script> |
118 | 95 |
119 </body> | 96 </body> |
120 </html> | 97 </html> |
OLD | NEW |