-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
573 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @author gchq77703 [] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import jwt from "jsonwebtoken"; | ||
import OperationError from "../errors/OperationError"; | ||
|
||
/** | ||
* JWT Decode operation | ||
*/ | ||
class JWTDecode extends Operation { | ||
|
||
/** | ||
* JWTDecode constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "JWT Decode"; | ||
this.module = "Crypto"; | ||
this.description = "Decodes a JSON Web Token <b>without</b> checking whether the provided secret / private key is valid. Use 'JWT Verify' to check if the signature is valid as well."; | ||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; | ||
this.inputType = "string"; | ||
this.outputType = "JSON"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {JSON} | ||
*/ | ||
run(input, args) { | ||
try { | ||
const decoded = jwt.decode(input, { | ||
json: true, | ||
complete: true | ||
}); | ||
|
||
return decoded.payload; | ||
} catch (err) { | ||
throw new OperationError(err); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default JWTDecode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @author gchq77703 [] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import jwt from "jsonwebtoken"; | ||
import OperationError from "../errors/OperationError"; | ||
|
||
/** | ||
* JWT Sign operation | ||
*/ | ||
class JWTSign extends Operation { | ||
|
||
/** | ||
* JWTSign constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "JWT Sign"; | ||
this.module = "Crypto"; | ||
this.description = "Signs a JSON object as a JSON Web Token using a provided secret / private key.<br><br>The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA."; | ||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; | ||
this.inputType = "JSON"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
name: "Private/Secret Key", | ||
type: "text", | ||
value: "secret" | ||
}, | ||
{ | ||
name: "Signing algorithm", | ||
type: "option", | ||
value: [ | ||
"HS256", | ||
"HS384", | ||
"HS512", | ||
"RS256", | ||
"RS384", | ||
"RS512", | ||
"ES256", | ||
"ES384", | ||
"ES512", | ||
"None" | ||
] | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {JSON} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
const [key, algorithm] = args; | ||
|
||
try { | ||
return jwt.sign(input, key, { | ||
algorithm: algorithm === "None" ? "none" : algorithm | ||
}); | ||
} catch (err) { | ||
throw new OperationError(`Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA. | ||
${err}`); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default JWTSign; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @author gchq77703 [] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import jwt from "jsonwebtoken"; | ||
import OperationError from "../errors/OperationError"; | ||
|
||
/** | ||
* JWT Verify operation | ||
*/ | ||
class JWTVerify extends Operation { | ||
|
||
/** | ||
* JWTVerify constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "JWT Verify"; | ||
this.module = "Crypto"; | ||
this.description = "Verifies that a JSON Web Token is valid and has been signed with the provided secret / private key.<br><br>The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA."; | ||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; | ||
this.inputType = "string"; | ||
this.outputType = "JSON"; | ||
this.args = [ | ||
{ | ||
name: "Private/Secret Key", | ||
type: "text", | ||
value: "secret" | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
const [key] = args; | ||
|
||
try { | ||
const verified = jwt.verify(input, key, { algorithms: [ | ||
"HS256", | ||
"HS384", | ||
"HS512", | ||
"none" | ||
]}); | ||
|
||
if (verified.hasOwnProperty("name") && verified.name === "JsonWebTokenError") { | ||
throw new OperationError(verified.message); | ||
} | ||
|
||
return verified; | ||
} catch (err) { | ||
throw new OperationError(err); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default JWTVerify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.