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 debug('\nencrypt() with iv that is null...'); |
30 return crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, data); | 31 return crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, data); |
31 }).then(failAndFinishJSTest, function(result) { | 32 }).then(failAndFinishJSTest, function(result) { |
32 logError(result); | 33 logError(result); |
33 | 34 |
34 // Missing iv | 35 debug('\nencrypt() without iv...'); |
35 return crypto.subtle.decrypt({name: 'AES-CBC'}, key, data); | 36 return crypto.subtle.decrypt({name: 'AES-CBC'}, key, data); |
36 }).then(failAndFinishJSTest, function(result) { | 37 }).then(failAndFinishJSTest, function(result) { |
37 logError(result); | 38 logError(result); |
38 | 39 |
39 // iv is not a buffer | 40 debug('\nencrypt() with iv that is a number...'); |
40 return crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, data); | 41 return crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, data); |
41 }).then(failAndFinishJSTest, function(result) { | 42 }).then(failAndFinishJSTest, function(result) { |
42 logError(result); | 43 logError(result); |
43 | 44 |
44 // iv is too short | 45 debug('\nencrypt() with an iv containing 0 bytes...'); |
45 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(0)}, key,
data); | 46 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(0)}, key,
data); |
46 }).then(failAndFinishJSTest, function(result) { | 47 }).then(failAndFinishJSTest, function(result) { |
47 logError(result); | 48 logError(result); |
48 | 49 |
49 // iv is longer than expected | 50 debug('\nencrypt() with an iv containing 17 bytes...'); |
50 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new ArrayBuffer(17)}, key
, data); | 51 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new ArrayBuffer(17)}, key
, data); |
51 }).then(failAndFinishJSTest, function(result) { | 52 }).then(failAndFinishJSTest, function(result) { |
52 logError(result); | 53 logError(result); |
53 }).then(finishJSTest, failAndFinishJSTest); | 54 }).then(finishJSTest, failAndFinishJSTest); |
54 | 55 |
55 </script> | 56 </script> |
56 | 57 |
57 </body> | 58 </body> |
58 </html> | 59 </html> |
OLD | NEW |