Implement KDBX 4.1 PasswordQuality flag

This commit is contained in:
Janek Bevendorff 2021-11-09 21:14:12 +01:00
parent 035757e228
commit ffaeac130f
7 changed files with 25 additions and 5 deletions

Binary file not shown.

View File

@ -24,7 +24,7 @@ const QString CustomData::LastModified = QStringLiteral("_LAST_MODIFIED");
const QString CustomData::Created = QStringLiteral("_CREATED"); const QString CustomData::Created = QStringLiteral("_CREATED");
const QString CustomData::BrowserKeyPrefix = QStringLiteral("KPXC_BROWSER_"); const QString CustomData::BrowserKeyPrefix = QStringLiteral("KPXC_BROWSER_");
const QString CustomData::BrowserLegacyKeyPrefix = QStringLiteral("Public Key: "); const QString CustomData::BrowserLegacyKeyPrefix = QStringLiteral("Public Key: ");
const QString CustomData::ExcludeFromReports = QStringLiteral("KnownBad"); const QString CustomData::ExcludeFromReportsLegacy = QStringLiteral("KnownBad");
CustomData::CustomData(QObject* parent) CustomData::CustomData(QObject* parent)
: ModifiableObject(parent) : ModifiableObject(parent)

View File

@ -51,7 +51,7 @@ public:
static const QString Created; static const QString Created;
static const QString BrowserKeyPrefix; static const QString BrowserKeyPrefix;
static const QString BrowserLegacyKeyPrefix; static const QString BrowserLegacyKeyPrefix;
static const QString ExcludeFromReports; static const QString ExcludeFromReportsLegacy; // Pre-KDBX 4.1
signals: signals:
void aboutToBeAdded(const QString& key); void aboutToBeAdded(const QString& key);

View File

@ -46,6 +46,7 @@ Entry::Entry()
m_data.iconNumber = DefaultIconNumber; m_data.iconNumber = DefaultIconNumber;
m_data.autoTypeEnabled = true; m_data.autoTypeEnabled = true;
m_data.autoTypeObfuscation = 0; m_data.autoTypeObfuscation = 0;
m_data.excludeFromReports = false;
connect(m_attributes, &EntryAttributes::modified, this, &Entry::updateTotp); connect(m_attributes, &EntryAttributes::modified, this, &Entry::updateTotp);
connect(m_attributes, &EntryAttributes::modified, this, &Entry::modified); connect(m_attributes, &EntryAttributes::modified, this, &Entry::modified);
@ -219,13 +220,14 @@ const QSharedPointer<PasswordHealth>& Entry::passwordHealth()
bool Entry::excludeFromReports() const bool Entry::excludeFromReports() const
{ {
return customData()->contains(CustomData::ExcludeFromReports) return m_data.excludeFromReports
&& customData()->value(CustomData::ExcludeFromReports) == TRUE_STR; || (customData()->contains(CustomData::ExcludeFromReportsLegacy)
&& customData()->value(CustomData::ExcludeFromReportsLegacy) == TRUE_STR);
} }
void Entry::setExcludeFromReports(bool state) void Entry::setExcludeFromReports(bool state)
{ {
customData()->set(CustomData::ExcludeFromReports, state ? TRUE_STR : FALSE_STR); set(m_data.excludeFromReports, state);
} }
/** /**
@ -1433,6 +1435,9 @@ bool EntryData::equals(const EntryData& other, CompareItemOptions options) const
// The existance of TOTP has changed between these entries // The existance of TOTP has changed between these entries
return false; return false;
} }
if (::compare(excludeFromReports, other.excludeFromReports, options) != 0) {
return false;
}
return true; return true;
} }

View File

@ -65,6 +65,7 @@ struct EntryData
TimeInfo timeInfo; TimeInfo timeInfo;
QSharedPointer<Totp::Settings> totpSettings; QSharedPointer<Totp::Settings> totpSettings;
QSharedPointer<PasswordHealth> passwordHealth; QSharedPointer<PasswordHealth> passwordHealth;
bool excludeFromReports;
bool operator==(const EntryData& other) const; bool operator==(const EntryData& other) const;
bool operator!=(const EntryData& other) const; bool operator!=(const EntryData& other) const;

View File

@ -726,6 +726,10 @@ Entry* KdbxXmlReader::parseEntry(bool history)
parseEntryString(entry); parseEntryString(entry);
continue; continue;
} }
if (m_xml.name() == "QualityCheck") {
entry->setExcludeFromReports(!readBool());
continue;
}
if (m_xml.name() == "Binary") { if (m_xml.name() == "Binary") {
QPair<QString, QString> ref = parseEntryBinary(entry); QPair<QString, QString> ref = parseEntryBinary(entry);
if (!ref.first.isEmpty() && !ref.second.isEmpty()) { if (!ref.first.isEmpty() && !ref.second.isEmpty()) {
@ -747,6 +751,13 @@ Entry* KdbxXmlReader::parseEntry(bool history)
} }
if (m_xml.name() == "CustomData") { if (m_xml.name() == "CustomData") {
parseCustomData(entry->customData()); parseCustomData(entry->customData());
// Upgrade pre-KDBX-4.1 password report exclude flag
if (entry->customData()->contains(CustomData::ExcludeFromReportsLegacy)) {
entry->setExcludeFromReports(entry->customData()->value(CustomData::ExcludeFromReportsLegacy)
== TRUE_STR);
entry->customData()->remove(CustomData::ExcludeFromReportsLegacy);
}
continue; continue;
} }
skipCurrentElement(); skipCurrentElement();

View File

@ -344,6 +344,9 @@ void KdbxXmlWriter::writeEntry(const Entry* entry)
writeString("OverrideURL", entry->overrideUrl()); writeString("OverrideURL", entry->overrideUrl());
writeString("Tags", entry->tags()); writeString("Tags", entry->tags());
writeTimes(entry->timeInfo()); writeTimes(entry->timeInfo());
if (entry->excludeFromReports()) {
writeBool("QualityCheck", false);
}
const QList<QString> attributesKeyList = entry->attributes()->keys(); const QList<QString> attributesKeyList = entry->attributes()->keys();
for (const QString& key : attributesKeyList) { for (const QString& key : attributesKeyList) {