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 an AES key."); | 12 description("Test exporting an AES key."); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 var extractable = true; | 16 var extractable = true; |
17 var nonExtractable = false; | 17 var nonExtractable = false; |
18 | 18 |
19 var jwkKey = { | 19 var jwkKey = { |
20 "kty": "oct", | 20 "kty": "oct", |
21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs" | 21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs" |
22 }; | 22 }; |
23 | 23 |
24 var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey)); | |
25 | |
26 debug("Importing a JWK key..."); | 24 debug("Importing a JWK key..."); |
27 crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: {name:
"SHA-256"} }, extractable, ["sign", "verify"]).then(function(result) { | 25 crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: "SHA-256"} }
, extractable, ["sign", "verify"]).then(function(result) { |
28 key = result; | 26 key = result; |
29 | 27 |
30 return crypto.subtle.exportKey(null, key); | 28 return crypto.subtle.exportKey(null, key); |
31 }).then(failAndFinishJSTest, function(result) { | 29 }).then(failAndFinishJSTest, function(result) { |
32 logError(result); | 30 logError(result); |
33 return crypto.subtle.exportKey(undefined, key); | 31 return crypto.subtle.exportKey(undefined, key); |
34 }).then(failAndFinishJSTest, function(result) { | 32 }).then(failAndFinishJSTest, function(result) { |
35 logError(result); | 33 logError(result); |
36 return crypto.subtle.exportKey({}, key); | 34 return crypto.subtle.exportKey({}, key); |
37 }).then(failAndFinishJSTest, function(result) { | 35 }).then(failAndFinishJSTest, function(result) { |
(...skipping 16 matching lines...) Expand all Loading... |
54 }).then(function(result) { | 52 }).then(function(result) { |
55 exportedJWK = JSON.parse(bytesToASCIIString(result)); | 53 exportedJWK = JSON.parse(bytesToASCIIString(result)); |
56 shouldBe("exportedJWK.kty", "'oct'"); | 54 shouldBe("exportedJWK.kty", "'oct'"); |
57 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'"); | 55 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'"); |
58 shouldBe("exportedJWK.alg", "'HS256'"); | 56 shouldBe("exportedJWK.alg", "'HS256'"); |
59 shouldBe("exportedJWK.ext", "true"); | 57 shouldBe("exportedJWK.ext", "true"); |
60 shouldBe("exportedJWK.use", "undefined"); | 58 shouldBe("exportedJWK.use", "undefined"); |
61 shouldBe("exportedJWK.key_ops", "['sign', 'verify']"); | 59 shouldBe("exportedJWK.key_ops", "['sign', 'verify']"); |
62 | 60 |
63 debug("\nImporting a key that's not extractable..."); | 61 debug("\nImporting a key that's not extractable..."); |
64 return crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", h
ash: {name: "SHA-256"} }, nonExtractable, ["sign", "verify"]); | 62 return crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: "
SHA-256"} }, nonExtractable, ["sign", "verify"]); |
65 }, failAndFinishJSTest).then(function(result) { | 63 }, failAndFinishJSTest).then(function(result) { |
66 key = result; | 64 key = result; |
67 | 65 |
68 debug("\nTrying to export as raw..."); | 66 debug("\nTrying to export as raw..."); |
69 return crypto.subtle.exportKey("raw", key); | 67 return crypto.subtle.exportKey("raw", key); |
70 }).then(function(result) { | 68 }).then(function(result) { |
71 testFailed("Promise wasn't rejected"); | 69 testFailed("Promise wasn't rejected"); |
72 finishJSTest(); | 70 finishJSTest(); |
73 }, function(result) { | 71 }, function(result) { |
74 logError(result); | 72 logError(result); |
75 testPassed("Rejected, as expected"); | 73 testPassed("Rejected, as expected"); |
76 | 74 |
77 debug("Trying to export as jwk..."); | 75 debug("Trying to export as jwk..."); |
78 return crypto.subtle.exportKey("jwk", key); | 76 return crypto.subtle.exportKey("jwk", key); |
79 }).then(function(result) { | 77 }).then(function(result) { |
80 testFailed("Promise wasn't rejected"); | 78 testFailed("Promise wasn't rejected"); |
81 finishJSTest(); | 79 finishJSTest(); |
82 }, function(result) { | 80 }, function(result) { |
83 logError(result); | 81 logError(result); |
84 testPassed("Rejected, as expected"); | 82 testPassed("Rejected, as expected"); |
85 | 83 |
86 finishJSTest(); | 84 finishJSTest(); |
87 }); | 85 }); |
88 </script> | 86 </script> |
89 | 87 |
90 </body> | 88 </body> |
91 </html> | 89 </html> |
OLD | NEW |