mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
fix: refactor GenerateHOTP to use optauth
This commit is contained in:
parent
672cb5dea4
commit
90133e3f90
1 changed files with 19 additions and 21 deletions
|
@ -5,16 +5,14 @@
|
|||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import otp from "otp";
|
||||
import ToBase32 from "./ToBase32.mjs";
|
||||
import * as OTPAuth from "otpauth";
|
||||
|
||||
/**
|
||||
* Generate HOTP operation
|
||||
*/
|
||||
class GenerateHOTP extends Operation {
|
||||
|
||||
/**
|
||||
* GenerateHOTP constructor
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -31,11 +29,6 @@ class GenerateHOTP extends Operation {
|
|||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "Key size",
|
||||
"type": "number",
|
||||
"value": 32
|
||||
},
|
||||
{
|
||||
"name": "Code length",
|
||||
"type": "number",
|
||||
|
@ -50,21 +43,26 @@ class GenerateHOTP extends Operation {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
run(input, args) {
|
||||
const otpObj = otp({
|
||||
name: args[0],
|
||||
keySize: args[1],
|
||||
codeLength: args[2],
|
||||
secret: (new ToBase32).run(input, []).split("=")[0],
|
||||
});
|
||||
const counter = args[3];
|
||||
return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`;
|
||||
}
|
||||
const secretStr = new TextDecoder("utf-8").decode(input).trim();
|
||||
const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
|
||||
|
||||
const hotp = new OTPAuth.HOTP({
|
||||
issuer: "",
|
||||
label: args[0],
|
||||
algorithm: "SHA1",
|
||||
digits: args[1],
|
||||
counter: args[2],
|
||||
secret: OTPAuth.Secret.fromBase32(secret)
|
||||
});
|
||||
|
||||
const uri = hotp.toString();
|
||||
const code = hotp.generate();
|
||||
|
||||
return `URI: ${uri}\n\nPassword: ${code}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default GenerateHOTP;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue