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 error handling for JWK import."); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 var extractable = true; | |
17 var nonExtractable = false; | |
18 | |
19 var hmac256 = {name: "HMAC", hash: {name: "sha-256"}}; | |
20 | |
21 Promise.resolve(null).then(function(result) { | |
22 // 'null' treated as a Dictionary with default values - an empty dictionary | |
23 return crypto.subtle.importKey("jwk", null, {name: "aes-cbc"}, extractable,
["encrypt"]); | |
24 }).then(failAndFinishJSTest, function(result) { | |
25 logError(result); | |
26 // 'undefined' treated as a Dictionary with default values - an empty dictio
nary | |
27 return crypto.subtle.importKey("jwk", undefined, {name: "aes-cbc"}, extracta
ble, ["encrypt"]); | |
28 }).then(failAndFinishJSTest, function(result) { | |
29 logError(result); | |
30 return crypto.subtle.importKey("jwk", {}, {name: "aes-cbc"}, extractable, ["
encrypt"]); | |
31 }).then(failAndFinishJSTest, function(result) { | |
32 logError(result); | |
33 // Unknown/invalid JWK values. | |
34 return crypto.subtle.importKey("jwk", { "kty": "foobar", "alg": "HS256", "us
e": "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hmac256, extrac
table, ["sign"]); | |
35 }).then(failAndFinishJSTest, function(result) { | |
36 logError(result); | |
37 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "foobar", "use"
: "enc", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {name: "aes-cbc"}
, extractable, ["encrypt"]); | |
38 }).then(failAndFinishJSTest, function(result) { | |
39 logError(result); | |
40 // Algorithm mismatch. | |
41 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"enc", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {nam
e: "AES-cbc"}, nonExtractable, ["encrypt"]); | |
42 }).then(failAndFinishJSTest, function(result) { | |
43 logError(result); | |
44 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, { na
me: "hmac", hash: {name: "sha-1"} }, nonExtractable, ["sign"]); | |
45 }).then(failAndFinishJSTest, function(result) { | |
46 logError(result); | |
47 // No key data. | |
48 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256" }, hmac
256, extractable, ["sign"]); | |
49 }).then(failAndFinishJSTest, function(result) { | |
50 logError(result); | |
51 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "A128CBC" }, {n
ame: "aes-cbc"}, extractable, ["encrypt"]); | |
52 }).then(failAndFinishJSTest, function(result) { | |
53 logError(result); | |
54 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "A128CBC", "use
": "enc", "ext": false, "k": "1234" }, {name: "aes-cbc"}, nonExtractable, ["encr
ypt"]); | |
55 }).then(failAndFinishJSTest, function(result) { | |
56 logError(result); | |
57 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "A128CBC", "use
": "enc", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {n
ame: "aes-cbc"}, nonExtractable, ["encrypt"]); | |
58 }).then(failAndFinishJSTest, function(result) { | |
59 logError(result); | |
60 debug("\nimportKey() with 'k' member containing '+' and '/' characters..."); | |
61 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": false, "k": "ahjkn23387f+nsibf23qsvahjkn37387fgnsibf23qs" }, hmac
256, nonExtractable, ["sign"]); | |
62 }).then(failAndFinishJSTest, function(result) { | |
63 logError(result); | |
64 // Incorrect data types. | |
65 return crypto.subtle.importKey("jwk", { "kty": 1, "alg": "HS256", "use": "si
g", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hmac256,
nonExtractable, ["sign"]); | |
66 }).then(failAndFinishJSTest, function(result) { | |
67 logError(result); | |
68 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": 1, "use": "enc"
, "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {name: "ae
s-cbc"}, nonExtractable, ["encrypt"]); | |
69 }).then(failAndFinishJSTest, function(result) { | |
70 logError(result); | |
71 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
1, "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hmac256,
nonExtractable, ["sign"]); | |
72 }).then(failAndFinishJSTest, function(result) { | |
73 logError(result); | |
74 // ext is recognized as a boolean even though it is a string. | |
75 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": "false", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hm
ac256, nonExtractable, ["sign"]); | |
76 }).then(function(result) { | |
77 debug("Boolean JWK property passed as a string and worked"); | |
78 // k is recognized as a string even though it is a number. | |
79 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": false, "k": 1258 }, hmac256, nonExtractable, ["sign"]); | |
80 }).then(function(result) { | |
81 debug("String JWK property passed as a number and worked"); | |
82 }).then(finishJSTest, failAndFinishJSTest); | |
83 </script> | |
84 | |
85 </body> | |
86 </html> | |
OLD | NEW |