4 Commits

Author SHA1 Message Date
284d9b2efc 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 00:38:47 -07:00
f70e0cc838 export SettingScope 2022-11-06 00:38:47 -07:00
73a405c008 define SettingScope 2022-11-06 00:38:37 -07:00
4c7d3533a3 refactor: move getSetting from background.js -> helpers.js
this is because i plan to use it in `detailsInterface.js`
2022-11-05 23:55:38 -07:00
3 changed files with 11 additions and 14 deletions

View File

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

View File

@@ -8,13 +8,6 @@ const hash = require("hash.js");
const Authenticator = require("otplib").authenticator.Authenticator; const Authenticator = require("otplib").authenticator.Authenticator;
const BrowserpassURL = require("@browserpass/url"); 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 = { module.exports = {
prepareLogins, prepareLogins,
filterSortLogins, filterSortLogins,
@@ -24,6 +17,13 @@ module.exports = {
SettingScope, 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 ----------------------------------// //----------------------------------- Function definitions ----------------------------------//
/** /**

View File

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