4 <script src=
"../../resources/js-test.js"></script>
5 <script src=
"resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Tests calls to unwrapKey() with bad inputs.");
16 function importUnwrappingKey()
18 var data
= new Uint8Array(16);
19 var extractable
= true;
20 var keyUsages
= ['unwrapKey'];
22 return crypto
.subtle
.importKey('raw', data
, {name
: 'AES-CBC'}, extractable
, keyUsages
);
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
;
31 keyUsages
= ['encrypt'];
34 return crypto
.subtle
.unwrapKey('raw', null, unwrappingKey
, unwrapAlgorithm
, unwrappedKeyAlgorithm
, extractable
, keyUsages
);
35 }).then(failAndFinishJSTest
, function(result
) {
38 // Invalid unwrappingKey
39 return crypto
.subtle
.unwrapKey('raw', wrappedKey
, 'hi', unwrapAlgorithm
, unwrappedKeyAlgorithm
, extractable
, keyUsages
);
40 }).then(failAndFinishJSTest
, function(result
) {
43 // Invalid keyUsages (also, unwrappedKeyAlgorithm is set to null).
44 return crypto
.subtle
.unwrapKey('raw', wrappedKey
, unwrappingKey
, unwrapAlgorithm
, null, extractable
, 9);
45 }).then(failAndFinishJSTest
, function(result
) {
48 // Invalid unwrapAlgorithm
49 return crypto
.subtle
.unwrapKey('raw', wrappedKey
, unwrappingKey
, null, unwrappedKeyAlgorithm
, extractable
, keyUsages
);
50 }).then(failAndFinishJSTest
, function(result
) {
53 // Invalid unwrappedKeyAlgorithm (specified but bad).
54 return crypto
.subtle
.unwrapKey('raw', wrappedKey
, unwrappingKey
, unwrapAlgorithm
, 3, extractable
, keyUsages
);
55 }).then(failAndFinishJSTest
, function(result
) {
59 return crypto
.subtle
.unwrapKey('bad-format', wrappedKey
, unwrappingKey
, unwrapAlgorithm
, unwrappedKeyAlgorithm
, extractable
, keyUsages
);
60 }).then(failAndFinishJSTest
, function(result
) {
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
) {
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
, aesCtrAlgorithm
, unwrappedKeyAlgorithm
, extractable
, keyUsages
);
71 }).then(failAndFinishJSTest
, function(result
) {
73 }).then(finishJSTest
, failAndFinishJSTest
);