Ignore non-connected databases from search with Browser Integration (#1810)

This commit is contained in:
Sami Vänttinen 2018-05-04 23:06:07 +03:00 committed by Jonathan White
parent a910821506
commit 658298bc31
3 changed files with 29 additions and 8 deletions

View File

@ -240,9 +240,17 @@ QJsonObject BrowserAction::handleGetLogins(const QJsonObject& json, const QStrin
return getErrorReply(action, ERROR_KEEPASS_NO_URL_PROVIDED);
}
const QJsonArray keys = decrypted.value("keys").toArray();
StringPairList keyList;
for (const QJsonValue val : keys) {
const QJsonObject keyObject = val.toObject();
keyList.push_back(qMakePair(keyObject.value("id").toString(), keyObject.value("key").toString()));
}
const QString id = decrypted.value("id").toString();
const QString submit = decrypted.value("submitUrl").toString();
const QJsonArray users = m_browserService.findMatchingEntries(id, url, submit, "");
const QJsonArray users = m_browserService.findMatchingEntries(id, url, submit, "", keyList);
if (users.isEmpty()) {
return getErrorReply(action, ERROR_KEEPASS_NO_LOGINS_FOUND);

View File

@ -224,7 +224,7 @@ QString BrowserService::getKey(const QString& id)
return config->attributes()->value(QLatin1String(ASSOCIATE_KEY_PREFIX) + id);
}
QJsonArray BrowserService::findMatchingEntries(const QString& id, const QString& url, const QString& submitUrl, const QString& realm)
QJsonArray BrowserService::findMatchingEntries(const QString& id, const QString& url, const QString& submitUrl, const QString& realm, const StringPairList& keyList)
{
QJsonArray result;
if (thread() != QThread::currentThread()) {
@ -233,7 +233,8 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id, const QString&
Q_ARG(const QString&, id),
Q_ARG(const QString&, url),
Q_ARG(const QString&, submitUrl),
Q_ARG(const QString&, realm));
Q_ARG(const QString&, realm),
Q_ARG(const StringPairList&, keyList));
return result;
}
@ -244,7 +245,7 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id, const QString&
// Check entries for authorization
QList<Entry*> pwEntriesToConfirm;
QList<Entry*> pwEntries;
for (Entry* entry : searchEntries(url)) {
for (Entry* entry : searchEntries(url, keyList)) {
switch (checkAccess(entry, host, submitHost, realm)) {
case Denied:
continue;
@ -381,7 +382,7 @@ QList<Entry*> BrowserService::searchEntries(Database* db, const QString& hostnam
return entries;
}
QList<Entry*> BrowserService::searchEntries(const QString& text)
QList<Entry*> BrowserService::searchEntries(const QString& text, const StringPairList& keyList)
{
// Get the list of databases to search
QList<Database*> databases;
@ -390,7 +391,16 @@ QList<Entry*> BrowserService::searchEntries(const QString& text)
for (int i = 0; i < count; ++i) {
if (DatabaseWidget* dbWidget = qobject_cast<DatabaseWidget*>(m_dbTabWidget->widget(i))) {
if (Database* db = dbWidget->database()) {
databases << db;
// Check if database is connected with KeePassXC-Browser
for (const StringPair keyPair : keyList) {
Entry* entry = db->resolveEntry(KEEPASSXCBROWSER_UUID);
if (entry) {
QString key = entry->attributes()->value(QLatin1String(ASSOCIATE_KEY_PREFIX) + keyPair.first);
if (!key.isEmpty() && keyPair.second == key) {
databases << db;
}
}
}
}
}
}

View File

@ -25,6 +25,9 @@
#include "gui/DatabaseTabWidget.h"
#include "core/Entry.h"
typedef QPair<QString, QString> StringPair;
typedef QList<StringPair> StringPairList;
class BrowserService : public QObject
{
Q_OBJECT
@ -40,12 +43,12 @@ public:
QString getKey(const QString& id);
void addEntry(const QString& id, const QString& login, const QString& password, const QString& url, const QString& submitUrl, const QString& realm);
QList<Entry*> searchEntries(Database* db, const QString& hostname);
QList<Entry*> searchEntries(const QString& text);
QList<Entry*> searchEntries(const QString& text, const StringPairList& keyList);
void removeSharedEncryptionKeys();
void removeStoredPermissions();
public slots:
QJsonArray findMatchingEntries(const QString& id, const QString& url, const QString& submitUrl, const QString& realm);
QJsonArray findMatchingEntries(const QString& id, const QString& url, const QString& submitUrl, const QString& realm, const StringPairList& keyList);
QString storeKey(const QString& key);
void updateEntry(const QString& id, const QString& uuid, const QString& login, const QString& password, const QString& url);
void databaseLocked(DatabaseWidget* dbWidget);