20
#include "TestYkChallengeResponseKey.h"
22
#include "core/Tools.h"
23
#include "crypto/Crypto.h"
24
#include "keys/ChallengeResponseKey.h"
26
#include <QCryptographicHash>
30
QTEST_GUILESS_MAIN(TestYubiKeyChallengeResponse)
32
void TestYubiKeyChallengeResponse::initTestCase()
35
QVERIFY(Crypto::init());
37
if (!YubiKey::instance()->isInitialized()) {
38
QSKIP("Unable to initialize YubiKey interface.");
42
void TestYubiKeyChallengeResponse::testDetectDevices()
44
YubiKey::instance()->findValidKeys();
47
const auto foundKeys = YubiKey::instance()->foundKeys();
48
for (auto i = foundKeys.cbegin(); i != foundKeys.cend(); ++i) {
49
const auto& displayName = i.value();
50
QVERIFY(displayName.contains("Challenge-Response - Slot") || displayName.contains("Configured Slot -"));
51
QVERIFY(displayName.contains(QString::number(i.key().first)));
52
QVERIFY(displayName.contains(QString::number(i.key().second)));
61
void TestYubiKeyChallengeResponse::testKeyChallenge()
63
auto keys = YubiKey::instance()->foundKeys().keys();
65
QSKIP("No YubiKey devices were detected.");
69
bool wouldBlock = false;
70
YubiKeySlot pKey(0, 0);
71
for (auto key : keys) {
72
if (YubiKey::instance()->testChallenge(key, &wouldBlock) && !wouldBlock) {
79
if (pKey.first == 0) {
81
QSKIP("No YubiKey contains a slot in passive mode.");
84
QScopedPointer<ChallengeResponseKey> key(new ChallengeResponseKey(pKey));
86
QByteArray ba("UnitTest");
87
QVERIFY(key->challenge(ba));
88
QCOMPARE(key->rawKey().size(), 20);
89
auto hash = QString(QCryptographicHash::hash(key->rawKey(), QCryptographicHash::Sha256).toHex());
90
QCOMPARE(hash, QString("2f7802c7112c301303526e7737b54d546c905076dca6e9538edf761a2264cd70"));