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