OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../fast/js/resources/js-test-pre.js"></script> | 4 <script src="../fast/js/resources/js-test-pre.js"></script> |
5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <p id="description"></p> | 8 <p id="description"></p> |
9 <div id="console"></div> | 9 <div id="console"></div> |
10 | 10 |
11 <script> | 11 <script> |
12 description("Tests cypto.subtle.sign and crypto.subtle.verify"); | 12 description("Tests cypto.subtle.sign and crypto.subtle.verify"); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}}; | 16 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}}; |
17 data = asciiToArrayBuffer("hello"); | 17 data = asciiToArrayBuffer("hello"); |
18 | 18 |
19 importTestKeys().then(function(importedKeys) { | 19 importTestKeys().then(function(importedKeys) { |
20 keys = importedKeys; | 20 keys = importedKeys; |
21 | 21 |
22 // Pass invalid signature parameters to verify() | 22 // Pass invalid signature parameters to verify() |
23 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)"); | 23 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)"); |
24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)"); | 24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)"); |
25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)"); | 25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)"); |
26 | 26 |
27 // Operation does not support signing. | 27 // Operation does not support signing. |
28 shouldThrow("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSha1, data)"); | 28 shouldThrow("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSha1, data)"); |
29 | 29 |
| 30 // Operation doesn't support signing (also given an invalid key, but the |
| 31 // first failure takes priority) |
| 32 shouldThrow("crypto.subtle.sign({name: 'RSAES-PKCS1-v1_5'}, keys.hmacSha1, d
ata)"); |
| 33 |
30 // Key's algorithm must match. | 34 // Key's algorithm must match. |
31 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, key
s.hmacSha1, data)"); | 35 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, key
s.hmacSha1, data)"); |
32 | 36 |
33 // --------------------------------------------------- | 37 // --------------------------------------------------- |
34 // HMAC normalization failures (HmacParams) | 38 // HMAC normalization failures (HmacParams) |
35 // --------------------------------------------------- | 39 // --------------------------------------------------- |
36 shouldThrow("crypto.subtle.sign({name: 'hmac'}, keys.hmacSha1, data)"); | 40 shouldThrow("crypto.subtle.sign({name: 'hmac'}, keys.hmacSha1, data)"); |
37 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: 3}, keys.hmacSha1, data
)"); | 41 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: 3}, keys.hmacSha1, data
)"); |
38 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: null}, keys.hmacSha1, d
ata)"); | 42 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: null}, keys.hmacSha1, d
ata)"); |
39 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {}}, keys.hmacSha1, dat
a)"); | 43 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {}}, keys.hmacSha1, dat
a)"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, gen
eratedHmacSha1Key, data)"); | 78 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, gen
eratedHmacSha1Key, data)"); |
75 | 79 |
76 // However it can be used to sign for HMAC SHA-1 | 80 // However it can be used to sign for HMAC SHA-1 |
77 shouldNotThrow("crypto.subtle.sign(hmacSha1, generatedHmacSha1Key, data)"); | 81 shouldNotThrow("crypto.subtle.sign(hmacSha1, generatedHmacSha1Key, data)"); |
78 }).then(finishJSTest, failAndFinishJSTest); | 82 }).then(finishJSTest, failAndFinishJSTest); |
79 | 83 |
80 </script> | 84 </script> |
81 | 85 |
82 <script src="../fast/js/resources/js-test-post.js"></script> | 86 <script src="../fast/js/resources/js-test-post.js"></script> |
83 </body> | 87 </body> |
OLD | NEW |