mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
Added algorithm-choice support to JWT Verify
This commit is contained in:
parent
ae1b12c120
commit
0a73825ebe
1 changed files with 22 additions and 3 deletions
|
@ -26,12 +26,19 @@ class JWTVerify extends Operation {
|
||||||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "JSON";
|
this.outputType = "JSON";
|
||||||
|
let algOptions = JWT_ALGORITHMS.slice(0, JWT_ALGORITHMS.length - 1);
|
||||||
|
algOptions.push("Any");
|
||||||
this.args = [
|
this.args = [
|
||||||
{
|
{
|
||||||
name: "Public/Secret Key",
|
name: "Public/Secret Key",
|
||||||
type: "text",
|
type: "text",
|
||||||
value: "secret"
|
value: "secret"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Algorithm",
|
||||||
|
type: "option",
|
||||||
|
value: algOptions
|
||||||
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +48,21 @@ class JWTVerify extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [key] = args;
|
const [key, alg] = args;
|
||||||
const algos = JWT_ALGORITHMS;
|
switch (alg) {
|
||||||
algos[algos.indexOf("None")] = "none";
|
case "Any":
|
||||||
|
const algos = JWT_ALGORITHMS;
|
||||||
|
break;
|
||||||
|
case "None":
|
||||||
|
const algos = [ "none" ];
|
||||||
|
default:
|
||||||
|
const algIndex = JWT_ALGORITHMS.indexOf(alg);
|
||||||
|
if (algIndex === -1) {
|
||||||
|
throw new OperationError("The JWT verification algorithm provided is not supported.");
|
||||||
|
}
|
||||||
|
const algos = JWT_ALGORITHMS[];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const verified = jwt.verify(input, key, { algorithms: algos });
|
const verified = jwt.verify(input, key, { algorithms: algos });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue