Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Regenerate transform seed and transform master key on save. #1068

Merged
merged 1 commit into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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