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 exporting keys with various usages to JWK."); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 var extractable = true; |
| 17 |
| 18 var aesKeyAsArrayBuffer = Base64URL.parse("jnOw99oOZFLIEPMrgJB55WL46tJSLGt7"); |
| 19 var hmacKeyAsArrayBuffer = Base64URL.parse("ahjkn-_387fgnsibf23qsvahjkn-_387fgns
ibf23qs"); |
| 20 |
| 21 function testWithAESCBC(usages, expectedKeyOps) |
| 22 { |
| 23 return crypto.subtle.importKey("raw", aesKeyAsArrayBuffer, {name: "AES-CBC"},
extractable, usages).then(function(result) { |
| 24 return crypto.subtle.exportKey("jwk", result); |
| 25 }).then(function(result) { |
| 26 jwk = JSON.parse(bytesToASCIIString(result)); |
| 27 debug(usages + ":"); |
| 28 shouldBe("jwk.use", "undefined"); |
| 29 shouldBe("jwk.key_ops", JSON.stringify(expectedKeyOps)); |
| 30 debug(""); |
| 31 }); |
| 32 } |
| 33 |
| 34 function testWithHMAC(usages, expectedKeyOps) |
| 35 { |
| 36 return crypto.subtle.importKey("raw", hmacKeyAsArrayBuffer, {name: 'hmac', h
ash: {name: 'sha-256'}}, extractable, usages).then(function(result) { |
| 37 return crypto.subtle.exportKey("jwk", result); |
| 38 }).then(function(result) { |
| 39 jwk = JSON.parse(bytesToASCIIString(result)); |
| 40 debug(usages + ":"); |
| 41 shouldBe("jwk.use", "undefined"); |
| 42 shouldBe("jwk.key_ops", JSON.stringify(expectedKeyOps)); |
| 43 debug(""); |
| 44 }); |
| 45 } |
| 46 |
| 47 Promise.all([ |
| 48 testWithAESCBC(["encrypt"], ["encrypt"]), |
| 49 testWithAESCBC(["decrypt"], ["decrypt"]), |
| 50 testWithAESCBC(["encrypt", "decrypt"], ["encrypt", "decrypt"]), |
| 51 testWithAESCBC(["wrapKey"], ["wrapKey"]), |
| 52 testWithAESCBC(["unwrapKey"], ["unwrapKey"]), |
| 53 testWithAESCBC(["wrapKey", "unwrapKey"], ["wrapKey", "unwrapKey"]), |
| 54 testWithAESCBC(["encrypt", "decrypt", "wrapKey"], ["encrypt", "decrypt", "wr
apKey"]), |
| 55 testWithAESCBC(["encrypt", "decrypt", "wrapKey", "unwrapKey"], ["encrypt", "
decrypt", "wrapKey", "unwrapKey"]), |
| 56 testWithHMAC(["sign"], ["sign"]), |
| 57 testWithHMAC(["verify"], ["verify"]), |
| 58 testWithHMAC(["sign", "verify"], ["sign", "verify"]), |
| 59 ]).then(finishJSTest, failAndFinishJSTest); |
| 60 </script> |
| 61 |
| 62 </body> |
| 63 </html> |
OLD | NEW |