diff --git a/keepassxc-browser/background/browserAction.js b/keepassxc-browser/background/browserAction.js index dcfd8d5..4f6835d 100755 --- a/keepassxc-browser/background/browserAction.js +++ b/keepassxc-browser/background/browserAction.js @@ -15,8 +15,7 @@ browserAction.show = function(callback, tab) { if (!page.tabs[tab.id] || page.tabs[tab.id].stack.length === 0) { browserAction.showDefault(callback, tab); return; - } - else { + } else { data = page.tabs[tab.id].stack[page.tabs[tab.id].stack.length - 1]; } @@ -38,13 +37,13 @@ browserAction.update = function(interval) { return; } - let data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; + const data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; if (data.visibleForMilliSeconds !== undefined && data.visibleForMilliSeconds !== -1) { if (data.visibleForMilliSeconds <= 0) { browserAction.stackPop(page.currentTabId); browserAction.disableLoop(); - browserAction.show(null, {'id': page.currentTabId}); + browserAction.show(null, { 'id': page.currentTabId }); page.clearCredentials(page.currentTabId); return; } @@ -72,7 +71,7 @@ browserAction.update = function(interval) { }; browserAction.showDefault = function(callback, tab) { - let stackData = { + const stackData = { level: 1, iconType: 'normal', popup: 'popup.html' @@ -100,7 +99,7 @@ browserAction.stackAdd = function(callback, tab, icon, popup, level, push, visib level = 1; } - let stackData = { + const stackData = { level: level, icon: icon }; @@ -123,13 +122,12 @@ browserAction.stackAdd = function(callback, tab, icon, popup, level, push, visib if (push) { browserAction.stackPush(stackData, id); - } - else { + } else { browserAction.stackUnshift(stackData, id); } if (!dontShow) { - browserAction.show(null, {'id': id}); + browserAction.show(null, { 'id': id }); } }; @@ -142,17 +140,15 @@ browserAction.removeLevelFromStack = function(callback, tab, level, type, dontSh type = '<='; } - let newStack = []; + const newStack = []; for (const i of page.tabs[tab.id].stack) { - if ( - (type == '<' && i.level >= level) || - (type == '<=' && i.level > level) || - (type == '=' && i.level != level) || - (type == '==' && i.level != level) || - (type == '!=' && i.level == level) || - (type == '>' && i.level <= level) || - (type == '>=' && i.level < level) - ) { + if ((type === '<' && i.level >= level) || + (type === '<=' && i.level > level) || + (type === '=' && i.level !== level) || + (type === '==' && i.level !== level) || + (type === '!=' && i.level === level) || + (type === '>' && i.level <= level) || + (type === '>=' && i.level < level)) { newStack.push(i); } } @@ -199,10 +195,8 @@ browserAction.removeRememberPopup = function(callback, tab, removeImmediately) { browserAction.stackPop(tab.id); browserAction.show(null, {"id": tab.id}); page.clearCredentials(tab.id); - return; - } - else if (!isNaN(data.visibleForPageUpdates) && data.redirectOffset > 0 && currentMS >= data.redirectOffset) { - data.visibleForPageUpdates = data.visibleForPageUpdates - 1; + } else if (!isNaN(data.visibleForPageUpdates) && data.redirectOffset > 0 && currentMS >= data.redirectOffset) { + data.visibleForPageUpdates -= 1; } } }; @@ -256,17 +250,18 @@ browserAction.setRememberPopup = function(tabId, username, password, url, userna list: credentialsList }; - browserAction.show(null, {'id': id}); + browserAction.show(null, { 'id': id }); if (page.settings.showLoginNotifications) { const message = tr('rememberCredentialsPopup'); const buttons = [ - { - 'title': tr('popupButtonClose') - }, - { - 'title': tr('popupButtonIgnore') - }]; + { + 'title': tr('popupButtonClose') + }, + { + 'title': tr('popupButtonIgnore') + } + ]; browser.notifications.create({ 'type': 'basic', @@ -293,7 +288,7 @@ function getValueOrDefault(settings, key, defaultVal, min) { val = defaultVal; } return val; - } catch(e) { + } catch (e) { return defaultVal; } } @@ -312,16 +307,16 @@ browserAction.generateIconName = function(iconType, icon) { }; browserAction.ignoreSite = function(url) { - browser.windows.getCurrent().then((win) => { + browser.windows.getCurrent().then(() => { // Get current active window browser.tabs.query({ 'active': true, 'currentWindow': true }).then((tabs) => { const tab = tabs[0]; // Send the message to the current tab's content script - browser.runtime.getBackgroundPage().then((global) => { + browser.runtime.getBackgroundPage().then(() => { browser.tabs.sendMessage(tab.id, { - action: 'ignore-site', - args: [url] + action: 'ignore_site', + args: [ url ] }); }); }); diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index 2d6477b..921374f 100755 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -40,7 +40,7 @@ kpxcEvent.invoke = function(handler, callback, senderTabId, args, secondTime) { page.createTabEntry(senderTabId); } - // remove information from no longer existing tabs + // Remove information from no longer existing tabs page.removePageInformationFromNotExistingTabs(); browser.tabs.get(senderTabId).then((tab) => { @@ -70,8 +70,7 @@ kpxcEvent.invoke = function(handler, callback, senderTabId, args, secondTime) { if (handler) { handler.apply(this, args); - } - else { + } else { console.log('undefined handler for tab ' + tab.id); } }).catch((e) => { @@ -113,12 +112,12 @@ kpxcEvent.onLoadSettings = function(callback, tab) { }; kpxcEvent.onLoadKeyRing = function(callback, tab) { - browser.storage.local.get({'keyRing': {}}).then(function(item) { + browser.storage.local.get({ 'keyRing': {} }).then(function(item) { keepass.keyRing = item.keyRing; if (keepass.isAssociated() && !keepass.keyRing[keepass.associated.hash]) { keepass.associated = { - "value": false, - "hash": null + 'value': false, + 'hash': null }; } callback(item.keyRing); @@ -128,7 +127,7 @@ kpxcEvent.onLoadKeyRing = function(callback, tab) { }; kpxcEvent.onSaveSettings = function(callback, tab, settings) { - browser.storage.local.set({'settings': settings}).then(function() { + browser.storage.local.set({ 'settings': settings }).then(function() { kpxcEvent.onLoadSettings(callback, tab); }); }; @@ -168,9 +167,9 @@ kpxcEvent.onReconnect = function(callback, tab) { }; kpxcEvent.lockDatabase = function(callback, tab) { - keepass.lockDatabase(tab).then((response => { + keepass.lockDatabase(tab).then(() => { kpxcEvent.showStatus(true, tab, callback); - })); + }); }; kpxcEvent.onPopStack = function(callback, tab) { @@ -191,7 +190,7 @@ kpxcEvent.onGetConnectedDatabase = function(callback, tab) { }; kpxcEvent.onGetKeePassXCVersions = function(callback, tab) { - if (keepass.currentKeePassXC == '') { + if (keepass.currentKeePassXC === '') { keepass.getDatabaseHash((res) => { callback({'current': keepass.currentKeePassXC, 'latest': keepass.latestKeePassXC.version}); }, tab); @@ -229,7 +228,7 @@ kpxcEvent.onSetRememberPopup = function(callback, tab, username, password, url, }; kpxcEvent.onLoginPopup = function(callback, tab, logins) { - let stackData = { + const stackData = { level: 1, iconType: 'questionmark', popup: 'popup_login.html' @@ -245,7 +244,7 @@ kpxcEvent.initHttpAuth = function(callback) { } kpxcEvent.onHTTPAuthPopup = function(callback, tab, data) { - let stackData = { + const stackData = { level: 1, iconType: 'questionmark', popup: 'popup_httpauth.html' @@ -256,7 +255,7 @@ kpxcEvent.onHTTPAuthPopup = function(callback, tab, data) { }; kpxcEvent.onMultipleFieldsPopup = function(callback, tab) { - let stackData = { + const stackData = { level: 1, iconType: 'normal', popup: 'popup_multiple-fields.html' @@ -280,7 +279,7 @@ kpxcEvent.pageSetLoginId = function(callback, tab, loginId) { page.loginId = loginId; }; -// all methods named in this object have to be declared BEFORE this! +// All methods named in this object have to be declared BEFORE this! kpxcEvent.messageHandlers = { 'add_credentials': keepass.addCredentials, 'associate': keepass.associate, diff --git a/keepassxc-browser/background/httpauth.js b/keepassxc-browser/background/httpauth.js index f1fbba0..cf9caef 100755 --- a/keepassxc-browser/background/httpauth.js +++ b/keepassxc-browser/background/httpauth.js @@ -31,7 +31,7 @@ httpAuth.init = function() { }; httpAuth.requestCompleted = function(details) { - let index = httpAuth.requests.indexOf(details.requestId); + const index = httpAuth.requests.indexOf(details.requestId); if (index >= 0) { httpAuth.requests.splice(index, 1); } @@ -57,7 +57,7 @@ httpAuth.retrieveCredentials = function(tabId, url, submitUrl, forceCallback) { httpAuth.processPendingCallbacks = async function(details, resolve, reject) { if (httpAuth.requests.indexOf(details.requestId) >= 0 || !page.tabs[details.tabId]) { - reject({cancel: false}); + reject({ cancel: false }); return; } @@ -74,7 +74,7 @@ httpAuth.processPendingCallbacks = async function(details, resolve, reject) { }; httpAuth.loginOrShowCredentials = function(logins, details, resolve, reject) { - // at least one login found --> use first to login + // At least one login found --> use first to login if (logins.length > 0 && page.settings.autoFillAndSend) { if (logins.length === 1) { resolve({ @@ -89,9 +89,7 @@ httpAuth.loginOrShowCredentials = function(logins, details, resolve, reject) { } kpxcEvent.onHTTPAuthPopup(null, { 'id': details.tabId }, { 'logins': logins, 'url': details.searchUrl, 'resolve': resolve }); } - } - // no logins found - else { - reject({cancel: false}); + } else { + reject({ cancel: false }); // No logins found } }; diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 842217f..f4797c5 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -46,9 +46,9 @@ browser.tabs.onRemoved.addListener((tabId, removeInfo) => { * @param {object} activeInfo */ browser.tabs.onActivated.addListener((activeInfo) => { - // remove possible credentials from old tab information + // Remove possible credentials from old tab information page.clearCredentials(page.currentTabId, true); - browserAction.removeRememberPopup(null, {'id': page.currentTabId}, true); + browserAction.removeRememberPopup(null, { 'id': page.currentTabId }, true); browser.tabs.get(activeInfo.tabId).then((info) => { if (info && info.id) { @@ -81,14 +81,14 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { browser.runtime.onMessage.addListener(kpxcEvent.onMessage); const contextMenuItems = [ - {title: tr('contextMenuFillUsernameAndPassword'), action: 'fill_user_pass'}, - {title: tr('contextMenuFillPassword'), action: 'fill_pass_only'}, + {title: tr('contextMenuFillUsernameAndPassword'), action: 'fill_username_password'}, + {title: tr('contextMenuFillPassword'), action: 'fill_password'}, {title: tr('contextMenuFillTOTP'), action: 'fill_totp'}, {title: tr('contextMenuShowPasswordGeneratorIcons'), action: 'activate_password_generator'}, {title: tr('contextMenuSaveCredentials'), action: 'remember_credentials'} ]; -let menuContexts = ['editable']; +const menuContexts = ['editable']; if (isFirefox()) { menuContexts.push('password'); @@ -102,33 +102,19 @@ for (const item of contextMenuItems) { onclick: (info, tab) => { browser.tabs.sendMessage(tab.id, { action: item.action - }).catch((e) => {console.log(e);}); + }).catch((e) => { + console.log(e); + }); } }); } // Listen for keyboard shortcuts specified by user browser.commands.onCommand.addListener((command) => { - if (command === 'fill-username-password') { + if (contextMenuItems.some(e => e.action === command)) { browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { if (tabs.length) { - browser.tabs.sendMessage(tabs[0].id, { action: 'fill_user_pass' }); - } - }); - } - - if (command === 'fill-password') { - browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { - if (tabs.length) { - browser.tabs.sendMessage(tabs[0].id, { action: 'fill_pass_only' }); - } - }); - } - - if (command === 'fill-totp') { - browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { - if (tabs.length) { - browser.tabs.sendMessage(tabs[0].id, { action: 'fill_totp' }); + browser.tabs.sendMessage(tabs[0].id, { action: command }); } }); } diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index f813c63..8549fbc 100755 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -15,12 +15,12 @@ keepass.nativeHostName = 'org.keepassxc.keepassxc_browser'; keepass.nativePort = null; keepass.keySize = 24; keepass.latestVersionUrl = 'https://api.github.com/repos/keepassxreboot/keepassxc/releases/latest'; -keepass.cacheTimeout = 30 * 1000; // milliseconds +keepass.cacheTimeout = 30 * 1000; // Milliseconds keepass.databaseHash = ''; keepass.previousDatabaseHash = ''; keepass.keyId = 'keepassxc-browser-cryptokey-name'; keepass.keyBody = 'keepassxc-browser-key'; -keepass.messageTimeout = 500; // milliseconds +keepass.messageTimeout = 500; // Milliseconds keepass.nonce = nacl.util.encodeBase64(nacl.randomBytes(keepass.keySize)); const kpActions = { @@ -79,7 +79,7 @@ const kpErrors = { }; browser.storage.local.get({ - 'latestKeePassXC': {'version': '', 'lastChecked': null}, + 'latestKeePassXC': { 'version': '', 'lastChecked': null }, 'keyRing': {}}).then((item) => { keepass.latestKeePassXC = item.latestKeePassXC; keepass.keyRing = item.keyRing; @@ -88,11 +88,11 @@ browser.storage.local.get({ keepass.sendNativeMessage = function(request, enableTimeout = false) { return new Promise((resolve, reject) => { let timeout; - let action = request.action; - let ev = keepass.nativePort.onMessage; + const requestAction = request.action; + const ev = keepass.nativePort.onMessage; - let listener = ((port, action) => { - let handler = (msg) => { + const listener = ((port, action) => { + const handler = (msg) => { if (msg && msg.action === action) { port.removeListener(handler); if (enableTimeout) { @@ -102,7 +102,7 @@ keepass.sendNativeMessage = function(request, enableTimeout = false) { } }; return handler; - })(ev, action); + })(ev, requestAction); ev.addListener(listener); @@ -110,7 +110,7 @@ keepass.sendNativeMessage = function(request, enableTimeout = false) { if (enableTimeout) { timeout = setTimeout(() => { const errorMessage = { - action: action, + action: requestAction, error: kpErrors.getError(kpErrors.TIMEOUT_OR_NOT_CONNECTED), errorCode: kpErrors.TIMEOUT_OR_NOT_CONNECTED }; @@ -137,19 +137,19 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password, page.tabs[tab.id].errorMessage = null; } - keepass.testAssociation((response) => { - if (!response) { + keepass.testAssociation((taResponse) => { + if (!taResponse) { browserAction.showDefault(null, tab); callback([]); return; } const kpAction = kpActions.SET_LOGIN; - const {dbid} = keepass.getCryptoKey(); + const { dbid } = keepass.getCryptoKey(); const nonce = keepass.getNonce(); const incrementedNonce = keepass.incrementedNonce(nonce); - let messageData = { + const messageData = { action: kpAction, id: dbid, login: username, @@ -181,12 +181,10 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password, const message = nacl.util.encodeUTF8(res); const parsed = JSON.parse(message); callback(keepass.verifyResponse(parsed, incrementedNonce) ? 'success' : 'error'); - } - else if (response.error && response.errorCode) { + } else if (response.error && response.errorCode) { keepass.handleError(tab, response.errorCode, response.error); callback('error'); - } - else { + } else { browserAction.showDefault(null, tab); } }); @@ -219,16 +217,16 @@ keepass.retrieveCredentials = function(callback, tab, url, submiturl, forceCallb const kpAction = kpActions.GET_LOGINS; const nonce = keepass.getNonce(); const incrementedNonce = keepass.incrementedNonce(nonce); - const {dbid} = keepass.getCryptoKey(); + const { dbid } = keepass.getCryptoKey(); - for (let keyHash in keepass.keyRing) { + for (const keyHash in keepass.keyRing) { keys.push({ id: keepass.keyRing[keyHash].id, key: keepass.keyRing[keyHash].key }); } - let messageData = { + const messageData = { action: kpAction, id: dbid, url: url, @@ -267,21 +265,18 @@ keepass.retrieveCredentials = function(callback, tab, url, submiturl, forceCallb entries = parsed.entries; keepass.updateLastUsed(keepass.databaseHash); if (entries.length === 0) { - // questionmark-icon is not triggered, so we have to trigger for the normal symbol + // Questionmark-icon is not triggered, so we have to trigger for the normal symbol browserAction.showDefault(null, tab); } callback(entries); - } - else { + } else { console.log('RetrieveCredentials for ' + url + ' rejected'); } page.debug('keepass.retrieveCredentials() => entries.length = {1}', entries.length); - } - else if (response.error && response.errorCode) { + } else if (response.error && response.errorCode) { keepass.handleError(tab, response.errorCode, response.error); callback([]); - } - else { + } else { browserAction.showDefault(null, tab); callback([]); } @@ -337,17 +332,14 @@ keepass.generatePassword = function(callback, tab, forceCallback) { if (parsed.entries) { passwords = parsed.entries; keepass.updateLastUsed(keepass.databaseHash); - } - else { + } else { console.log('No entries returned. Is KeePassXC up-to-date?'); } - } - else { + } else { console.log('GeneratePassword rejected'); } callback(passwords); - } - else if (response.error && response.errorCode) { + } else if (response.error && response.errorCode) { keepass.handleError(tab, response.errorCode, response.error); } }); @@ -406,8 +398,7 @@ keepass.associate = function(callback, tab) { if (!keepass.verifyResponse(parsed, incrementedNonce)) { keepass.handleError(tab, kpErrors.ASSOCIATION_FAILED); - } - else { + } else { // Use public key as identification key with older KeePassXC releases const savedKey = keepass.compareVersion('2.3.4', keepass.currentKeePassXC) ? idKey : key; keepass.setCryptoKey(id, savedKey); // Save the new identification public key as id key for the database @@ -416,8 +407,7 @@ keepass.associate = function(callback, tab) { } browserAction.show(callback, tab); - } - else if (response.error && response.errorCode) { + } else if (response.error && response.errorCode) { keepass.handleError(tab, response.errorCode, response.error); } }); @@ -456,7 +446,7 @@ keepass.testAssociation = function(callback, tab, enableTimeout = false, trigger const kpAction = kpActions.TEST_ASSOCIATE; const nonce = keepass.getNonce(); const incrementedNonce = keepass.incrementedNonce(nonce); - const {dbid, dbkey} = keepass.getCryptoKey(); + const { dbid, dbkey } = keepass.getCryptoKey(); if (dbkey === null || dbid === null) { if (tab && page.tabs[tab.id]) { @@ -500,17 +490,14 @@ keepass.testAssociation = function(callback, tab, enableTimeout = false, trigger keepass.handleError(tab, kpErrors.ENCRYPTION_KEY_UNRECOGNIZED); keepass.associated.value = false; keepass.associated.hash = null; - } - else if (!keepass.isAssociated()) { + } else if (!keepass.isAssociated()) { keepass.handleError(tab, kpErrors.ASSOCIATION_FAILED); - } - else { + } else { if (tab && page.tabs[tab.id]) { delete page.tabs[tab.id].errorMessage; } } - } - else if (response.error && response.errorCode) { + } else if (response.error && response.errorCode) { keepass.handleError(tab, response.errorCode, response.error); } callback(keepass.isAssociated()); @@ -539,9 +526,9 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false, trigger const encrypted = keepass.encrypt(messageData, nonce); if (encrypted.length <= 0) { - keepass.handleError(tab, kpErrors.PUBLIC_KEY_NOT_FOUND); - callback(keepass.databaseHash); - return; + keepass.handleError(tab, kpErrors.PUBLIC_KEY_NOT_FOUND); + callback(keepass.databaseHash); + return; } const request = { @@ -580,23 +567,20 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false, trigger keepass.isKeePassXCAvailable = true; callback(parsed.hash); return; - } - else if (parsed.errorCode) { + } else if (parsed.errorCode) { keepass.databaseHash = ''; keepass.isDatabaseClosed = true; keepass.handleError(tab, kpErrors.DATABASE_NOT_OPENED); callback(keepass.databaseHash); return; } - } - else { + } else { keepass.databaseHash = ''; keepass.isDatabaseClosed = true; if (response.message && response.message === '') { keepass.isKeePassXCAvailable = false; keepass.handleError(tab, kpErrors.TIMEOUT_OR_NOT_CONNECTED); - } - else { + } else { keepass.handleError(tab, response.errorCode, response.error); } callback(keepass.databaseHash); @@ -633,8 +617,7 @@ keepass.changePublicKeys = function(tab, enableTimeout = false) { keepass.handleError(tab, kpErrors.KEY_CHANGE_FAILED); reject(false); } - } - else { + } else { keepass.isKeePassXCAvailable = true; console.log('Server public key: ' + nacl.util.encodeBase64(keepass.serverPublicKey)); } @@ -686,8 +669,7 @@ keepass.lockDatabase = function(tab) { keepass.handleError(tab, kpErrors.DATABASE_NOT_OPENED); resolve(true); } - } - else if (response.error && response.errorCode) { + } else if (response.error && response.errorCode) { keepass.isDatabaseClosed = true; keepass.handleError(tab, response.errorCode, response.error); } @@ -759,25 +741,24 @@ keepass.saveKey = function(hash, id, key) { created: new Date().valueOf(), lastUsed: new Date().valueOf() }; - } - else { + } else { keepass.keyRing[hash].id = id; keepass.keyRing[hash].key = key; keepass.keyRing[hash].hash = hash; } - browser.storage.local.set({'keyRing': keepass.keyRing}); + browser.storage.local.set({ 'keyRing': keepass.keyRing }); }; keepass.updateLastUsed = function(hash) { if ((hash in keepass.keyRing)) { keepass.keyRing[hash].lastUsed = new Date().valueOf(); - browser.storage.local.set({'keyRing': keepass.keyRing}); + browser.storage.local.set({ 'keyRing': keepass.keyRing }); } }; keepass.deleteKey = function(hash) { delete keepass.keyRing[hash]; - browser.storage.local.set({'keyRing': keepass.keyRing}); + browser.storage.local.set({ 'keyRing': keepass.keyRing }); }; keepass.setcurrentKeePassXCVersion = function(version) { @@ -789,7 +770,7 @@ keepass.setcurrentKeePassXCVersion = function(version) { keepass.keePassXCUpdateAvailable = function() { if (page.settings.checkUpdateKeePassXC && page.settings.checkUpdateKeePassXC > 0) { const lastChecked = (keepass.latestKeePassXC.lastChecked) ? new Date(keepass.latestKeePassXC.lastChecked) : new Date(1986, 11, 21); - const daysSinceLastCheck = Math.floor(((new Date()).getTime()-lastChecked.getTime())/86400000); + const daysSinceLastCheck = Math.floor(((new Date()).getTime() - lastChecked.getTime()) / 86400000); if (daysSinceLastCheck >= page.settings.checkUpdateKeePassXC) { keepass.checkForNewKeePassXCVersion(); } @@ -799,7 +780,7 @@ keepass.keePassXCUpdateAvailable = function() { }; keepass.checkForNewKeePassXCVersion = function() { - let xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); let version = -1; xhr.onload = function(e) { @@ -973,7 +954,7 @@ keepass.getCryptoKey = function() { let dbkey = null; let dbid = null; if (!(keepass.databaseHash in keepass.keyRing)) { - return {dbid, dbkey}; + return { dbid, dbkey }; } dbid = keepass.keyRing[keepass.databaseHash].id; @@ -982,7 +963,7 @@ keepass.getCryptoKey = function() { dbkey = keepass.keyRing[keepass.databaseHash].key; } - return {dbid, dbkey}; + return { dbid, dbkey }; }; keepass.setCryptoKey = function(id, key) { @@ -1046,7 +1027,7 @@ keepass.updatePopup = function(iconType) { if (page && page.tabs.length > 0) { const data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; data.iconType = iconType; - browserAction.show(null, {'id': page.currentTabId}); + browserAction.show(null, { 'id': page.currentTabId }); } }; diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 87da6b3..95c8884 100755 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -20,7 +20,7 @@ page.loginId = -1; page.initSettings = function() { return new Promise((resolve, reject) => { - browser.storage.local.get({'settings': {}}).then((item) => { + browser.storage.local.get({ 'settings': {} }).then((item) => { page.settings = item.settings; if (!('checkUpdateKeePassXC' in page.settings)) { page.settings.checkUpdateKeePassXC = defaultSettings.checkUpdateKeePassXC; @@ -62,14 +62,14 @@ page.initOpenedTabs = function() { page.createTabEntry(i.id); } - // set initial tab-ID - browser.tabs.query({ 'active': true, 'currentWindow': true }).then((tabs) => { - if (tabs.length === 0) { + // Set initial tab-ID + browser.tabs.query({ 'active': true, 'currentWindow': true }).then((t) => { + if (t.length === 0) { resolve(); return; // For example: only the background devtools or a popup are opened } - page.currentTabId = tabs[0].id; - browserAction.show(null, tabs[0]); + page.currentTabId = t[0].id; + browserAction.show(null, t[0]); resolve(); }); }); @@ -84,7 +84,7 @@ page.isValidProtocol = function(url) { page.switchTab = function(callback, tab) { browserAction.showDefault(null, tab); - browser.tabs.sendMessage(tab.id, {action: 'activated_tab'}).catch((e) => {}); + browser.tabs.sendMessage(tab.id, { action: 'activated_tab' }).catch((e) => {}); }; page.clearCredentials = function(tabId, complete) { @@ -121,18 +121,18 @@ page.createTabEntry = function(tabId) { }; page.removePageInformationFromNotExistingTabs = function() { - let rand = Math.floor(Math.random()*1001); + const rand = Math.floor(Math.random() * 1001); if (rand === 28) { browser.tabs.query({}).then(function(tabs) { - let $tabIds = []; - const $infoIds = Object.keys(page.tabs); + const tabIds = []; + const infoIds = Object.keys(page.tabs); for (const t of tabs) { - $tabIds[t.id] = true; + tabIds[t.id] = true; } - for (const i of $infoIds) { - if (!(i in $tabIds)) { + for (const i of infoIds) { + if (!(i in tabIds)) { delete page.tabs[i]; } } @@ -143,8 +143,7 @@ page.removePageInformationFromNotExistingTabs = function() { page.debugConsole = function() { if (arguments.length > 1) { console.log(page.sprintf(arguments[0], arguments)); - } - else { + } else { console.log(arguments[0]); } }; @@ -163,8 +162,7 @@ page.setDebug = function(bool) { if (bool) { page.debug = page.debugConsole; return 'Debug mode enabled'; - } - else { + } else { page.debug = page.debugDummy; return 'Debug mode disabled'; } diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index d9dff0c..93160dd 100755 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -1,2170 +1,2148 @@ -'use strict'; - -// contains already called method names -var _called = {}; -_called.retrieveCredentials = false; -_called.clearLogins = false; -_called.manualFillRequested = 'none'; -let _loginId = -1; -let _singleInputEnabledForPage = false; -const _maximumInputs = 100; - -// Count of detected form fields on the page -var _detectedFields = 0; - -// Element id's containing input fields detected by MutationObserver -var _observerIds = []; - -// Document URL -let _documentURL = document.location.href; - -function _f(fieldId) { - const field = (fieldId) ? jQuery('input[data-cip-id=\''+fieldId+'\']:first') : []; - return (field.length > 0) ? field : null; -} - -function _fs(fieldId) { - const field = (fieldId) ? jQuery('input[data-cip-id=\''+fieldId+'\']:first,select[data-cip-id=\''+fieldId+'\']:first').first() : []; - return (field.length > 0) ? field : null; -} - -browser.runtime.onMessage.addListener(function(req, sender, callback) { - if ('action' in req) { - if (req.action === 'fill_user_pass_with_specific_login') { - if (cip.credentials[req.id]) { - let combination = null; - if (cip.u) { - cip.setValueWithChange(cip.u, cip.credentials[req.id].login); - combination = cipFields.getCombination('username', cip.u); - 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); - browser.runtime.sendMessage({ - action: 'page_set_login_id', args: [req.id] - }); - combination = cipFields.getCombination('password', cip.p); - } - - let list = []; - if (cip.fillInStringFields(combination.fields, cip.credentials[req.id].stringFields, list)) { - cipForm.destroy(false, {'password': list.list[0], 'username': list.list[1]}); - } - } - } else if (req.action === 'fill_user_pass') { - _called.manualFillRequested = 'both'; - cip.receiveCredentialsIfNecessary().then((response) => { - cip.fillInFromActiveElement(false); - }); - } else if (req.action === 'fill_pass_only') { - _called.manualFillRequested = 'pass'; - cip.receiveCredentialsIfNecessary().then((response) => { - cip.fillInFromActiveElement(false, true); // passOnly to true - }); - } else if (req.action === 'fill_totp') { - cip.receiveCredentialsIfNecessary().then((response) => { - cip.fillInFromActiveElementTOTPOnly(false); - }); - } else if (req.action === 'activate_password_generator') { - cip.initPasswordGenerator(cipFields.getAllFields()); - } else if (req.action === 'remember_credentials') { - cip.contextMenuRememberCredentials(); - } else if (req.action === 'choose_credential_fields') { - cipDefine.init(); - } else if (req.action === 'clear_credentials') { - cipEvents.clearCredentials(); - return Promise.resolve(); - } else if (req.action === 'activated_tab') { - cipEvents.triggerActivatedTab(); - return Promise.resolve(); - } else if (req.action === 'redetect_fields') { - browser.runtime.sendMessage({ - action: 'load_settings', - }).then((response) => { - cip.settings = response; - cip.initCredentialFields(true); - }); - } else if (req.action === 'ignore-site') { - cip.ignoreSite(req.args); - } - else if (req.action === 'check_database_hash' && 'hash' in req) { - cip.detectDatabaseChange(req.hash); - } - } -}); - - -var cipAutocomplete = {}; - -// objects of username + description for autocomplete -cipAutocomplete.elements = []; - -cipAutocomplete.init = function(field) { - if (cip.settings.autoFillSingleEntry && cip.credentials.length === 1 && field.hasClass('ui-autocomplete-input')) { - field.autocomplete('destroy'); - } - - let acMenu = jQuery('#kpxc-ac-menu'); - if (acMenu.length == 0) { - jQuery('
').appendTo('body'); - } - - field - .addClass('kpxc') - .autocomplete({ - appendTo: '#kpxc-ac-menu', - minLength: 0, - source: cipAutocomplete.onSource, - select: cipAutocomplete.onSelect, - open: cipAutocomplete.onOpen - }); - field - .click(cipAutocomplete.onClick) - .blur(cipAutocomplete.onBlur) - .focus(cipAutocomplete.onFocus); -}; - -cipAutocomplete.onClick = function() { - jQuery(this).autocomplete('search', jQuery(this).val()); -}; - -cipAutocomplete.onOpen = function(event, ui) { - jQuery('ul.ui-autocomplete.ui-menu').css('z-index', 2147483636); -}; - -cipAutocomplete.onSource = function(request, callback) { - const matches = jQuery.map(cipAutocomplete.elements, (tag) => { - if (tag.label.toUpperCase().indexOf(request.term.toUpperCase()) === 0) { - return tag; - } - }); - callback(matches); -}; - -cipAutocomplete.onSelect = function(e, ui) { - e.preventDefault(); - cip.setValueWithChange(jQuery(this), ui.item.value); - const fieldId = cipFields.prepareId(jQuery(this).attr('data-cip-id')); - const combination = cipFields.getCombination('username', fieldId); - combination.loginId = ui.item.loginId; - cip.fillInCredentials(combination, true, false); - jQuery(this).data('fetched', true); -}; - -cipAutocomplete.onBlur = function() { - if (jQuery(this).data('fetched') === true) { - jQuery(this).data('fetched', false); - } - else { - const fieldId = cipFields.prepareId(jQuery(this).attr('data-cip-id')); - const fields = cipFields.getCombination('username', fieldId); - const fieldValue = jQuery(this).val(); - - // Check if the manually inserted value is one of the retrieved credentials - let fieldFound = cipAutocomplete.elements.some(e => e.value === fieldValue); - - if (_f(fields.password) && _f(fields.password).data('unchanged') !== true && fieldFound && _detectedFields > 1) { - cip.fillInCredentials(fields, true, true); - } - } -}; - -cipAutocomplete.onFocus = function() { - cip.u = jQuery(this); - - if (jQuery(this).val() === '') { - jQuery(this).autocomplete('search', ''); - } -}; - -var cipPassword = {}; -cipPassword.observedIcons = []; -cipPassword.observingLock = false; - -cipPassword.init = function() { - if ('initPasswordGenerator' in _called) { - return; - } - - _called.initPasswordGenerator = true; - - window.setInterval(function() { - cipPassword.checkObservedElements(); - }, 400); -}; - -cipPassword.initField = function(field, inputs, pos) { - if (!field || field.length !== 1) { - return; - } - if (field.data('cip-password-generator')) { - return; - } - - field.data('cip-password-generator', true); - - cipPassword.createIcon(field); - - let $found = false; - if (inputs) { - for (let i = pos + 1; i < inputs.length; i++) { - if (inputs[i] && inputs[i].attr('type') && inputs[i].attr('type').toLowerCase() === 'password') { - field.data('cip-genpw-next-field-id', inputs[i].data('cip-id')); - field.data('cip-genpw-next-is-password-field', (i === 0)); - $found = true; - break; - } - } - } - - field.data('cip-genpw-next-field-exists', $found); -}; - -cipPassword.createDialog = function() { - if ('passwordCreateDialog' in _called) { - return; - } - - _called.passwordCreateDialog = true; - - const $dialog = jQuery('
') - .addClass('dialog-form') - .attr('id', 'cip-genpw-dialog'); - - const $inputDiv = jQuery('
').addClass('form-group'); - const $inputGroup = jQuery('
').addClass('genpw-input-group'); - const $textfieldPassword = jQuery('') - .attr('id', 'cip-genpw-textfield-password') - .attr('type', 'text') - .attr('aria-describedby', 'cip-genpw-quality') - .attr('placeholder', tr('passwordGeneratorPlaceholder')) - .addClass('genpw-text ui-widget-content ui-corner-all') - .on('change keypress paste textInput input', function() { - jQuery('#cip-genpw-btn-clipboard:first').removeClass('btn-success'); - }); - const $quality = jQuery('') - .addClass('genpw-input-group-addon') - .addClass('b2c-add-on') - .attr('id', 'cip-genpw-quality') - .text(tr('passwordGeneratorBits')); - $inputGroup.append($textfieldPassword).append($quality); - - const $checkGroup = jQuery('
').addClass('genpw-input-group'); - const $checkboxNextField = jQuery('') - .attr('id', 'cip-genpw-checkbox-next-field') - .attr('type', 'checkbox') - .addClass('cip-genpw-checkbox'); - const $labelNextField = jQuery('