Fix Yubikey detection in Database Settings/Wizard

* Fixes #2608
This commit is contained in:
Jonathan White 2019-02-01 17:38:40 -05:00
parent c9f91b2de5
commit ca39f6e159
2 changed files with 13 additions and 7 deletions

View File

@ -79,9 +79,9 @@ QWidget* YubiKeyEditWidget::componentEditWidget()
// clang-format off // clang-format off
connect(YubiKey::instance(), SIGNAL(detected(int,bool)), SLOT(yubikeyDetected(int,bool)), Qt::QueuedConnection); connect(YubiKey::instance(), SIGNAL(detected(int,bool)), SLOT(yubikeyDetected(int,bool)), Qt::QueuedConnection);
// clang-format on connect(YubiKey::instance(), SIGNAL(detectComplete()), SLOT(yubikeyDetectComplete()), Qt::QueuedConnection);
connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection); connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection);
// clang-format on
pollYubikey(); pollYubikey();
#endif #endif
@ -102,9 +102,11 @@ void YubiKeyEditWidget::pollYubikey()
if (!m_compEditWidget) { if (!m_compEditWidget) {
return; return;
} }
m_isDetected = false;
m_compUi->comboChallengeResponse->clear();
m_compUi->buttonRedetectYubikey->setEnabled(false); m_compUi->buttonRedetectYubikey->setEnabled(false);
m_compUi->comboChallengeResponse->setEnabled(false); m_compUi->comboChallengeResponse->setEnabled(false);
m_compUi->comboChallengeResponse->clear();
m_compUi->yubikeyProgress->setVisible(true); m_compUi->yubikeyProgress->setVisible(true);
// YubiKey init is slow, detect asynchronously to not block the UI // YubiKey init is slow, detect asynchronously to not block the UI
@ -119,12 +121,8 @@ void YubiKeyEditWidget::yubikeyDetected(int slot, bool blocking)
return; return;
} }
YkChallengeResponseKey yk(slot, blocking); YkChallengeResponseKey yk(slot, blocking);
m_compUi->comboChallengeResponse->clear();
// add detected YubiKey to combo box and encode blocking mode in LSB, slot number in second LSB // add detected YubiKey to combo box and encode blocking mode in LSB, slot number in second LSB
m_compUi->comboChallengeResponse->addItem(yk.getName(), QVariant((slot << 1u) | blocking)); m_compUi->comboChallengeResponse->addItem(yk.getName(), QVariant((slot << 1u) | blocking));
m_compUi->comboChallengeResponse->setEnabled(true);
m_compUi->buttonRedetectYubikey->setEnabled(true);
m_compUi->yubikeyProgress->setVisible(false);
m_isDetected = true; m_isDetected = true;
#else #else
Q_UNUSED(slot); Q_UNUSED(slot);
@ -132,6 +130,13 @@ void YubiKeyEditWidget::yubikeyDetected(int slot, bool blocking)
#endif #endif
} }
void YubiKeyEditWidget::yubikeyDetectComplete()
{
m_compUi->comboChallengeResponse->setEnabled(true);
m_compUi->buttonRedetectYubikey->setEnabled(true);
m_compUi->yubikeyProgress->setVisible(false);
}
void YubiKeyEditWidget::noYubikeyFound() void YubiKeyEditWidget::noYubikeyFound()
{ {
#ifdef WITH_XC_YUBIKEY #ifdef WITH_XC_YUBIKEY

View File

@ -46,6 +46,7 @@ protected:
private slots: private slots:
void yubikeyDetected(int slot, bool blocking); void yubikeyDetected(int slot, bool blocking);
void yubikeyDetectComplete();
void noYubikeyFound(); void noYubikeyFound();
void pollYubikey(); void pollYubikey();