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