mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-13 08:19:50 -05:00
Upgrade to KDBX 4 if new 4.1 features are used
This commit is contained in:
parent
835e31ac3c
commit
c872e406ed
@ -18,6 +18,7 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
#include "core/Group.h"
|
#include "core/Group.h"
|
||||||
|
#include "core/Metadata.h"
|
||||||
#include "format/Kdbx3Writer.h"
|
#include "format/Kdbx3Writer.h"
|
||||||
#include "format/Kdbx4Writer.h"
|
#include "format/Kdbx4Writer.h"
|
||||||
#include "format/KeePass2Writer.h"
|
#include "format/KeePass2Writer.h"
|
||||||
@ -42,7 +43,7 @@ bool KeePass2Writer::writeDatabase(const QString& filename, Database* db)
|
|||||||
/**
|
/**
|
||||||
* @return true if the database should upgrade to KDBX4.
|
* @return true if the database should upgrade to KDBX4.
|
||||||
*/
|
*/
|
||||||
bool KeePass2Writer::implicitUpgradeNeeded(Database const* db) const
|
bool KeePass2Writer::implicitKDBXUpgradeNeeded(Database const* db)
|
||||||
{
|
{
|
||||||
if (db->kdf()->uuid() != KeePass2::KDF_AES_KDBX3) {
|
if (db->kdf()->uuid() != KeePass2::KDF_AES_KDBX3) {
|
||||||
return false;
|
return false;
|
||||||
@ -56,11 +57,23 @@ bool KeePass2Writer::implicitUpgradeNeeded(Database const* db) const
|
|||||||
if (group->customData() && !group->customData()->isEmpty()) {
|
if (group->customData() && !group->customData()->isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!group->tags().isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (group->previousParentGroup()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& entry : group->entries()) {
|
for (const auto& entry : group->entries()) {
|
||||||
if (entry->customData() && !entry->customData()->isEmpty()) {
|
if (entry->customData() && !entry->customData()->isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (entry->excludeFromReports()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (entry->previousParentGroup()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& historyItem : entry->historyItems()) {
|
for (const auto& historyItem : entry->historyItems()) {
|
||||||
if (historyItem->customData() && !historyItem->customData()->isEmpty()) {
|
if (historyItem->customData() && !historyItem->customData()->isEmpty()) {
|
||||||
@ -70,6 +83,14 @@ bool KeePass2Writer::implicitUpgradeNeeded(Database const* db) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<QUuid> customIconsOrder = db->metadata()->customIconsOrder();
|
||||||
|
for (const QUuid& uuid : customIconsOrder) {
|
||||||
|
const auto& icon = db->metadata()->customIcon(uuid);
|
||||||
|
if (!icon.name.isEmpty() || icon.lastModified.isValid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +106,7 @@ bool KeePass2Writer::writeDatabase(QIODevice* device, Database* db)
|
|||||||
m_error = false;
|
m_error = false;
|
||||||
m_errorStr.clear();
|
m_errorStr.clear();
|
||||||
|
|
||||||
bool upgradeNeeded = implicitUpgradeNeeded(db);
|
bool upgradeNeeded = implicitKDBXUpgradeNeeded(db);
|
||||||
if (upgradeNeeded) {
|
if (upgradeNeeded) {
|
||||||
// We MUST re-transform the key, because challenge-response hashing has changed in KDBX 4.
|
// We MUST re-transform the key, because challenge-response hashing has changed in KDBX 4.
|
||||||
// If we forget to re-transform, the database will be saved WITHOUT a challenge-response key component!
|
// If we forget to re-transform, the database will be saved WITHOUT a challenge-response key component!
|
||||||
|
@ -33,6 +33,7 @@ public:
|
|||||||
bool writeDatabase(const QString& filename, Database* db);
|
bool writeDatabase(const QString& filename, Database* db);
|
||||||
bool writeDatabase(QIODevice* device, Database* db);
|
bool writeDatabase(QIODevice* device, Database* db);
|
||||||
void extractDatabase(Database* db, QByteArray& xmlOutput);
|
void extractDatabase(Database* db, QByteArray& xmlOutput);
|
||||||
|
static bool implicitKDBXUpgradeNeeded(Database const* db);
|
||||||
|
|
||||||
QSharedPointer<KdbxWriter> writer() const;
|
QSharedPointer<KdbxWriter> writer() const;
|
||||||
quint32 version() const;
|
quint32 version() const;
|
||||||
@ -42,7 +43,6 @@ 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 = "";
|
||||||
|
Loading…
Reference in New Issue
Block a user