From 2a8b52a014a6a9fa8cc234c20b1dee7b056bee68 Mon Sep 17 00:00:00 2001 From: onlykey Date: Mon, 1 Jul 2019 10:56:28 -0400 Subject: [PATCH] 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. --- src/keys/YkChallengeResponseKey.cpp | 8 +++++--- src/keys/drivers/YubiKey.cpp | 17 +++++++++++++++++ src/keys/drivers/YubiKey.h | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/keys/YkChallengeResponseKey.cpp b/src/keys/YkChallengeResponseKey.cpp index 03328ef74..3af12e422 100644 --- a/src/keys/YkChallengeResponseKey.cpp +++ b/src/keys/YkChallengeResponseKey.cpp @@ -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 diff --git a/src/keys/drivers/YubiKey.cpp b/src/keys/drivers/YubiKey.cpp index b4aa82205..042d2d1c2 100644 --- a/src/keys/drivers/YubiKey.cpp +++ b/src/keys/drivers/YubiKey.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -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(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(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 diff --git a/src/keys/drivers/YubiKey.h b/src/keys/drivers/YubiKey.h index 420e650b5..ef05b9479 100644 --- a/src/keys/drivers/YubiKey.h +++ b/src/keys/drivers/YubiKey.h @@ -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;