Merge 173abaf64a7b4b71718249f71596a79a8832022f into 6a3a370bb15032dbfd1a063af446837b572464f1
This commit is contained in:
commit
8143de8c72
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import * as OTPAuth from "otpauth";
|
import * as OTPAuth from "otpauth";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,22 +47,29 @@ class GenerateHOTP extends Operation {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const secretStr = new TextDecoder("utf-8").decode(input).trim();
|
try {
|
||||||
const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
|
const secretStr = new TextDecoder("utf-8").decode(input).trim();
|
||||||
|
const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
|
||||||
|
|
||||||
const hotp = new OTPAuth.HOTP({
|
const hotp = new OTPAuth.HOTP({
|
||||||
issuer: "",
|
issuer: "",
|
||||||
label: args[0],
|
label: args[0],
|
||||||
algorithm: "SHA1",
|
algorithm: "SHA1",
|
||||||
digits: args[1],
|
digits: args[1],
|
||||||
counter: args[2],
|
counter: args[2],
|
||||||
secret: OTPAuth.Secret.fromBase32(secret)
|
secret: OTPAuth.Secret.fromBase32(secret)
|
||||||
});
|
});
|
||||||
|
|
||||||
const uri = hotp.toString();
|
const uri = hotp.toString();
|
||||||
const code = hotp.generate();
|
const code = hotp.generate();
|
||||||
|
|
||||||
return `URI: ${uri}\n\nPassword: ${code}`;
|
return `URI: ${uri}\n\nPassword: ${code}`;
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof TypeError) {
|
||||||
|
throw new OperationError("Invalid character found in input. HOTP secrets must be valid Base32 characters (A-Z, 2-7).");
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user