Fix updating reference passwords from KeePassXC-Browser (#2218)

* Allow updating reference passwords

* Fix function change after refactor
This commit is contained in:
Sami Vänttinen 2019-01-21 21:24:57 +02:00 committed by Jonathan White
parent 94430c300b
commit 0da9efdbd4
4 changed files with 35 additions and 1 deletions

View File

@ -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;
@ -391,7 +402,9 @@ void BrowserService::updateEntry(const QString& id,
if (browserSettings()->alwaysAllowUpdate() || dialogResult == MessageBox::Save) {
entry->beginUpdate();
if (!entry->attributes()->isReference(EntryAttributes::UserNameKey)) {
entry->setUsername(login);
}
entry->setPassword(password);
entry->endUpdate();
}

View File

@ -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);

View File

@ -24,6 +24,7 @@
#include <QRegularExpression>
#include <QSet>
#include <QStringList>
#include <QUuid>
class EntryAttributes : public QObject
{
@ -47,6 +48,7 @@ public:
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;

View File

@ -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()