| 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 <script src="resources/keys.js"></script> | |
| 7 </head> | 6 </head> |
| 8 <body> | 7 <body> |
| 9 <p id="description"></p> | 8 <p id="description"></p> |
| 10 <div id="console"></div> | 9 <div id="console"></div> |
| 11 | 10 |
| 12 <script> | 11 <script> |
| 13 description("Tests cypto.subtle.sign and crypto.subtle.verify"); | 12 description("Tests calls to unwrapKey() with bad inputs."); |
| 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 | 13 |
| 19 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 20 | 15 |
| 21 importTestKeys().then(function(result) { | 16 function importUnwrappingKey() |
| 22 keys = result; | 17 { |
| 23 key = keys.hmacSha1; | 18 var data = new Uint8Array(16); |
| 24 wrappingKey = keys.aesCbc; | 19 var extractable = true; |
| 20 var keyUsages = ['unwrapKey']; |
| 25 | 21 |
| 26 wrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; | 22 return crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable,
keyUsages); |
| 23 } |
| 27 | 24 |
| 28 // -------------------------------- | 25 importUnwrappingKey().then(function(result) { |
| 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); | 26 wrappedKey = new Uint8Array(100); |
| 63 unwrappingKey = keys.aesCbc; | 27 unwrappingKey = result; |
| 64 unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; | 28 unwrapAlgorithm = {name: 'aes-cbc', iv: new Uint8Array(16)}; |
| 65 unwrappedKeyAlgorithm = unwrapAlgorithm; | 29 unwrappedKeyAlgorithm = unwrapAlgorithm; |
| 66 extractable = true; | 30 extractable = true; |
| 67 keyUsages = ['encrypt']; | 31 keyUsages = ['encrypt']; |
| 68 | 32 |
| 69 // Invalid format | |
| 70 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('bad-format', wrappedKe
y, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages
)"); | |
| 71 | |
| 72 // Invalid wrappedKey | 33 // Invalid wrappedKey |
| 73 shouldThrow("crypto.subtle.unwrapKey('raw', null, unwrappingKey, unwrapAlgor
ithm, unwrappedKeyAlgorithm, extractable, keyUsages)"); | 34 shouldThrow("crypto.subtle.unwrapKey('raw', null, unwrappingKey, unwrapAlgor
ithm, unwrappedKeyAlgorithm, extractable, keyUsages)"); |
| 74 | 35 |
| 75 // Invalid unwrappingKey | 36 // Invalid unwrappingKey |
| 76 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorith
m, unwrappedKeyAlgorithm, extractable, keyUsages)"); | 37 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorith
m, unwrappedKeyAlgorithm, extractable, keyUsages)"); |
| 77 | 38 |
| 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). | 39 // Invalid keyUsages (also, unwrappedKeyAlgorithm is set to null). |
| 82 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorith
m, null, extractable, 9)"); | 40 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, 'hi', unwrapAlgorith
m, null, extractable, 9)"); |
| 83 | 41 |
| 84 // Invalid unwrapAlgorithm | 42 // Invalid unwrapAlgorithm |
| 85 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, null,
unwrappedKeyAlgorithm, extractable, keyUsages)"); | 43 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, null,
unwrappedKeyAlgorithm, extractable, keyUsages)"); |
| 86 | 44 |
| 87 // Invalid unwrappedKeyAlgorithm (specified but bad). | 45 // Invalid unwrappedKeyAlgorithm (specified but bad). |
| 88 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwra
pAlgorithm, 3, extractable, keyUsages)"); | 46 shouldThrow("crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, unwra
pAlgorithm, 3, extractable, keyUsages)"); |
| 89 | 47 |
| 48 // Invalid format |
| 49 return crypto.subtle.unwrapKey('bad-format', wrappedKey, unwrappingKey, unwr
apAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages); |
| 50 }).then(failAndFinishJSTest, function(result) { |
| 51 error = result; |
| 52 shouldBeNull("error"); |
| 53 |
| 90 // SHA-1 isn't a valid unwrapKey algorithm. | 54 // SHA-1 isn't a valid unwrapKey algorithm. |
| 91 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwr
appingKey, {name: 'SHA-1'}, unwrappedKeyAlgorithm, extractable, keyUsages)"); | 55 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, {name: 'SHA
-1'}, unwrappedKeyAlgorithm, extractable, keyUsages); |
| 56 }).then(failAndFinishJSTest, function(result) { |
| 57 error = result; |
| 58 shouldBeNull("error"); |
| 92 | 59 |
| 93 // Mismatch between the unwrappingKey's algorithm and unwrapAlgorithm. | 60 // Mismatch between the unwrappingKey's algorithm and unwrapAlgorithm. |
| 94 shouldRejectPromiseWithNull("crypto.subtle.unwrapKey('raw', wrappedKey, unwr
appingKey, aesCtrAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages)"); | 61 aesCtrAlgorithm = {name: 'AES-CTR', counter: new Uint8Array(16), length: 0}; |
| 95 | 62 return crypto.subtle.unwrapKey('raw', wrappedKey, unwrappingKey, aesCtrAlgor
ithm, unwrappedKeyAlgorithm, extractable, keyUsages); |
| 63 }).then(failAndFinishJSTest, function(result) { |
| 64 error = result; |
| 65 shouldBeNull("error"); |
| 96 }).then(finishJSTest, failAndFinishJSTest); | 66 }).then(finishJSTest, failAndFinishJSTest); |
| 97 | 67 |
| 98 | |
| 99 </script> | 68 </script> |
| 100 | 69 |
| 101 </body> | 70 </body> |
| 71 </html> |
| OLD | NEW |