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 </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 bad algorithm inputs for AES-CBC"); | 12 description("Tests generateKey() with bad AES-CBC parameters."); |
13 | |
14 jsTestIsAsync = true; | 13 jsTestIsAsync = true; |
15 | 14 |
16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); | 15 extractable = true; |
17 var data = asciiToUint8Array("hello"); | 16 keyUsages = ['encrypt', 'decrypt']; |
18 var key = null; | |
19 | 17 |
20 Promise.resolve(null).then(function(result) { | 18 // Invalid keyUsages |
21 var usages = ['encrypt', 'decrypt']; | 19 shouldThrow("crypto.subtle.generateKey({ name: 'aes-cbc', length: 1024 }, extrac
table, -1)"); |
22 var extractable = false; | 20 shouldThrow("crypto.subtle.generateKey({ name: 'aes-cbc', length: 1024 }, extrac
table, null)"); |
23 var algorithm = {name: 'aes-cbc'}; | |
24 | 21 |
25 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); | 22 Promise.resolve(null).then(function() { |
26 }).then(function(result) { | 23 // Bad key usage "boo". |
27 key = result; | 24 return crypto.subtle.generateKey({ name: 'aes-cbc', length: 1024 }, extracta
ble, ['boo']); |
28 | |
29 // Bad iv | |
30 return crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, data); | |
31 }).then(failAndFinishJSTest, function(result) { | 25 }).then(failAndFinishJSTest, function(result) { |
32 error = result; | 26 error = result; |
33 shouldBeNull("error"); | 27 shouldBeNull("error"); |
34 | 28 |
35 // Missing iv | 29 return crypto.subtle.generateKey({ name: 'aes-cbc' }, extractable, keyUsages
); |
36 return crypto.subtle.decrypt({name: 'AES-CBC'}, key, data); | |
37 }).then(failAndFinishJSTest, function(result) { | 30 }).then(failAndFinishJSTest, function(result) { |
38 error = result; | 31 error = result; |
39 shouldBeNull("error"); | 32 shouldBeNull("error"); |
40 | 33 |
41 // iv is not a buffer | 34 return crypto.subtle.generateKey({ name: 'aes-cbc', length: 70000 }, extract
able, keyUsages); |
42 return crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, data); | |
43 }).then(failAndFinishJSTest, function(result) { | 35 }).then(failAndFinishJSTest, function(result) { |
44 error = result; | 36 error = result; |
45 shouldBeNull("error"); | 37 shouldBeNull("error"); |
46 | 38 |
47 // iv is too short | 39 return crypto.subtle.generateKey({ name: 'aes-cbc', length: -3 }, extractabl
e, keyUsages); |
48 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(0)}, key,
data); | |
49 }).then(failAndFinishJSTest, function(result) { | 40 }).then(failAndFinishJSTest, function(result) { |
50 error = result; | 41 error = result; |
51 shouldBeNull("error"); | 42 shouldBeNull("error"); |
| 43 |
| 44 return crypto.subtle.generateKey({ name: 'aes-cbc', length: -Infinity }, ext
ractable, keyUsages); |
| 45 }).then(failAndFinishJSTest, function(result) { |
| 46 error = result; |
| 47 shouldBeNull("error"); |
52 }).then(finishJSTest, failAndFinishJSTest); | 48 }).then(finishJSTest, failAndFinishJSTest); |
53 | 49 |
54 </script> | 50 </script> |
55 | 51 |
56 </body> | 52 </body> |
57 </html> | 53 </html> |
OLD | NEW |