Skip to content

Commit

Permalink
Adding OnlyKey support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
onlykey authored and droidmonkey committed Jul 7, 2019
1 parent c669ecb commit 2a8b52a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/keys/YkChallengeResponseKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/keys/drivers/YubiKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <ykcore.h>
#include <ykdef.h>
#include <ykpers-version.h>
#include <ykstatus.h>
#include <yubikey.h>

Expand All @@ -37,6 +38,7 @@
YubiKey::YubiKey()
: m_yk_void(nullptr)
, m_ykds_void(nullptr)
, m_onlyKey(false)
, m_mutex(QMutex::Recursive)
{
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/keys/drivers/YubiKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class YubiKey : public QObject
*/
bool getSerial(unsigned int& serial);

/**
* @brief YubiKey::getVendorName - vendor name of token
* @return vendor name
*/
QString getVendorName();

/**
* @brief YubiKey::detect - probe for attached YubiKeys
*/
Expand Down Expand Up @@ -110,6 +116,7 @@ class YubiKey : public QObject
// Create void ptr here to avoid ifdef header include mess
void* m_yk_void;
void* m_ykds_void;
bool m_onlyKey;

QMutex m_mutex;

Expand Down

0 comments on commit 2a8b52a

Please sign in to comment.