Updated algorithm selection

This commit is contained in:
Michael Rowley 2022-03-21 20:50:43 +00:00
parent 8332e39b6b
commit d23d98d2a0
3 changed files with 6 additions and 19 deletions

View file

@ -19,6 +19,5 @@ export const JWT_ALGORITHMS = [
"RS512", "RS512",
"ES256", "ES256",
"ES384", "ES384",
"ES512", "ES512"
"None"
]; ];

View file

@ -26,6 +26,7 @@ class JWTSign extends Operation {
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
this.inputType = "JSON"; this.inputType = "JSON";
this.outputType = "string"; this.outputType = "string";
const algorithmList = JWT_ALGORITHMS.concat(["None"]);
this.args = [ this.args = [
{ {
name: "Private/Secret Key", name: "Private/Secret Key",
@ -35,7 +36,7 @@ class JWTSign extends Operation {
{ {
name: "Signing algorithm", name: "Signing algorithm",
type: "option", type: "option",
value: JWT_ALGORITHMS value: algorithmList
} }
]; ];
} }

View file

@ -26,8 +26,7 @@ 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";
const algOptions = JWT_ALGORITHMS; const algorithmList = JWT_ALGORITHMS.concat(["Any"]);
algOptions.push("Any");
this.args = [ this.args = [
{ {
name: "Public/Secret Key", name: "Public/Secret Key",
@ -37,7 +36,7 @@ class JWTVerify extends Operation {
{ {
name: "Signing algorithm", name: "Signing algorithm",
type: "option", type: "option",
value: algOptions value: algorithmList
} }
]; ];
} }
@ -49,19 +48,7 @@ class JWTVerify extends Operation {
*/ */
run(input, args) { run(input, args) {
const [key, alg] = args; const [key, alg] = args;
let algos = []; let algos = (alg == "Any" ? JWT_ALGORITHMS : alg);
switch (alg) {
case "Any":
algos = JWT_ALGORITHMS;
break;
case "None":
algos.push("none");
break;
default:
algos.push(alg);
break;
}
try { try {
const verified = jwt.verify(input, key, { algorithms: algos }); const verified = jwt.verify(input, key, { algorithms: algos });