2014-05-26 03:46:41 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Kyle Manna <kyle@kylemanna.com>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2014-05-26 03:46:41 -04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TestYkChallengeResponseKey.h"
|
2018-01-24 07:22:20 -05:00
|
|
|
#include "TestGlobal.h"
|
|
|
|
#include "crypto/Crypto.h"
|
2014-05-26 03:46:41 -04:00
|
|
|
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestYubiKeyChalResp)
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::initTestCase()
|
|
|
|
{
|
2017-02-24 15:00:48 -05:00
|
|
|
// crypto subsystem needs to be initialized for YubiKey testing
|
|
|
|
QVERIFY(Crypto::init());
|
2014-05-26 03:46:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::init()
|
|
|
|
{
|
2018-01-24 07:22:20 -05:00
|
|
|
if (!YubiKey::instance()->init()) {
|
|
|
|
QSKIP("Unable to connect to YubiKey");
|
2014-05-26 03:46:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::detectDevices()
|
|
|
|
{
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(YubiKey::instance(), SIGNAL(detected(int, bool)), SLOT(ykDetected(int, bool)), Qt::QueuedConnection);
|
2014-05-26 03:46:41 -04:00
|
|
|
QtConcurrent::run(YubiKey::instance(), &YubiKey::detect);
|
|
|
|
|
2017-02-24 14:44:06 -05:00
|
|
|
// need to wait for the hardware (that's hopefully plugged in)...
|
2014-05-26 03:46:41 -04:00
|
|
|
QTest::qWait(2000);
|
|
|
|
QVERIFY2(m_detected > 0, "Is a YubiKey attached?");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::getSerial()
|
|
|
|
{
|
|
|
|
unsigned int serial;
|
|
|
|
QVERIFY(YubiKey::instance()->getSerial(serial));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::keyGetName()
|
|
|
|
{
|
|
|
|
QVERIFY(m_key);
|
|
|
|
QVERIFY(m_key->getName().length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::keyIssueChallenge()
|
|
|
|
{
|
|
|
|
QVERIFY(m_key);
|
|
|
|
if (m_key->isBlocking()) {
|
|
|
|
/* Testing active mode in unit tests is unreasonable */
|
|
|
|
QSKIP("YubiKey not in passive mode", SkipSingle);
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray ba("UnitTest");
|
|
|
|
QVERIFY(m_key->challenge(ba));
|
|
|
|
|
|
|
|
/* TODO Determine if it's reasonable to provide a fixed secret key for
|
|
|
|
* verification testing. Obviously simple technically, but annoying
|
|
|
|
* if devs need to re-program their yubikeys or have a spare test key
|
2019-09-21 12:31:44 -04:00
|
|
|
* for unit tests to pass.
|
2014-05-26 03:46:41 -04:00
|
|
|
*
|
|
|
|
* Might be worth it for integrity verification though.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::ykDetected(int slot, bool blocking)
|
|
|
|
{
|
|
|
|
Q_UNUSED(blocking);
|
|
|
|
|
|
|
|
if (slot > 0)
|
|
|
|
m_detected++;
|
|
|
|
|
|
|
|
/* Key used for later testing */
|
|
|
|
if (!m_key)
|
2018-01-24 07:22:20 -05:00
|
|
|
m_key.reset(new YkChallengeResponseKey(slot, blocking));
|
2014-05-26 03:46:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestYubiKeyChalResp::deinit()
|
|
|
|
{
|
|
|
|
QVERIFY(YubiKey::instance()->deinit());
|
|
|
|
}
|