diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp index 16b48592e..2270d96eb 100644 --- a/src/keys/CompositeKey.cpp +++ b/src/keys/CompositeKey.cpp @@ -17,6 +17,7 @@ #include "CompositeKey.h" #include "CompositeKey_p.h" +#include "ChallengeResponseKey.h" #include #include @@ -47,7 +48,7 @@ void CompositeKey::clear() bool CompositeKey::isEmpty() const { - return m_keys.isEmpty(); + return m_keys.isEmpty() && m_challengeResponseKeys.isEmpty(); } CompositeKey* CompositeKey::clone() const @@ -67,6 +68,9 @@ CompositeKey& CompositeKey::operator=(const CompositeKey& key) for (const Key* subKey : asConst(key.m_keys)) { addKey(*subKey); } + Q_FOREACH (const ChallengeResponseKey* subKey, key.m_challengeResponseKeys) { + addChallengeResponseKey(*subKey); + } return *this; } @@ -142,11 +146,35 @@ QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray return result; } +QByteArray CompositeKey::challenge(const QByteArray& seed) const +{ + /* If no challenge response was requested, return nothing to + * maintain backwards compatability with regular databases. + */ + if (m_challengeResponseKeys.length() == 0) { + return QByteArray(); + } + + CryptoHash cryptoHash(CryptoHash::Sha256); + + Q_FOREACH (ChallengeResponseKey* key, m_challengeResponseKeys) { + key->challenge(seed); + cryptoHash.addData(key->rawKey()); + } + + return cryptoHash.result(); +} + void CompositeKey::addKey(const Key& key) { m_keys.append(key.clone()); } +void CompositeKey::addChallengeResponseKey(const ChallengeResponseKey& key) +{ + m_challengeResponseKeys.append(key.clone()); +} + int CompositeKey::transformKeyBenchmark(int msec) { TransformKeyBenchmarkThread thread1(msec); diff --git a/src/keys/CompositeKey.h b/src/keys/CompositeKey.h index 3290d3671..66ad91ad9 100644 --- a/src/keys/CompositeKey.h +++ b/src/keys/CompositeKey.h @@ -21,6 +21,7 @@ #include #include "keys/Key.h" +#include "keys/ChallengeResponseKey.h" class CompositeKey : public Key { @@ -36,7 +37,10 @@ public: QByteArray rawKey() const; QByteArray transform(const QByteArray& seed, quint64 rounds, bool* ok, QString* errorString) const; + QByteArray challenge(const QByteArray& seed) const; + void addKey(const Key& key); + void addChallengeResponseKey(const ChallengeResponseKey& key); static int transformKeyBenchmark(int msec); @@ -45,6 +49,7 @@ private: quint64 rounds, bool* ok, QString* errorString); QList m_keys; + QList m_challengeResponseKeys; }; #endif // KEEPASSX_COMPOSITEKEY_H