mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Merge pull request #1393 from keepassxreboot/hotfix/kdbx4-attachments
Correct missing attachments in KDBX 4 write
This commit is contained in:
commit
edb7b56f1a
@ -152,6 +152,9 @@ bool Kdbx4Writer::writeDatabase(QIODevice* device, Database* db)
|
|||||||
CHECK_RETURN_FALSE(writeInnerHeaderField(outputDevice, KeePass2::InnerHeaderFieldID::InnerRandomStreamKey,
|
CHECK_RETURN_FALSE(writeInnerHeaderField(outputDevice, KeePass2::InnerHeaderFieldID::InnerRandomStreamKey,
|
||||||
protectedStreamKey));
|
protectedStreamKey));
|
||||||
|
|
||||||
|
// Write attachments to the inner header
|
||||||
|
writeAttachments(outputDevice, db);
|
||||||
|
|
||||||
CHECK_RETURN_FALSE(writeInnerHeaderField(outputDevice, KeePass2::InnerHeaderFieldID::End, QByteArray()));
|
CHECK_RETURN_FALSE(writeInnerHeaderField(outputDevice, KeePass2::InnerHeaderFieldID::End, QByteArray()));
|
||||||
|
|
||||||
KeePass2RandomStream randomStream(KeePass2::ProtectedStreamAlgo::ChaCha20);
|
KeePass2RandomStream randomStream(KeePass2::ProtectedStreamAlgo::ChaCha20);
|
||||||
@ -204,24 +207,17 @@ bool Kdbx4Writer::writeInnerHeaderField(QIODevice* device, KeePass2::InnerHeader
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void Kdbx4Writer::writeAttachments(QIODevice* device, Database* db)
|
||||||
* Write binary header field..
|
|
||||||
*
|
|
||||||
* @param device output device
|
|
||||||
* @param fieldId field identifier
|
|
||||||
* @param data header payload
|
|
||||||
* @return true on success
|
|
||||||
*/
|
|
||||||
bool Kdbx4Writer::writeBinary(QIODevice* device, const QByteArray& data)
|
|
||||||
{
|
{
|
||||||
QByteArray fieldIdArr;
|
const QList<Entry*> allEntries = db->rootGroup()->entriesRecursive(true);
|
||||||
fieldIdArr[0] = static_cast<char>(KeePass2::InnerHeaderFieldID::Binary);
|
for (Entry* entry : allEntries) {
|
||||||
CHECK_RETURN_FALSE(writeData(device, fieldIdArr));
|
const QList<QString> attachmentKeys = entry->attachments()->keys();
|
||||||
CHECK_RETURN_FALSE(writeData(device, Endian::sizedIntToBytes(static_cast<quint32>(data.size() + 1), KeePass2::BYTEORDER)));
|
for (const QString& key : attachmentKeys) {
|
||||||
CHECK_RETURN_FALSE(writeData(device, QByteArray(1, '\1')));
|
QByteArray data = entry->attachments()->value(key);
|
||||||
CHECK_RETURN_FALSE(writeData(device, data));
|
data.prepend("\x01");
|
||||||
|
writeInnerHeaderField(device, KeePass2::InnerHeaderFieldID::Binary, data);
|
||||||
return true;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool writeInnerHeaderField(QIODevice* device, KeePass2::InnerHeaderFieldID fieldId, const QByteArray& data);
|
bool writeInnerHeaderField(QIODevice* device, KeePass2::InnerHeaderFieldID fieldId, const QByteArray& data);
|
||||||
bool writeBinary(QIODevice* device, const QByteArray& data);
|
void writeAttachments(QIODevice* device, Database* db);
|
||||||
static bool serializeVariantMap(const QVariantMap& map, QByteArray& outputBytes);
|
static bool serializeVariantMap(const QVariantMap& map, QByteArray& outputBytes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user