Skip to content

Commit

Permalink
Fix: Regenerate transform seed and transform master key on save.
Browse files Browse the repository at this point in the history
  • Loading branch information
rockihack authored and droidmonkey committed Oct 19, 2017
1 parent 3bc8a79 commit c6f83b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,25 @@ bool Database::hasKey() const
return m_data.hasKey;
}

bool Database::transformKeyWithSeed(const QByteArray& transformSeed)
{
Q_ASSERT(hasKey());

bool ok;
QString errorString;

QByteArray transformedMasterKey =
m_data.key.transform(transformSeed, transformRounds(), &ok, &errorString);
if (!ok) {
return false;
}

m_data.transformSeed = transformSeed;
m_data.transformedMasterKey = transformedMasterKey;

return true;
}

bool Database::verifyKey(const CompositeKey& key) const
{
Q_ASSERT(hasKey());
Expand Down
1 change: 1 addition & 0 deletions src/core/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Database : public QObject
*/
bool setKey(const CompositeKey& key);
bool hasKey() const;
bool transformKeyWithSeed(const QByteArray& transformSeed);
bool verifyKey(const CompositeKey& key) const;
void recycleEntry(Entry* entry);
void recycleGroup(Group* group);
Expand Down
8 changes: 7 additions & 1 deletion src/format/KeePass2Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ void KeePass2Writer::writeDatabase(QIODevice* device, Database* db)
m_error = false;
m_errorStr.clear();

QByteArray transformSeed = randomGen()->randomArray(32);
QByteArray masterSeed = randomGen()->randomArray(32);
QByteArray encryptionIV = randomGen()->randomArray(16);
QByteArray protectedStreamKey = randomGen()->randomArray(32);
QByteArray startBytes = randomGen()->randomArray(32);
QByteArray endOfHeader = "\r\n\r\n";

if (db->challengeMasterSeed(masterSeed) == false) {
raiseError("Unable to issue challenge-response.");
raiseError(tr("Unable to issue challenge-response."));
return;
}

if (!db->transformKeyWithSeed(transformSeed)) {
raiseError(tr("Unable to calculate master key"));
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/format/KeePass2Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef KEEPASSX_KEEPASS2WRITER_H
#define KEEPASSX_KEEPASS2WRITER_H

#include <QCoreApplication>

#include "format/KeePass2.h"
#include "keys/CompositeKey.h"

Expand All @@ -26,6 +28,8 @@ class QIODevice;

class KeePass2Writer
{
Q_DECLARE_TR_FUNCTIONS(KeePass2Writer)

public:
KeePass2Writer();
void writeDatabase(QIODevice* device, Database* db);
Expand Down

0 comments on commit c6f83b9

Please sign in to comment.