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 <script src="resources/keys.js"></script> | |
7 </head> | |
8 <body> | |
9 <p id="description"></p> | |
10 <div id="console"></div> | |
11 | |
12 <script> | |
13 description("Tests cypto.subtle.sign and crypto.subtle.verify"); | |
14 | |
15 // FIXME: This is only testing invalid parameters right now. Once the | |
16 // chromium-side implements the algorithms more interesting tests should be | |
17 // added. | |
18 | |
19 jsTestIsAsync = true; | |
20 | |
21 importTestKeys().then(function(result) { | |
22 keys = result; | |
23 key = keys.hmacSha1; | |
24 wrappingKey = keys.aesCbc; | |
25 | |
26 wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; | |
27 | |
28 // -------------------------------- | |
29 // wrapKey invalid parameters | |
30 // -------------------------------- | |
31 | |
32 // Invalid format. | |
33 shouldRejectPromiseWithNull("crypto.subtle.wrapKey('bad-format', key, wrappi
ngKey, wrapAlgorithm)"); | |
34 | |
35 // Invalid key | |
36 shouldThrow("crypto.subtle.wrapKey('raw', 1, wrappingKey, wrapAlgorithm)"); | |
37 | |
38 // Invalid wrappingKey | |
39 shouldThrow("crypto.subtle.wrapKey('raw', key, '', wrapAlgorithm)"); | |
40 | |
41 // Invalid wrapAlgorithm | |
42 shouldThrow("crypto.subtle.wrapKey('raw', key, wrappingKey, undefined)"); | |
43 | |
44 // Key is not extractable. | |
45 shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', keys.aesCbcJustDec
rypt, wrappingKey, wrapAlgorithm)"); | |
46 | |
47 // wrappingKey's usage does not include wrapKey. | |
48 shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', key, keys.aesCbcJu
stDecrypt, wrapAlgorithm)"); | |
49 | |
50 // SHA-1 isn't a valid wrapKey algorithm. | |
51 shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', key, wrappingKey,
{name: 'SHA-1'})"); | |
52 | |
53 // Wrap algorithm doesn't match the wrapping key's algorithm (AES-CBC key | |
54 // with AES-CTR wrap algorithm) | |
55 aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0}; | |
56 shouldRejectPromiseWithNull("crypto.subtle.wrapKey('raw', key, wrappingKey,
aesCtrAlgorithm)"); | |
57 | |
58 // -------------------------------- | |
59 // unwrapKey invalid parameters | |
60 // -------------------------------- | |
61 | |
62 wrappedKey = new Uint8Array(100); | |
63 unwrappingKey = keys.aesCbc; | |
64 unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; | |
65 unwrappedKeyAlgorithm = unwrapAlgorithm; | |
66 extractable = true; | |
67 keyUsages = ['encrypt']; | |
68 | |
69 // Invalid format | |
70 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('bad-format', wrappedKe
y, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages
)"); | |
71 | |
72 // Invalid wrappedKey | |
73 shouldThrow("crypto.subtle.unwrapKey('raw', null, unwrappingKey, unwrapAlgor
ithm, unwrappedKeyAlgorithm, extractable, keyUsages)"); | |
74 | |
75 // Invalid unwrappingKey | |
76 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorith
m, unwrappedKeyAlgorithm, extractable, keyUsages)"); | |
77 | |
78 // unwrappingKey does not include unwrapKey usage. | |
79 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, keys
.aesCbcJustDecrypt, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsag
es)"); | |
80 | |
81 // Invalid keyUsages (also, unwrappedKeyAlgorithm is set to null). | |
82 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorith
m, null, extractable, 9)"); | |
83 | |
84 // Invalid unwrapAlgorithm | |
85 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, null,
unwrappedKeyAlgorithm, extractable, keyUsages)"); | |
86 | |
87 // Invalid unwrappedKeyAlgorithm (specified but bad). | |
88 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwra
pAlgorithm, 3, extractable, keyUsages)"); | |
89 | |
90 // SHA-1 isn't a valid unwrapKey algorithm. | |
91 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwr
appingKey, {name: 'SHA-1'}, unwrappedKeyAlgorithm, extractable, keyUsages)"); | |
92 | |
93 // Mismatch between the unwrappingKey's algorithm and unwrapAlgorithm. | |
94 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwr
appingKey, aesCtrAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)"); | |
95 | |
96 }).then(finishJSTest, failAndFinishJSTest); | |
97 | |
98 | |
99 </script> | |
100 | |
101 </body> | |
OLD | NEW |