keys: CompositeKey: Add ChallengeResponseKey support

* Each Challenge Response Key consists of a list of regular keys and now
  challenge response keys.
* Copy ChallengeResponseKeys when copying the object.
* Challenge consists of challenging each driver in the list and hashing
  the concatenated data result using SHA256.

Signed-off-by: Kyle Manna <kyle@kylemanna.com>
This commit is contained in:
Kyle Manna 2014-05-26 01:38:07 -07:00
parent 9bdb41a727
commit ccd6704b8f
2 changed files with 34 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "CompositeKey.h"
#include "CompositeKey_p.h"
#include "ChallengeResponseKey.h"
#include <QtConcurrent>
#include <QElapsedTimer>
@ -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);

View File

@ -21,6 +21,7 @@
#include <QList>
#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<Key*> m_keys;
QList<ChallengeResponseKey*> m_challengeResponseKeys;
};
#endif // KEEPASSX_COMPOSITEKEY_H