Add context screen & integrated TOTP support (#229)

This commit is contained in:
Erayd
2020-09-10 07:13:15 +12:00
committed by GitHub
parent 0f8608ec7e
commit 29a7043264
18 changed files with 616 additions and 98 deletions

View File

@@ -4,12 +4,15 @@
const FuzzySort = require("fuzzysort");
const sha1 = require("sha1");
const ignore = require("ignore");
const hash = require("hash.js");
const Authenticator = require("otplib").authenticator.Authenticator;
const BrowserpassURL = require("@browserpass/url");
module.exports = {
prepareLogins,
filterSortLogins,
ignoreFiles,
makeTOTP,
};
//----------------------------------- Function definitions ----------------------------------//
@@ -220,6 +223,37 @@ function filterSortLogins(logins, searchQuery, currentDomainOnly) {
return candidates;
}
/**
* Generate TOTP token
*
* @since 3.6.0
*
* @param object params OTP generation params
* @return string Generated OTP code
*/
function makeTOTP(params) {
switch (params.algorithm) {
case "sha1":
case "sha256":
case "sha512":
break;
default:
throw new Error(`Unsupported TOTP algorithm: ${params.algorithm}`);
}
var generator = new Authenticator();
generator.options = {
crypto: {
createHmac: (a, k) => hash.hmac(hash[a], k),
},
algorithm: params.algorithm,
digits: params.digits,
step: params.period,
};
return generator.generate(params.secret);
}
//----------------------------------- Private functions ----------------------------------//
/**