| 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 calls to wrapKey() with bad inputs."); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); | 16 function importWrappingKey() |
| 17 var data = asciiToUint8Array("hello"); | 17 { |
| 18 var key = null; | 18 var data = new Uint8Array(16); |
| 19 var extractable = true; |
| 20 var keyUsages = ['wrapKey']; |
| 19 | 21 |
| 20 Promise.resolve(null).then(function(result) { | 22 return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable,
keyUsages); |
| 21 var usages = ['encrypt', 'decrypt']; | 23 } |
| 22 var extractable = false; | |
| 23 // FIXME: Should use aes-ctr here. | |
| 24 var algorithm = {name: 'aes-cbc'}; | |
| 25 | 24 |
| 26 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); | 25 function importKeyToWrap() |
| 26 { |
| 27 var data = new Uint8Array(16); |
| 28 var extractable = true; |
| 29 var keyUsages = ['sign']; |
| 30 |
| 31 return crypto.subtle.importKey('raw', data, {name: 'HMAC', hash: {name: 'SHA
-1'}}, extractable, keyUsages); |
| 32 } |
| 33 |
| 34 importWrappingKey().then(function(result) { |
| 35 wrappingKey = result; |
| 36 return importKeyToWrap(); |
| 27 }).then(function(result) { | 37 }).then(function(result) { |
| 28 key = result; | 38 key = result; |
| 29 | 39 |
| 30 return crypto.subtle.encrypt({name: 'AES-CTR', counter: null}, key, data); | 40 wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; |
| 41 |
| 42 // Invalid key |
| 43 shouldThrow("crypto.subtle.wrapKey('raw', 1, wrappingKey, wrapAlgorithm)"); |
| 44 |
| 45 // Invalid wrappingKey |
| 46 shouldThrow("crypto.subtle.wrapKey('raw', key, '', wrapAlgorithm)"); |
| 47 |
| 48 // Invalid wrapAlgorithm |
| 49 shouldThrow("crypto.subtle.wrapKey('raw', key, wrappingKey, undefined)"); |
| 50 |
| 51 // Invalid format for wrapKey |
| 52 return crypto.subtle.wrapKey('bad-format', key, wrappingKey, wrapAlgorithm); |
| 31 }).then(failAndFinishJSTest, function(result) { | 53 }).then(failAndFinishJSTest, function(result) { |
| 32 error = result; | 54 error = result; |
| 33 shouldBeNull("error"); | 55 shouldBeNull("error"); |
| 34 | 56 |
| 35 return crypto.subtle.encrypt({name: 'AES-CTR'}, key, data); | 57 // SHA-1 isn't a valid wrapKey algorithm. |
| 58 return crypto.subtle.wrapKey('raw', key, wrappingKey, {name: 'SHA-1'}); |
| 36 }).then(failAndFinishJSTest, function(result) { | 59 }).then(failAndFinishJSTest, function(result) { |
| 37 error = result; | 60 error = result; |
| 38 shouldBeNull("error"); | 61 shouldBeNull("error"); |
| 39 | 62 |
| 40 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(0)},
key, data); | 63 // Wrap algorithm doesn't match the wrapping key's algorithm (AES-CBC key |
| 64 // with AES-CTR wrap algorithm) |
| 65 aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0}; |
| 66 return crypto.subtle.wrapKey('raw', key, wrappingKey, aesCtrAlgorithm); |
| 41 }).then(failAndFinishJSTest, function(result) { | 67 }).then(failAndFinishJSTest, function(result) { |
| 42 error = result; | 68 error = result; |
| 43 shouldBeNull("error"); | 69 shouldBeNull("error"); |
| 44 | |
| 45 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: 256}, key, data); | |
| 46 }).then(failAndFinishJSTest, function(result) { | |
| 47 error = result; | |
| 48 shouldBeNull("error"); | |
| 49 | |
| 50 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: -3}, key, data); | |
| 51 }).then(failAndFinishJSTest, function(result) { | |
| 52 error = result; | |
| 53 shouldBeNull("error"); | |
| 54 | |
| 55 return crypto.subtle.encrypt({name: 'AES-CTR', counter: new Uint8Array(16),
length: Infinity}, key, data); | |
| 56 }).then(failAndFinishJSTest, function(result) { | |
| 57 error = result; | |
| 58 shouldBeNull("error"); | |
| 59 }).then(finishJSTest, failAndFinishJSTest); | 70 }).then(finishJSTest, failAndFinishJSTest); |
| 60 | 71 |
| 61 </script> | 72 </script> |
| 62 | 73 |
| 63 </body> | 74 </body> |
| 64 </html> | 75 </html> |
| OLD | NEW |