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,
[]); | |
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, []); | |
28 }).then(failAndFinishJSTest, function(result) { | |
29 logError(result); | |
30 return crypto.subtle.importKey("jwk", {}, {name: "aes-cbc"}, extractable, []
); | |
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, []); | |
35 }).then(failAndFinishJSTest, function(result) { | |
36 logError(result); | |
37 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "foobar", "use"
: "sig", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {name: "aes-cbc"}
, extractable, []); | |
38 }).then(failAndFinishJSTest, function(result) { | |
39 logError(result); | |
40 // Algorithm mismatch. | |
41 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {nam
e: "AES-cbc"}, nonExtractable, []); | |
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, []); | |
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, []); | |
49 }).then(failAndFinishJSTest, function(result) { | |
50 logError(result); | |
51 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "A128CBC" }, {n
ame: "aes-cbc"}, extractable, []); | |
52 }).then(failAndFinishJSTest, function(result) { | |
53 logError(result); | |
54 // FIXME: http://crbug.com/378037 | |
55 // Key data length is incorrect, not allowed in JWK. | |
56 // return crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct",
"alg": "HS256", "use": "sig", "ext": false, "k": "1234" }'), hmac256, nonExtract
able, []); | |
57 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "A128CBC", "use
": "sig", "ext": false, "k": "1234" }, {name: "aes-cbc"}, nonExtractable, []); | |
58 }).then(failAndFinishJSTest, function(result) { | |
59 logError(result); | |
60 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "A128CBC", "use
": "sig", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {n
ame: "aes-cbc"}, nonExtractable, []); | |
61 }).then(failAndFinishJSTest, function(result) { | |
62 logError(result); | |
63 // Key data is not valid base64url. | |
64 // FIXME: http://crbug.com/378034 | |
65 // return crypto.subtle.importKey("jwk", asciiToUint8Array('{ "kty": "oct",
"alg": "HS256", "use": "sig", "ext": false, "k": "ahjkn23387f+nsibf23qsvahjkn373
87fgnsibf23qs" }'), hmac256, nonExtractable, []); | |
66 | |
67 // Incorrect data types. | |
68 return crypto.subtle.importKey("jwk", { "kty": 1, "alg": "HS256", "use": "si
g", "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hmac256,
nonExtractable, []); | |
69 }).then(failAndFinishJSTest, function(result) { | |
70 logError(result); | |
71 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": 1, "use": "sig"
, "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, {name: "ae
s-cbc"}, nonExtractable, []); | |
72 }).then(failAndFinishJSTest, function(result) { | |
73 logError(result); | |
74 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
1, "ext": false, "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hmac256,
nonExtractable, []); | |
75 }).then(failAndFinishJSTest, function(result) { | |
76 logError(result); | |
77 // ext is recognized as a boolean even though it is a string. | |
78 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": "false", "k": "ahjkn23387fgnsibf23qsvahjkn37387fgnsibf23qs" }, hm
ac256, nonExtractable, []); | |
79 }).then(function(result) { | |
80 debug("Boolean JWK property passed as a string and worked"); | |
81 // k is recognized as a string even though it is a number. | |
82 return crypto.subtle.importKey("jwk", { "kty": "oct", "alg": "HS256", "use":
"sig", "ext": false, "k": 1258 }, hmac256, nonExtractable, []); | |
83 }).then(function(result) { | |
84 debug("String JWK property passed as a number and worked"); | |
85 }).then(finishJSTest, failAndFinishJSTest); | |
86 </script> | |
87 | |
88 </body> | |
89 </html> | |
OLD | NEW |