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 bad algorithm inputs for AES-CBC"); |
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 var algorithm = {name: 'aes-cbc'}; | 23 var algorithm = {name: 'aes-cbc'}; |
24 | 24 |
25 debug('\nImporting AES-CBC key...'); | |
25 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage s); | 26 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage s); |
26 }).then(function(result) { | 27 }).then(function(result) { |
27 key = result; | 28 key = result; |
28 | 29 |
29 // Bad iv | 30 // Bad iv |
31 debug('\nencrypt() with iv that is null...'); | |
30 return crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, data); | 32 return crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, data); |
31 }).then(failAndFinishJSTest, function(result) { | 33 }).then(failAndFinishJSTest, function(result) { |
32 logError(result); | 34 logError(result); |
33 | 35 |
34 // Missing iv | 36 // Missing iv |
37 debug('\nencrypt() without iv...'); | |
35 return crypto.subtle.decrypt({name: 'AES-CBC'}, key, data); | 38 return crypto.subtle.decrypt({name: 'AES-CBC'}, key, data); |
36 }).then(failAndFinishJSTest, function(result) { | 39 }).then(failAndFinishJSTest, function(result) { |
37 logError(result); | 40 logError(result); |
38 | 41 |
39 // iv is not a buffer | 42 // iv is not a buffer |
43 debug('\nencrypt() with iv that is a number...'); | |
40 return crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, data); | 44 return crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, data); |
41 }).then(failAndFinishJSTest, function(result) { | 45 }).then(failAndFinishJSTest, function(result) { |
42 logError(result); | 46 logError(result); |
43 | 47 |
44 // iv is too short | 48 // iv is too short |
49 debug('\nencrypt() with iv that is of 0 byte...'); | |
eroman
2014/12/12 19:37:01
"encrypt() with an iv that is empty"
or
"encrypt()
jww
2014/12/12 19:55:24
nit: "0 byte" -> "0 bytes"
Paritosh Kumar
2014/12/15 08:21:26
Done.
Paritosh Kumar
2014/12/15 08:21:26
Done.
| |
45 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(0)}, key, data); | 50 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(0)}, key, data); |
46 }).then(failAndFinishJSTest, function(result) { | 51 }).then(failAndFinishJSTest, function(result) { |
47 logError(result); | 52 logError(result); |
48 | 53 |
49 // iv is longer than expected | 54 // iv is longer than expected |
55 debug('\nencrypt() with iv that is of 17 byte...'); | |
eroman
2014/12/12 19:37:01
encrypt() with an iv containing 17 bytes
jww
2014/12/12 19:55:24
nit: "17 byte" -> "17 bytes"
Paritosh Kumar
2014/12/15 08:21:26
Done.
Paritosh Kumar
2014/12/15 08:21:26
Done.
| |
50 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new ArrayBuffer(17)}, key , data); | 56 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new ArrayBuffer(17)}, key , data); |
51 }).then(failAndFinishJSTest, function(result) { | 57 }).then(failAndFinishJSTest, function(result) { |
52 logError(result); | 58 logError(result); |
53 }).then(finishJSTest, failAndFinishJSTest); | 59 }).then(finishJSTest, failAndFinishJSTest); |
54 | 60 |
55 </script> | 61 </script> |
56 | 62 |
57 </body> | 63 </body> |
58 </html> | 64 </html> |
OLD | NEW |