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 <script src="resources/keys.js"></script> |
7 </head> | 7 </head> |
8 <body> | 8 <body> |
9 <p id="description"></p> | 9 <p id="description"></p> |
10 <div id="console"></div> | 10 <div id="console"></div> |
11 | 11 |
12 <script> | 12 <script> |
13 description("Tests cypto.subtle.sign and crypto.subtle.verify"); | 13 description("Tests cypto.subtle.sign and crypto.subtle.verify"); |
14 | 14 |
15 jsTestIsAsync = true; | 15 jsTestIsAsync = true; |
16 | 16 |
17 // A list of Promises for every test to run. | 17 var runTests; |
18 var allTests = []; | 18 var allTests = new Promise(function(resolve) { |
19 runTests = resolve; | |
20 }); | |
19 | 21 |
20 // ------------------------------------------------- | 22 // ------------------------------------------------- |
21 // Successful sign/verify for HMAC | 23 // Successful sign/verify for HMAC |
22 // ------------------------------------------------- | 24 // ------------------------------------------------- |
23 | 25 |
24 // The "key", "message", and "mac" are written as hex encoded strings. | 26 // The "key", "message", and "mac" are written as hex encoded strings. |
25 // | 27 // |
26 // Unless indicated otherwise, the data comes from: | 28 // Unless indicated otherwise, the data comes from: |
27 // http://csrc.nist.gov/groups/STM/cavp/index.html#07 | 29 // http://csrc.nist.gov/groups/STM/cavp/index.html#07 |
28 // Which can be downloaded from: | 30 // Which can be downloaded from: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // (4) Verify truncated mac (by stripping 1 byte off of it). | 114 // (4) Verify truncated mac (by stripping 1 byte off of it). |
113 var expectedMac = hexStringToUint8Array(testCase.mac); | 115 var expectedMac = hexStringToUint8Array(testCase.mac); |
114 return crypto.subtle.verify(algorithm, key, expectedMac.subarray(0, expe ctedMac.byteLength - 1), hexStringToUint8Array(testCase.message)); | 116 return crypto.subtle.verify(algorithm, key, expectedMac.subarray(0, expe ctedMac.byteLength - 1), hexStringToUint8Array(testCase.message)); |
115 }).then(function(result) { | 117 }).then(function(result) { |
116 verifyResult = result; | 118 verifyResult = result; |
117 shouldBe("verifyResult", "false") | 119 shouldBe("verifyResult", "false") |
118 }); | 120 }); |
119 } | 121 } |
120 | 122 |
121 // Add all of the tests defined above. | 123 // Add all of the tests defined above. |
122 for (var i = 0; i < kHmacTestVectors.length; ++i) { | 124 kHmacTestVectors.forEach(function(data) { |
123 allTests.push(runSuccessTestCase(kHmacTestVectors[i])); | 125 allTests = allTests.then(function() { |
124 } | 126 return runSuccessTestCase(data); |
127 }); | |
128 }); | |
125 | 129 |
126 hmac = {name: 'hmac'}; | 130 hmac = {name: 'hmac'}; |
127 data = asciiToUint8Array("hello"); | 131 data = asciiToUint8Array("hello"); |
128 | 132 |
129 allTests.push(importTestKeys().then(function(importedKeys) { | 133 allTests = allTests.then(function() { |
eroman
2014/03/26 09:07:58
In fact I have a similar changelist pending which
| |
134 return importTestKeys(); | |
135 }).then(function(importedKeys) { | |
130 keys = importedKeys; | 136 keys = importedKeys; |
131 | 137 |
132 // Pass invalid signature parameters to verify() | 138 // Pass invalid signature parameters to verify() |
133 shouldThrow("crypto.subtle.verify(hmac, keys.hmacSha1, null, data)"); | 139 shouldThrow("crypto.subtle.verify(hmac, keys.hmacSha1, null, data)"); |
134 shouldThrow("crypto.subtle.verify(hmac, keys.hmacSha1, 'a', data)"); | 140 shouldThrow("crypto.subtle.verify(hmac, keys.hmacSha1, 'a', data)"); |
135 shouldThrow("crypto.subtle.verify(hmac, keys.hmacSha1, [], data)"); | 141 shouldThrow("crypto.subtle.verify(hmac, keys.hmacSha1, [], data)"); |
136 | 142 |
137 // Operation does not support signing. | 143 // Operation does not support signing. |
138 shouldRejectPromiseWithNull("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSh a1, data)"); | 144 shouldRejectPromiseWithNull("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSh a1, data)"); |
139 | 145 |
140 // Operation doesn't support signing (also given an invalid key, but the | 146 // Operation doesn't support signing (also given an invalid key, but the |
141 // first failure takes priority) | 147 // first failure takes priority) |
142 shouldRejectPromiseWithNull("crypto.subtle.sign({name: 'RSAES-PKCS1-v1_5'}, keys.hmacSha1, data)"); | 148 shouldRejectPromiseWithNull("crypto.subtle.sign({name: 'RSAES-PKCS1-v1_5'}, keys.hmacSha1, data)"); |
143 })); | 149 }); |
144 | 150 |
145 // ------------------------------------------------- | 151 // ------------------------------------------------- |
146 // Wait until all the tests have been run. | 152 // Wait until all the tests have been run. |
147 // ------------------------------------------------- | 153 // ------------------------------------------------- |
148 | 154 allTests = allTests.then(finishJSTest, failAndFinishJSTest); |
149 Promise.all(allTests).then(finishJSTest, failAndFinishJSTest); | 155 runTests(); |
150 | 156 |
151 </script> | 157 </script> |
152 | 158 |
153 </body> | 159 </body> |
OLD | NEW |