3 Commits

Author SHA1 Message Date
1f2b7b1e45 fix enableOTP handling to match docs: prioritize store, then extension config 2022-11-06 01:53:32 -07:00
92060876c9 getSetting: add an optional scope parameter
settings are stored in 3 places:
- login (.gpg file)
- store (.browserpass-settings.json)
- extension-level config (browser UI)

but we don't want each setting to be settable everywhere, so scope
allows one to control which of these 3 places to search for a given
setting.
2022-11-06 01:49:01 -07:00
c796967226 export SettingScope (define it above the exports) 2022-11-06 01:06:28 -07:00
3 changed files with 14 additions and 11 deletions

View File

@@ -724,7 +724,7 @@ async function handleMessage(settings, message, sendResponse) {
}
break;
case "copyOTP":
if (settings.enableOTP) {
if (helpers.getSetting("enableOTP", message.login, settings, helpers.SettingScope.Store)) {
try {
if (!message.login.fields.otp) {
throw new Exception("No OTP seed available");
@@ -796,8 +796,8 @@ async function handleMessage(settings, message, sendResponse) {
// copy OTP token after fill
if (
settings.enableOTP &&
typeof message.login !== "undefined" &&
helpers.getSetting("enableOTP", message.login, settings, helpers.SettingScope.Store) &&
message.login.fields.hasOwnProperty("otp")
) {
copyToClipboard(helpers.makeTOTP(message.login.fields.otp.params));
@@ -963,7 +963,10 @@ async function parseFields(settings, login) {
}
// preprocess otp
if (settings.enableOTP && login.fields.hasOwnProperty("otp")) {
if (
helpers.getSetting("enableOTP", login, settings, helpers.SettingScope.Store) &&
login.fields.hasOwnProperty("otp")
) {
if (login.fields.otp.match(/^otpauth:\/\/.+/i)) {
// attempt to parse otp data as URI
try {

View File

@@ -8,6 +8,13 @@ const hash = require("hash.js");
const Authenticator = require("otplib").authenticator.Authenticator;
const BrowserpassURL = require("@browserpass/url");
const SettingScope = {
// query a setting first from the login, then the store, then globally
Login: "login",
// query a setting first from the store, then globally
Store: "store",
};
module.exports = {
prepareLogins,
filterSortLogins,
@@ -17,13 +24,6 @@ module.exports = {
SettingScope,
};
const SettingScope = {
// query a setting first from the login, then the store, then globally
Login: "login",
// query a setting first from the store, then globally
Store: "store",
};
//----------------------------------- Function definitions ----------------------------------//
/**

View File

@@ -103,7 +103,7 @@ function view(ctl, params) {
]),
(() => {
if (
this.settings.enableOTP &&
helpers.getSetting("enableOTP", login, this.settings, helpers.SettingScope.Store) &&
login.fields.otp &&
login.fields.otp.params.type === "totp"
) {