Fix filling TOTP with multiple pages

This commit is contained in:
varjolintu 2018-05-16 08:18:23 +03:00
parent 15b889fa78
commit 721378f11a
4 changed files with 52 additions and 26 deletions

View file

@ -272,6 +272,14 @@ kpxcEvent.pageClearLogins = function(callback, tab, alreadyCalled) {
callback();
};
kpxcEvent.pageGetLoginId = function(callback, tab) {
callback(page.loginId);
};
kpxcEvent.pageSetLoginId = function(callback, tab, loginId) {
page.loginId = loginId;
};
// all methods named in this object have to be declared BEFORE this!
kpxcEvent.messageHandlers = {
'add_credentials': keepass.addCredentials,
@ -287,6 +295,8 @@ kpxcEvent.messageHandlers = {
'load_settings': kpxcEvent.onLoadSettings,
'lock-database': kpxcEvent.lockDatabase,
'page_clear_logins': kpxcEvent.pageClearLogins,
'page_get_login_id': kpxcEvent.pageGetLoginId,
'page_set_login_id': kpxcEvent.pageSetLoginId,
'pop_stack': kpxcEvent.onPopStack,
'popup_login': kpxcEvent.onLoginPopup,
'popup_multiple-fields': kpxcEvent.onMultipleFieldsPopup,

View file

@ -16,6 +16,7 @@ var page = {};
page.tabs = [];
page.currentTabId = -1;
page.blockedTabs = [];
page.loginId = -1;
page.initSettings = function() {
return new Promise((resolve, reject) => {

View file

@ -22,12 +22,16 @@ browser.runtime.onMessage.addListener(function(req, sender, callback) {
if (cip.u) {
cip.setValueWithChange(cip.u, cip.credentials[req.id].login);
combination = cipFields.getCombination('username', cip.u);
_loginId = req.id;
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [req.id]
});
cip.u.focus();
}
if (cip.p) {
cip.setValueWithChange(cip.p, cip.credentials[req.id].password);
_loginId = req.id;
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [req.id]
});
combination = cipFields.getCombination('password', cip.p);
}
@ -1595,23 +1599,26 @@ cip.fillInFromActiveElementTOTPOnly = function(suppressWarnings) {
const el = document.activeElement;
cipFields.setUniqueId(jQuery(el));
const fieldId = cipFields.prepareId(jQuery(el).attr('data-cip-id'));
const pos = _loginId;
if (pos >= 0 && cip.credentials[pos]) {
// Check the value from stringFields (to be removed)
const $sf = _fs(fieldId);
if (cip.credentials[pos].stringFields && cip.credentials[pos].stringFields.length > 0) {
const sFields = cip.credentials[pos].stringFields;
for (const s of sFields) {
const val = s["KPH: {TOTP}"];
if (val) {
cip.setValue($sf, val);
browser.runtime.sendMessage({
action: 'page_get_login_id'
}).then((pos) => {
if (pos >= 0 && cip.credentials[pos]) {
// Check the value from stringFields (to be removed)
const currentField = _fs(fieldId);
if (cip.credentials[pos].stringFields && cip.credentials[pos].stringFields.length > 0) {
const stringFields = cip.credentials[pos].stringFields;
for (const s of stringFields) {
const val = s["KPH: {TOTP}"];
if (val) {
cip.setValue(currentField, val);
}
}
} else if (cip.credentials[pos].totp && cip.credentials[pos].totp.length > 0) {
cip.setValue(currentField, cip.credentials[pos].totp);
}
} else if (cip.credentials[pos].totp && cip.credentials[pos].totp.length > 0) {
cip.setValue($sf, cip.credentials[pos].totp);
}
}
});
};
cip.setValue = function(field, value) {
@ -1631,22 +1638,22 @@ cip.setValue = function(field, value) {
};
cip.fillInStringFields = function(fields, stringFields, filledInFields) {
let $filledIn = false;
let filledIn = false;
filledInFields.list = [];
if (fields && stringFields && fields.length > 0 && stringFields.length > 0) {
for (let i = 0; i < fields.length; i++) {
const $sf = _fs(fields[i]);
const currentField = _fs(fields[i]);
const stringFieldValue = Object.values(stringFields[i]);
if ($sf && stringFieldValue[0]) {
cip.setValue($sf, stringFieldValue[0]);
if (currentField && stringFieldValue[0]) {
cip.setValue(currentField, stringFieldValue[0]);
filledInFields.list.push(fields[i]);
$filledIn = true;
filledIn = true;
}
}
}
return $filledIn;
return filledIn;
};
cip.setValueWithChange = function(field, value) {
@ -1681,14 +1688,18 @@ cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
let filledIn = false;
if (uField && !onlyPassword) {
cip.setValueWithChange(uField, cip.credentials[0].login);
_loginId = 0;
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [0]
});
filledIn = true;
}
if (pField) {
pField.attr('type', 'password');
cip.setValueWithChange(pField, cip.credentials[0].password);
pField.data('unchanged', true);
_loginId = 0;
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [0]
});
filledIn = true;
}
@ -1713,14 +1724,18 @@ cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
let filledIn = false;
if (uField) {
cip.setValueWithChange(uField, cip.credentials[combination.loginId].login);
_loginId = combination.loginId;
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [combination.loginId]
});
filledIn = true;
}
if (pField) {
cip.setValueWithChange(pField, cip.credentials[combination.loginId].password);
pField.data('unchanged', true);
_loginId = combination.loginId;
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [combination.loginId]
});
filledIn = true;
}

View file

@ -19,7 +19,7 @@ $(function() {
const id = e.target.id;
browser.tabs.sendMessage(tab.id, {
action: 'fill_user_pass_with_specific_login',
id: id
id: Number(id)
});
close();
});