| 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("Test wrapping and unwrapping keys with AES-KW."); |  | 
|  13  |  | 
|  14 jsTestIsAsync = true; |  | 
|  15  |  | 
|  16 var kekData = hexStringToUint8Array("000102030405060708090A0B0C0D0E0F"); |  | 
|  17 var keyData = hexStringToUint8Array("00112233445566778899AABBCCDDEEFF"); |  | 
|  18 var extractable = true; |  | 
|  19  |  | 
|  20 debug("Importing key encryption key..."); |  | 
|  21 crypto.subtle.importKey("raw", kekData, {name: "aes-kw"}, extractable, ["wrapKey
    ", "unwrapKey"]).then(function(result) { |  | 
|  22     kek = result; |  | 
|  23  |  | 
|  24     debug("Importing a key to be wrapped..."); |  | 
|  25     return crypto.subtle.importKey("raw", keyData, {name: "aes-cbc"}, extractabl
    e, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]); |  | 
|  26 }).then(function(result) { |  | 
|  27     key = result; |  | 
|  28  |  | 
|  29     debug("Wrapping it..."); |  | 
|  30     return crypto.subtle.wrapKey("raw", key, kek, {name: "aes-kw"}); |  | 
|  31 }).then(function(result) { |  | 
|  32     wrappedKey = result; |  | 
|  33     shouldBe("bytesToHexString(wrappedKey)", "'1fa68b0a8112b447aef34bd8fb5a7b829
    d3e862371d2cfe5'"); // Result from RFC 3394. |  | 
|  34  |  | 
|  35     debug("Unwrapping it..."); |  | 
|  36     return crypto.subtle.unwrapKey("raw", wrappedKey, kek, {name: "aes-kw"}, {na
    me: "aes-cbc"}, extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]); |  | 
|  37 }).then(function(result) { |  | 
|  38     unwrappedKey = result; |  | 
|  39     shouldBe("unwrappedKey.toString()", "'[object CryptoKey]'"); |  | 
|  40     shouldBe("unwrappedKey.type", "'secret'"); |  | 
|  41     shouldBe("unwrappedKey.extractable", "true"); |  | 
|  42     shouldBe("unwrappedKey.algorithm.name", "'AES-CBC'"); |  | 
|  43     shouldBe("unwrappedKey.algorithm.length", "128"); |  | 
|  44     shouldBe("unwrappedKey.usages", "['encrypt', 'decrypt', 'wrapKey', 'unwrapKe
    y']"); |  | 
|  45  |  | 
|  46     debug("Exporting it..."); |  | 
|  47     return crypto.subtle.exportKey("raw", unwrappedKey); |  | 
|  48 }).then(function(result) { |  | 
|  49     unwrappedKeyData = result; |  | 
|  50     shouldBe("bytesToHexString(unwrappedKeyData)", "bytesToHexString(keyData)"); |  | 
|  51  |  | 
|  52     finishJSTest(); |  | 
|  53 }); |  | 
|  54 </script> |  | 
|  55  |  | 
|  56 </body> |  | 
|  57 </html> |  | 
| OLD | NEW |