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-CTR"); | 12 description("Tests bad algorithm inputs for AES-CTR"); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); | 16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); |
17 var data = asciiToUint8Array("hello"); | 17 var data = asciiToUint8Array("hello"); |
18 var key = null; | 18 var key = null; |
19 | 19 |
20 Promise.resolve(null).then(function(result) { | 20 Promise.resolve(null).then(function(result) { |
21 var usages = ['encrypt', 'decrypt']; | 21 var usages = ['encrypt', 'decrypt']; |
22 var extractable = false; | 22 var extractable = false; |
23 // FIXME: Should use aes-ctr here. | 23 // FIXME: Should use aes-ctr here. |
24 var algorithm = {name: 'aes-cbc'}; | 24 var algorithm = {name: 'aes-cbc'}; |
25 | 25 |
| 26 debug("\nImporting AES-CBC key..."); |
26 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); | 27 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); |
27 }).then(function(result) { | 28 }).then(function(result) { |
28 key = result; | 29 key = result; |
29 | 30 |
| 31 debug("\nencrypt() with counter null..."); |
30 return crypto.subtle.encrypt({name: 'AES-CTR', counter: null}, key, data); | 32 return crypto.subtle.encrypt({name: 'AES-CTR', counter: null}, key, data); |
31 }).then(failAndFinishJSTest, function(result) { | 33 }).then(failAndFinishJSTest, function(result) { |
32 logError(result); | 34 logError(result); |
33 | 35 |
| 36 debug("\nencrypt() without counter..."); |
34 return crypto.subtle.encrypt({name: 'AES-CTR'}, key, data); | 37 return crypto.subtle.encrypt({name: 'AES-CTR'}, key, data); |
35 }).then(failAndFinishJSTest, function(result) { | 38 }).then(failAndFinishJSTest, function(result) { |
36 logError(result); | 39 logError(result); |
37 | 40 |
| 41 debug("\nencrypt() without length..."); |
38 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(0)},
key, data); | 42 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(0)},
key, data); |
39 }).then(failAndFinishJSTest, function(result) { | 43 }).then(failAndFinishJSTest, function(result) { |
40 logError(result); | 44 logError(result); |
41 | 45 |
| 46 debug("\nencrypt() with a length of 256..."); |
42 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: 256}, key, data); | 47 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: 256}, key, data); |
43 }).then(failAndFinishJSTest, function(result) { | 48 }).then(failAndFinishJSTest, function(result) { |
44 logError(result); | 49 logError(result); |
45 | 50 |
| 51 debug("\nencrypt() with a length of -3..."); |
46 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: -3}, key, data); | 52 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: -3}, key, data); |
47 }).then(failAndFinishJSTest, function(result) { | 53 }).then(failAndFinishJSTest, function(result) { |
48 logError(result); | 54 logError(result); |
49 | 55 |
| 56 debug("\nencrypt() with length that is Infinity..."); |
50 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: Infinity}, key, data); | 57 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: Infinity}, key, data); |
51 }).then(failAndFinishJSTest, function(result) { | 58 }).then(failAndFinishJSTest, function(result) { |
52 logError(result); | 59 logError(result); |
53 }).then(finishJSTest, failAndFinishJSTest); | 60 }).then(finishJSTest, failAndFinishJSTest); |
54 | 61 |
55 </script> | 62 </script> |
56 | 63 |
57 </body> | 64 </body> |
58 </html> | 65 </html> |
OLD | NEW |