mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
Fix challenge-response key data after Botan
* Fix #6420 * Refactor Challenge-Response key files to be more streamlined. Added a test to confirm raw key data is accurate.
This commit is contained in:
@@ -22,8 +22,9 @@
|
||||
|
||||
#include "core/Tools.h"
|
||||
#include "crypto/Crypto.h"
|
||||
#include "keys/YkChallengeResponseKey.h"
|
||||
#include "keys/ChallengeResponseKey.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QScopedPointer>
|
||||
#include <QSignalSpy>
|
||||
|
||||
@@ -50,7 +51,7 @@ void TestYubiKeyChallengeResponse::testDetectDevices()
|
||||
// Look at the information retrieved from the key(s)
|
||||
for (auto key : YubiKey::instance()->foundKeys()) {
|
||||
auto displayName = YubiKey::instance()->getDisplayName(key);
|
||||
QVERIFY(displayName.contains("Challenge Response - Slot") || displayName.contains("Configured Slot -"));
|
||||
QVERIFY(displayName.contains("Challenge-Response - Slot") || displayName.contains("Configured Slot -"));
|
||||
QVERIFY(displayName.contains(QString::number(key.first)));
|
||||
QVERIFY(displayName.contains(QString::number(key.second)));
|
||||
}
|
||||
@@ -84,9 +85,11 @@ void TestYubiKeyChallengeResponse::testKeyChallenge()
|
||||
QSKIP("No YubiKey contains a slot in passive mode.");
|
||||
}
|
||||
|
||||
QScopedPointer<YkChallengeResponseKey> key(new YkChallengeResponseKey(pKey));
|
||||
QScopedPointer<ChallengeResponseKey> key(new ChallengeResponseKey(pKey));
|
||||
|
||||
QByteArray ba("UnitTest");
|
||||
QVERIFY(key->challenge(ba));
|
||||
QCOMPARE(key->rawKey().size(), 20UL);
|
||||
QCOMPARE(key->rawKey().size(), 20);
|
||||
auto hash = QString(QCryptographicHash::hash(key->rawKey(), QCryptographicHash::Sha256).toHex());
|
||||
QCOMPARE(hash, QString("2f7802c7112c301303526e7737b54d546c905076dca6e9538edf761a2264cd70"));
|
||||
}
|
||||
|
||||
@@ -18,22 +18,18 @@
|
||||
#include "MockChallengeResponseKey.h"
|
||||
|
||||
MockChallengeResponseKey::MockChallengeResponseKey(const QByteArray& secret)
|
||||
: ChallengeResponseKey(QUuid("aac5b480-cdc0-411e-9cb8-962062dcc1fd"))
|
||||
: ChallengeResponseKey()
|
||||
, m_secret(secret)
|
||||
{
|
||||
}
|
||||
|
||||
MockChallengeResponseKey::~MockChallengeResponseKey()
|
||||
QByteArray MockChallengeResponseKey::rawKey() const
|
||||
{
|
||||
return m_challenge + m_secret;
|
||||
}
|
||||
|
||||
bool MockChallengeResponseKey::challenge(const QByteArray& challenge)
|
||||
{
|
||||
m_challenge = challenge;
|
||||
|
||||
auto response = m_challenge + m_secret;
|
||||
m_key.resize(response.size());
|
||||
std::copy(response.begin(), response.end(), m_key.data());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,13 +28,17 @@ class MockChallengeResponseKey : public ChallengeResponseKey
|
||||
{
|
||||
public:
|
||||
explicit MockChallengeResponseKey(const QByteArray& secret);
|
||||
Q_DISABLE_COPY(MockChallengeResponseKey);
|
||||
~MockChallengeResponseKey() override;
|
||||
~MockChallengeResponseKey() override = default;
|
||||
|
||||
QByteArray rawKey() const override;
|
||||
|
||||
bool challenge(const QByteArray& challenge) override;
|
||||
|
||||
private:
|
||||
QByteArray m_challenge;
|
||||
QByteArray m_secret;
|
||||
|
||||
Q_DISABLE_COPY(MockChallengeResponseKey);
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_MOCKCHALLENGERESPONSEKEY_H
|
||||
|
||||
Reference in New Issue
Block a user