diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json old mode 100755 new mode 100644 index 5b8de4753..4dd4a1c52 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -321,6 +321,7 @@ "Bcrypt parse", "Scrypt", "Argon2", + "Argon2 compare", "Fletcher-8 Checksum", "Fletcher-16 Checksum", "Fletcher-32 Checksum", diff --git a/src/core/operations/Argon2Compare.mjs b/src/core/operations/Argon2Compare.mjs new file mode 100644 index 000000000..ab41851fd --- /dev/null +++ b/src/core/operations/Argon2Compare.mjs @@ -0,0 +1,56 @@ +/** + * @author Tan Zhen Yong [tzy@beyondthesprawl.com] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import argon2 from "argon2-browser"; + +/** + * Argon2 compare operation + */ +class Argon2Compare extends Operation { + + /** + * Argon2Compare constructor + */ + constructor() { + super(); + + this.name = "Argon2 compare"; + this.module = "Crypto"; + this.description = "Tests whether the input matches the given Argon2 hash. To test multiple possible passwords, use the 'Fork' operation."; + this.infoURL = "https://wikipedia.org/wiki/Argon2"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + "name": "Hash", + "type": "string", + "value": "" + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const encoded = args[0]; + + return argon2.verify({ + pass: input, + encoded + }).then(_ => { + return `Match: ${input}`; + }).catch(_ => { + return "No match"; + }); + } + +} + +export default Argon2Compare; diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index e0ac777b5..6003d34c9 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -138,6 +138,13 @@ Tiger-128`; assert.strictEqual(result.toString(), "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"); }), + it("Argon2 compare", async () => { + const result = await chef.Argon2Compare("argon2password", { + hash: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw" + }); + assert.strictEqual(result.toString(), "Match: argon2password"); + }), + it("Bcrypt", async () => { const result = await chef.bcrypt("Put a Sock In It"); const strResult = result.toString();