Fix KDBX minor version mismatch warning after reading header

- Keep the KDBX version from the file header when setKdf() runs during open.
- Add testMinorVersionMismatchAfterSetKdf to prevent regressions.
This commit is contained in:
tikisan_ authored and GitHub committed 2026-11-12 23:12:52 +01:00
1 parent 6bcb901aef
commit b1715d81c1
9 files changed
+59 -9

No files matched your search

+1 -1
View File
@@ -3638,7 +3638,7 @@ Would you like to correct it?</source>
<context>
<name>EditGroupWidgetBrowser</name>
<message>
<source>These settings affect to the group&apos;s behaviour with the browser extension.</source>
<source>These settings affect the group&apos;s behaviour with the browser extension.</source>
<translation type="unfinished"></translation>
</message>
<message>
+4 -1
View File
@@ -1126,7 +1126,8 @@ QSharedPointer<Kdf> Database::kdf() const
void Database::setKdf(QSharedPointer<Kdf> kdf)
{
m_data.kdf = std::move(kdf);
setFormatVersion(KeePass2Writer::kdbxVersionRequired(this, true, m_data.kdf.isNull()));
// Preserve the KDBX version from the file header when loading (see #13974).
setFormatVersion(KeePass2Writer::kdbxVersionRequired(this, false, m_data.kdf.isNull()));
}
bool Database::changeKdf(const QSharedPointer<Kdf>& kdf)
@@ -1141,6 +1142,8 @@ bool Database::changeKdf(const QSharedPointer<Kdf>& kdf)
}
setKdf(kdf);
// Recalculate format version for intentional KDF change (e.g. KDBX 3 downgrade).
setFormatVersion(KeePass2Writer::kdbxVersionRequired(this, true));
m_data.transformedDatabaseKey->setRawKey(transformedDatabaseKey);
markAsModified();
+1 -1
View File
@@ -26,7 +26,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>These settings affect to the group's behaviour with the browser extension.</string>
<string>These settings affect the group's behaviour with the browser extension.</string>
</property>
</widget>
</item>
+1 -1
View File
@@ -69,7 +69,7 @@ namespace Phantom
//
// If you need to update the hsluv-c code, be mindful of the removed sRGB
// conversions -- you will need to make similar modifications to the upstream
// hsluv-c code. Also note that that the hpluv (pastel) functions have been
// hsluv-c code. Also note that the hpluv (pastel) functions have been
// removed, as they are not used in Phantom.
typedef struct Triplet_tag Triplet;
struct Triplet_tag
+1 -1
View File
@@ -746,7 +746,7 @@ YubiKey::ChallengeResult YubiKeyInterfacePCSC::performChallenge(void* key,
*
* In fact, the Yubikey always assumes the last byte (nr. 64)
* and all bytes of the same value preceding it to be padding.
* This does not conform fully to PKCS7, because the the actual value
* This does not conform fully to PKCS7, because the actual value
* of the padding bytes is ignored.
*/
const int padLen = 64 - paddedChallenge.size();
+3 -3
View File
@@ -140,7 +140,7 @@ void QtIOCompressorPrivate::flushZlib(int flushMode)
ZlibSize outputSize = bufferSize - zlibStream.avail_out;
// Try to write data from the buffer to to the underlying device, return on failure.
// Try to write data from the buffer to the underlying device, return on failure.
if (!writeBytes(buffer, outputSize))
return;
@@ -528,7 +528,7 @@ qint64 QtIOCompressor::readData(char *data, qint64 maxSize)
int status;
do {
// Read data if if the input buffer is empty. There could be data in the buffer
// Read data if the input buffer is empty. There could be data in the buffer
// from a previous readData call.
if (d->zlibStream.avail_in == 0) {
qint64 bytesAvailable = d->device->read(reinterpret_cast<char *>(d->buffer), d->bufferSize);
@@ -605,7 +605,7 @@ qint64 QtIOCompressor::writeData(const char *data, qint64 maxSize)
ZlibSize outputSize = d->bufferSize - d->zlibStream.avail_out;
// Try to write data from the buffer to to the underlying device, return -1 on failure.
// Try to write data from the buffer to the underlying device, return -1 on failure.
if (d->writeBytes(d->buffer, outputSize) == false)
return -1;
+1 -1
View File
@@ -592,7 +592,7 @@ void TestCli::testAttachmentRemove()
QVERIFY(!attachmentRemoveCmd.name.isEmpty());
QVERIFY(attachmentRemoveCmd.getDescriptionLine().contains(attachmentRemoveCmd.name));
// Try deleting an attachment belonging to an non-existent entry
// Try deleting an attachment belonging to a non-existent entry
setInput("a");
execCmd(attachmentRemoveCmd,
{"attachment-rm", m_dbFile->fileName(), "invalid_entry_path", "invalid_attachment_name"});
+45
View File
@@ -611,3 +611,48 @@ void TestKdbx4Format::testCustomData()
QCOMPARE(newEntry->customData()->value(customDataKey1), customData1);
QCOMPARE(newEntry->customData()->value(customDataKey2), customData2);
}
void TestKdbx4Format::testMinorVersionMismatchAfterSetKdf()
{
const quint32 futureVersion = KeePass2::FILE_VERSION_MAX + 1;
Database db;
// Simulate KdbxReader reading a newer minor version from the file header.
db.setFormatVersion(futureVersion);
// Simulate Kdbx4Reader applying KDF parameters from the header.
db.setKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2D));
QCOMPARE(db.formatVersion(), futureVersion);
QVERIFY(db.hasMinorVersionMismatch());
Database supportedDb;
supportedDb.setFormatVersion(KeePass2::FILE_VERSION_4_1);
supportedDb.setKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2D));
QCOMPARE(supportedDb.formatVersion(), KeePass2::FILE_VERSION_4_1);
QVERIFY(!supportedDb.hasMinorVersionMismatch());
}
void TestKdbx4Format::testChangeKdfDowngradesToKdbx3()
{
auto key = QSharedPointer<CompositeKey>::create();
key->addKey(QSharedPointer<PasswordKey>::create("test"));
Database db;
db.setKey(key, true, true);
db.changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2D)));
QCOMPARE(db.formatVersion(), KeePass2::FILE_VERSION_4);
db.changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX3)));
QCOMPARE(db.formatVersion(), KeePass2::FILE_VERSION_3_1);
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
KeePass2Writer writer;
QVERIFY(writer.writeDatabase(&buffer, &db));
buffer.seek(0);
KeePass2Reader reader;
Database reopened;
QVERIFY(reader.readDatabase(&buffer, key, &reopened));
QCOMPARE(reader.version(), KeePass2::FILE_VERSION_3_1);
QCOMPARE(reopened.kdf()->uuid(), KeePass2::KDF_AES_KDBX3);
}
+2
View File
@@ -67,6 +67,8 @@ private slots:
void testUpgradeMasterKeyIntegrity_data();
void testAttachmentIndexStability();
void testCustomData();
void testMinorVersionMismatchAfterSetKdf();
void testChangeKdfDowngradesToKdbx3();
};
#endif // KEEPASSXC_TEST_KDBX4_H