Adding OnlyKey support

This adds support for OnlyKey and requires yubikey-personalization library 1.20.0 or newer. The function yk_open_key_vid_pid was added to yubikey-personalization in version 1.20.0.
This commit is contained in:
onlykey 2019-07-01 10:56:28 -04:00 committed by Jonathan White
parent c669ecb4dd
commit 2a8b52a014
3 changed files with 29 additions and 3 deletions

View File

@ -106,12 +106,14 @@ bool YkChallengeResponseKey::challenge(const QByteArray& challenge, unsigned int
QString YkChallengeResponseKey::getName() const
{
unsigned int serial;
QString fmt(QObject::tr("YubiKey[%1] Challenge Response - Slot %2 - %3"));
QString fmt(QObject::tr("%1[%2] Challenge Response - Slot %3 - %4"));
YubiKey::instance()->getSerial(serial);
return fmt.arg(
QString::number(serial), QString::number(m_slot), (m_blocking) ? QObject::tr("Press") : QObject::tr("Passive"));
return fmt.arg(YubiKey::instance()->getVendorName(),
QString::number(serial),
QString::number(m_slot),
(m_blocking) ? QObject::tr("Press") : QObject::tr("Passive"));
}
bool YkChallengeResponseKey::isBlocking() const

View File

@ -20,6 +20,7 @@
#include <ykcore.h>
#include <ykdef.h>
#include <ykpers-version.h>
#include <ykstatus.h>
#include <yubikey.h>
@ -37,6 +38,7 @@
YubiKey::YubiKey()
: m_yk_void(nullptr)
, m_ykds_void(nullptr)
, m_onlyKey(false)
, m_mutex(QMutex::Recursive)
{
}
@ -75,7 +77,17 @@ bool YubiKey::init()
}
// TODO: handle multiple attached hardware devices
m_onlyKey = false;
m_yk_void = static_cast<void*>(yk_open_first_key());
#if YKPERS_VERSION_NUMBER >= 0x011400
// New fuction available in yubikey-personalization version >= 1.20.0 that allows
// selecting device VID/PID (yk_open_key_vid_pid)
if (m_yk == nullptr) {
static const int device_pids[] = {0x60fc}; // OnlyKey PID
m_yk_void = static_cast<void*>(yk_open_key_vid_pid(0x1d50, device_pids, 1, 0));
m_onlyKey = true;
}
#endif
if (m_yk == nullptr) {
yk_release();
m_mutex.unlock();
@ -163,6 +175,11 @@ bool YubiKey::getSerial(unsigned int& serial)
return true;
}
QString YubiKey::getVendorName()
{
return m_onlyKey ? "OnlyKey" : "YubiKey";
}
YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByteArray& challenge, QByteArray& response)
{
// ensure that YubiKey::init() succeeded

View File

@ -79,6 +79,12 @@ public:
*/
bool getSerial(unsigned int& serial);
/**
* @brief YubiKey::getVendorName - vendor name of token
* @return vendor name
*/
QString getVendorName();
/**
* @brief YubiKey::detect - probe for attached YubiKeys
*/
@ -110,6 +116,7 @@ private:
// Create void ptr here to avoid ifdef header include mess
void* m_yk_void;
void* m_ykds_void;
bool m_onlyKey;
QMutex m_mutex;