Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix updating reference passwords from KeePassXC-Browser #2218

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ void BrowserService::updateEntry(const QString& id,
return;
}

// Check if the entry password is a reference. If so, update the original entry instead
while (entry->attributes()->isReference(EntryAttributes::PasswordKey)) {
const QUuid referenceUuid = entry->attributes()->referenceUuid(EntryAttributes::PasswordKey);
if (!referenceUuid.isNull()) {
entry = db->rootGroup()->findEntryByUuid(referenceUuid);
if (!entry) {
return;
}
}
}

QString username = entry->username();
if (username.isEmpty()) {
return;
Expand All @@ -391,7 +402,9 @@ void BrowserService::updateEntry(const QString& id,

if (browserSettings()->alwaysAllowUpdate() || dialogResult == MessageBox::Save) {
entry->beginUpdate();
entry->setUsername(login);
if (!entry->attributes()->isReference(EntryAttributes::UserNameKey)) {
entry->setUsername(login);
}
entry->setPassword(password);
entry->endUpdate();
}
Expand Down
18 changes: 18 additions & 0 deletions src/core/EntryAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,24 @@ void EntryAttributes::copyDataFrom(const EntryAttributes* other)
}
}

QUuid EntryAttributes::referenceUuid(const QString& key) const
{
if (!m_attributes.contains(key)) {
Q_ASSERT(false);
return {};
}

auto match = matchReference(value(key));
if (match.hasMatch()) {
const QString uuid = match.captured("SearchText");
if (!uuid.isEmpty()) {
return QUuid::fromRfc4122(QByteArray::fromHex(uuid.toLatin1()));
}
}

return {};
}

bool EntryAttributes::operator==(const EntryAttributes& other) const
{
return (m_attributes == other.m_attributes && m_protectedAttributes == other.m_protectedAttributes);
Expand Down
2 changes: 2 additions & 0 deletions src/core/EntryAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QRegularExpression>
#include <QSet>
#include <QStringList>
#include <QUuid>

class EntryAttributes : public QObject
{
Expand All @@ -47,6 +48,7 @@ class EntryAttributes : public QObject
void clear();
int attributesSize() const;
void copyDataFrom(const EntryAttributes* other);
QUuid referenceUuid(const QString& key) const;
bool operator==(const EntryAttributes& other) const;
bool operator!=(const EntryAttributes& other) const;

Expand Down
1 change: 1 addition & 0 deletions tests/TestEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void TestEntry::testClone()
QCOMPARE(entryClonePassRef->timeInfo().creationTime(), entryOrgClone->timeInfo().creationTime());
QVERIFY(entryClonePassRef->attributes()->isReference(EntryAttributes::PasswordKey));
QCOMPARE(entryClonePassRef->resolvePlaceholder(entryCloneUserRef->password()), entryOrg->password());
QCOMPARE(entryClonePassRef->attributes()->referenceUuid(EntryAttributes::PasswordKey), entryOrgClone->uuid());
}

void TestEntry::testResolveUrl()
Expand Down