YubiKey: Clean-up master seed challenge

* Tweak the logic so it more closely resembles other code (i.e.
  trasnformKey()). Matches existing style better.
* Save the challengeResponseKey in the database structure so that
  it can be referred to later (i.e. database unlocking).

Signed-off-by: Kyle Manna <kyle@kylemanna.com>
This commit is contained in:
Kyle Manna 2014-09-07 16:37:46 -07:00
parent 62190d79be
commit 77cc99acd3
4 changed files with 14 additions and 9 deletions

View File

@ -176,9 +176,14 @@ QByteArray Database::transformedMasterKey() const
return m_data.transformedMasterKey; return m_data.transformedMasterKey;
} }
bool Database::challengeMasterSeed(const QByteArray& masterSeed, QByteArray& result) const QByteArray Database::challengeResponseKey() const
{ {
return m_data.key.challenge(masterSeed, result); return m_data.challengeResponseKey;
}
bool Database::challengeMasterSeed(const QByteArray& masterSeed)
{
return m_data.key.challenge(masterSeed, m_data.challengeResponseKey);
} }
void Database::setCipher(const Uuid& cipher) void Database::setCipher(const Uuid& cipher)

View File

@ -59,6 +59,7 @@ public:
QByteArray transformedMasterKey; QByteArray transformedMasterKey;
CompositeKey key; CompositeKey key;
bool hasKey; bool hasKey;
QByteArray challengeResponseKey;
}; };
Database(); Database();
@ -89,7 +90,8 @@ public:
quint64 transformRounds() const; quint64 transformRounds() const;
QByteArray transformedMasterKey() const; QByteArray transformedMasterKey() const;
const CompositeKey & key() const; const CompositeKey & key() const;
bool challengeMasterSeed(const QByteArray& masterSeed, QByteArray& result) const; QByteArray challengeResponseKey() const;
bool challengeMasterSeed(const QByteArray& masterSeed);
void setCipher(const Uuid& cipher); void setCipher(const Uuid& cipher);
void setCompressionAlgo(Database::CompressionAlgorithm algo); void setCompressionAlgo(Database::CompressionAlgorithm algo);

View File

@ -113,15 +113,14 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
return nullptr; return nullptr;
} }
QByteArray challengeResult; if (m_db->challengeMasterSeed(m_masterSeed) == false) {
if (m_db->challengeMasterSeed(m_masterSeed, challengeResult) == false) {
raiseError(tr("Unable to issue challenge-response.")); raiseError(tr("Unable to issue challenge-response."));
return Q_NULLPTR; return Q_NULLPTR;
} }
CryptoHash hash(CryptoHash::Sha256); CryptoHash hash(CryptoHash::Sha256);
hash.addData(m_masterSeed); hash.addData(m_masterSeed);
hash.addData(challengeResult); hash.addData(m_db->challengeResponseKey());
hash.addData(m_db->transformedMasterKey()); hash.addData(m_db->transformedMasterKey());
QByteArray finalKey = hash.result(); QByteArray finalKey = hash.result();

View File

@ -51,15 +51,14 @@ void KeePass2Writer::writeDatabase(QIODevice* device, Database* db)
QByteArray startBytes = randomGen()->randomArray(32); QByteArray startBytes = randomGen()->randomArray(32);
QByteArray endOfHeader = "\r\n\r\n"; QByteArray endOfHeader = "\r\n\r\n";
QByteArray challengeResult; if (db->challengeMasterSeed(masterSeed) == false) {
if (db->challengeMasterSeed(masterSeed, challengeResult) == false) {
raiseError("Unable to issue challenge-response."); raiseError("Unable to issue challenge-response.");
return; return;
} }
CryptoHash hash(CryptoHash::Sha256); CryptoHash hash(CryptoHash::Sha256);
hash.addData(masterSeed); hash.addData(masterSeed);
hash.addData(challengeResult); hash.addData(db->challengeResponseKey());
Q_ASSERT(!db->transformedMasterKey().isEmpty()); Q_ASSERT(!db->transformedMasterKey().isEmpty());
hash.addData(db->transformedMasterKey()); hash.addData(db->transformedMasterKey());
QByteArray finalKey = hash.result(); QByteArray finalKey = hash.result();