mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-27 23:07:11 -05:00
Don't upgrade to KDBX 4 when CustomData are present only in meta data section, resolves #1565
This commit is contained in:
parent
2e8846ef8d
commit
0d4aff55bc
@ -129,9 +129,7 @@ void KdbxXmlWriter::writeMetadata()
|
|||||||
if (m_kdbxVersion < KeePass2::FILE_VERSION_4) {
|
if (m_kdbxVersion < KeePass2::FILE_VERSION_4) {
|
||||||
writeBinaries();
|
writeBinaries();
|
||||||
}
|
}
|
||||||
if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) {
|
writeCustomData(m_meta->customData());
|
||||||
writeCustomData(m_meta->customData());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_xml.writeEndElement();
|
m_xml.writeEndElement();
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,36 @@ bool KeePass2Writer::writeDatabase(const QString& filename, Database* db)
|
|||||||
return writeDatabase(&file, db);
|
return writeDatabase(&file, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the database should upgrade to KDBX4.
|
||||||
|
*/
|
||||||
|
bool KeePass2Writer::implicitUpgradeNeeded(Database const* db) const
|
||||||
|
{
|
||||||
|
if (!db->publicCustomData().isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& group: db->rootGroup()->groupsRecursive(true)) {
|
||||||
|
if (group->customData() && !group->customData()->isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& entry: group->entries()) {
|
||||||
|
if (entry->customData() && !entry->customData()->isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& historyItem: entry->historyItems()) {
|
||||||
|
if (historyItem->customData() && !historyItem->customData()->isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a database to a device in KDBX format.
|
* Write a database to a device in KDBX format.
|
||||||
*
|
*
|
||||||
@ -55,19 +85,7 @@ bool KeePass2Writer::writeDatabase(QIODevice* device, Database* db) {
|
|||||||
m_error = false;
|
m_error = false;
|
||||||
m_errorStr.clear();
|
m_errorStr.clear();
|
||||||
|
|
||||||
// determine KDBX3 vs KDBX4
|
if (db->kdf()->uuid() == KeePass2::KDF_AES_KDBX3 && !implicitUpgradeNeeded(db)) {
|
||||||
bool hasCustomData = !db->publicCustomData().isEmpty() || (db->metadata()->customData() && !db->metadata()->customData()->isEmpty());
|
|
||||||
if (!hasCustomData) {
|
|
||||||
for (const auto& entry: db->rootGroup()->entriesRecursive(true)) {
|
|
||||||
if ((entry->customData() && !entry->customData()->isEmpty()) ||
|
|
||||||
(entry->group() && entry->group()->customData() && !entry->group()->customData()->isEmpty())) {
|
|
||||||
hasCustomData = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db->kdf()->uuid() == KeePass2::KDF_AES_KDBX3 && !hasCustomData) {
|
|
||||||
m_version = KeePass2::FILE_VERSION_3_1;
|
m_version = KeePass2::FILE_VERSION_3_1;
|
||||||
m_writer.reset(new Kdbx3Writer());
|
m_writer.reset(new Kdbx3Writer());
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void raiseError(const QString& errorMessage);
|
void raiseError(const QString& errorMessage);
|
||||||
|
bool implicitUpgradeNeeded(Database const* db) const;
|
||||||
|
|
||||||
bool m_error = false;
|
bool m_error = false;
|
||||||
QString m_errorStr = "";
|
QString m_errorStr = "";
|
||||||
|
@ -149,8 +149,10 @@ void TestKdbx4::testFormat400Upgrade()
|
|||||||
sourceDb->changeKdf(KeePass2::uuidToKdf(kdfUuid));
|
sourceDb->changeKdf(KeePass2::uuidToKdf(kdfUuid));
|
||||||
sourceDb->setCipher(cipherUuid);
|
sourceDb->setCipher(cipherUuid);
|
||||||
|
|
||||||
|
// CustomData in meta should not cause any version change
|
||||||
|
sourceDb->metadata()->customData()->set("CustomPublicData", "Hey look, I turned myself into a pickle!");
|
||||||
if (addCustomData) {
|
if (addCustomData) {
|
||||||
sourceDb->metadata()->customData()->set("CustomPublicData", "Hey look, I turned myself into a pickle!");
|
// this, however, should
|
||||||
sourceDb->rootGroup()->customData()->set("CustomGroupData", "I just killed my family! I don't care who they were!");
|
sourceDb->rootGroup()->customData()->set("CustomGroupData", "I just killed my family! I don't care who they were!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user