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("Call encrypt using the wrong AES key"); | 12 description("Tests that unwrapping keys must have the 'unwrapKey' usage."); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); | 16 function importUnwrappingKey() |
17 var data = asciiToUint8Array("hello"); | 17 { |
18 var aesCbcKey = null; | 18 var data = new Uint8Array(16); |
| 19 var extractable = true; |
| 20 var keyUsages = ['decrypt']; |
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 var algorithm = {name: 'aes-gcm'}; | |
24 | 24 |
25 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); | 25 importUnwrappingKey().then(function(result) { |
26 }).then(function(result) { | 26 wrappedKey = new Uint8Array(100); |
27 key = result; | 27 unwrappingKey = result; |
28 shouldEvaluateAs("key.algorithm.name", "AES-GCM"); | 28 unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; |
| 29 unwrappedKeyAlgorithm = unwrapAlgorithm; |
| 30 extractable = true; |
| 31 keyUsages = ['encrypt']; |
29 | 32 |
30 // Can't use an AES-KW key for AES-CBC (even though both are AES keys). | 33 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwrapAlgor
ithm, unwrappedKeyAlgorithm, extractable, keyUsages); |
31 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(16)}, key,
data); | |
32 }).then(failAndFinishJSTest, function(result) { | 34 }).then(failAndFinishJSTest, function(result) { |
33 error = result; | 35 error = result; |
34 shouldBeNull("error"); | 36 shouldBeNull("error"); |
35 }).then(finishJSTest, failAndFinishJSTest); | 37 }).then(finishJSTest, failAndFinishJSTest); |
36 | 38 |
37 </script> | 39 </script> |
38 | 40 |
39 </body> | 41 </body> |
40 </html> | 42 </html> |
OLD | NEW |