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