OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../resources/js-test.js"></script> | |
5 <script src="resources/common.js"></script> | |
6 </head> | |
7 <body> | |
8 <p id="description"></p> | |
9 <div id="console"></div> | |
10 | |
11 <script> | |
12 description("Tests calls to unwrapKey() with bad inputs."); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 function importUnwrappingKey() | |
17 { | |
18 var data = new Uint8Array(16); | |
19 var extractable = true; | |
20 var keyUsages = ['unwrapKey']; | |
21 | |
22 return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable,
keyUsages); | |
23 } | |
24 | |
25 importUnwrappingKey().then(function(result) { | |
26 wrappedKey = new Uint8Array(100); | |
27 unwrappingKey = result; | |
28 unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; | |
29 unwrappedKeyAlgorithm = unwrapAlgorithm; | |
30 extractable = true; | |
31 keyUsages = ['encrypt']; | |
32 | |
33 // Invalid wrappedKey | |
34 return crypto.subtle.unwrapKey('raw', null, unwrappingKey, unwrapAlgorithm,
unwrappedKeyAlgorithm, extractable, keyUsages); | |
35 }).then(failAndFinishJSTest, function(result) { | |
36 logError(result); | |
37 | |
38 // Invalid unwrappingKey | |
39 return crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorithm, unw
rappedKeyAlgorithm, extractable, keyUsages); | |
40 }).then(failAndFinishJSTest, function(result) { | |
41 logError(result); | |
42 | |
43 // Invalid keyUsages (also, unwrappedKeyAlgorithm is set to null). | |
44 return crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorithm, nul
l, extractable, 9); | |
45 }).then(failAndFinishJSTest, function(result) { | |
46 logError(result); | |
47 | |
48 // Invalid unwrapAlgorithm | |
49 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, null, unwra
ppedKeyAlgorithm, extractable, keyUsages); | |
50 }).then(failAndFinishJSTest, function(result) { | |
51 logError(result); | |
52 | |
53 // Invalid unwrappedKeyAlgorithm (specified but bad). | |
54 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwrapAlgor
ithm, 3, extractable, keyUsages); | |
55 }).then(failAndFinishJSTest, function(result) { | |
56 logError(result); | |
57 | |
58 // Invalid format | |
59 return crypto.subtle.unwrapKey('bad-format', wrappedKey, unwrappingKey, unwr
apAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages); | |
60 }).then(failAndFinishJSTest, function(result) { | |
61 logError(result); | |
62 | |
63 // SHA-1 isn't a valid unwrapKey algorithm. | |
64 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, {name: 'SHA
-1'}, unwrappedKeyAlgorithm, extractable, keyUsages); | |
65 }).then(failAndFinishJSTest, function(result) { | |
66 logError(result); | |
67 | |
68 // Mismatch between the unwrappingKey's algorithm and unwrapAlgorithm. | |
69 aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0}; | |
70 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, aesCtrAlgor
ithm, unwrappedKeyAlgorithm, extractable, keyUsages); | |
71 }).then(failAndFinishJSTest, function(result) { | |
72 logError(result); | |
73 }).then(finishJSTest, failAndFinishJSTest); | |
74 | |
75 </script> | |
76 | |
77 </body> | |
78 </html> | |
OLD | NEW |