2 Commits

Author SHA1 Message Date
e3bf558ff6 pass the unmodified login path to the native component instead of assuming .gpg
this is in support of
<https://github.com/browserpass/browserpass-native/issues/127>.

this has immediate benefit for anyone using the patches shared in that PR
today. without this, browserpass doesn't recognize `github.com.age` as a
default key for `https://github.com`, because it fails the substring
match. by stripping the extension -- whatever it is -- both
`github.com.gpg` and `github.com.age` are recognized as keys for their
intended domain.
2022-11-24 10:11:24 +00:00
Colin Sane
21f3431d09 Fix enableOTP handling to match docs: prioritize store, then extension config (#308) 2022-11-22 01:19:22 +01:00
3 changed files with 32 additions and 27 deletions

View File

@@ -450,7 +450,7 @@ async function fillFields(settings, login, fields) {
// build focus or submit request // build focus or submit request
let focusOrSubmitRequest = { let focusOrSubmitRequest = {
origin: new BrowserpassURL(settings.tab.url).origin, origin: new BrowserpassURL(settings.tab.url).origin,
autoSubmit: getSetting("autoSubmit", login, settings), autoSubmit: helpers.getSetting("autoSubmit", login, settings),
filledFields: filledFields, filledFields: filledFields,
}; };
@@ -561,25 +561,6 @@ async function getFullSettings() {
return settings; return settings;
} }
/**
* Get most relevant setting value
*
* @param string key Setting key
* @param object login Login object
* @param object settings Settings object
* @return object Setting value
*/
function getSetting(key, login, settings) {
if (typeof login.settings[key] !== "undefined") {
return login.settings[key];
}
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
return settings.stores[login.store.id].settings[key];
}
return settings[key];
}
/** /**
* Deep copy an object * Deep copy an object
* *
@@ -743,7 +724,7 @@ async function handleMessage(settings, message, sendResponse) {
} }
break; break;
case "copyOTP": case "copyOTP":
if (settings.enableOTP) { if (helpers.getSetting("enableOTP", message.login, settings)) {
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");
@@ -815,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) &&
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));
@@ -889,7 +870,7 @@ function hostAction(settings, action, params = {}) {
async function parseFields(settings, login) { async function parseFields(settings, login) {
var response = await hostAction(settings, "fetch", { var response = await hostAction(settings, "fetch", {
storeId: login.store.id, storeId: login.store.id,
file: login.login + ".gpg", file: login.loginPath,
}); });
if (response.status != "ok") { if (response.status != "ok") {
throw new Error(JSON.stringify(response)); // TODO handle host error throw new Error(JSON.stringify(response)); // TODO handle host error
@@ -968,7 +949,7 @@ async function parseFields(settings, login) {
if (key === "secret" && lines.length) { if (key === "secret" && lines.length) {
login.fields.secret = lines[0]; login.fields.secret = lines[0];
} else if (key === "login") { } else if (key === "login") {
const defaultUsername = getSetting("username", login, settings); const defaultUsername = helpers.getSetting("username", login, settings);
login.fields[key] = defaultUsername || login.login.match(/([^\/]+)$/)[1]; login.fields[key] = defaultUsername || login.login.match(/([^\/]+)$/)[1];
} else { } else {
delete login.fields[key]; delete login.fields[key];
@@ -982,7 +963,7 @@ async function parseFields(settings, login) {
} }
// preprocess otp // preprocess otp
if (settings.enableOTP && login.fields.hasOwnProperty("otp")) { if (helpers.getSetting("enableOTP", login, settings) && 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

@@ -11,12 +11,32 @@ const BrowserpassURL = require("@browserpass/url");
module.exports = { module.exports = {
prepareLogins, prepareLogins,
filterSortLogins, filterSortLogins,
getSetting,
ignoreFiles, ignoreFiles,
makeTOTP, makeTOTP,
}; };
//----------------------------------- Function definitions ----------------------------------// //----------------------------------- Function definitions ----------------------------------//
/**
* Get most relevant setting value
*
* @param string key Setting key
* @param object login Login object
* @param object settings Settings object
* @return object Setting value
*/
function getSetting(key, login, settings) {
if (typeof login.settings[key] !== "undefined") {
return login.settings[key];
}
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
return settings.stores[login.store.id].settings[key];
}
return settings[key];
}
/** /**
* Get the deepest available domain component of a path * Get the deepest available domain component of a path
* *
@@ -67,10 +87,14 @@ function prepareLogins(files, settings) {
for (let storeId in files) { for (let storeId in files) {
for (let key in files[storeId]) { for (let key in files[storeId]) {
// set login fields // set login fields
const loginPath = files[storeId][key];
// remove the file-type extension
const loginName = loginPath.replace(/\.[^.]+$/u, "");
const login = { const login = {
index: index++, index: index++,
store: settings.stores[storeId], store: settings.stores[storeId],
login: files[storeId][key].replace(/\.gpg$/i, ""), login: loginName,
loginPath: loginPath,
allowFill: true, allowFill: true,
}; };

View File

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