mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-12-02 23:02:41 -08:00
Fix issues with Hardware Key auto detection
* Fix #10656 - Add a small delay when before auto-polling hardware keys to all them to settle immediately after plugging in. This resolves an issue where the key's serial number could not be resolved due to hardware timeout. * Also fix use of uninitialized variable if polling serial number fails for whatever reason. * Fix typo in macOS key registration code * Prevent registering duplicate listeners on window focus. These were not de-registered because we didn't trigger on unfocus. Show/Hide are sufficient triggers to add and remove listeners.
This commit is contained in:
1 parent
83623c896f
commit
3ace4c6cf5
3 files changed
+44
-33
No files matched your search
@@ -159,51 +159,50 @@ void DatabaseOpenWidget::toggleHardwareKeyComponent(bool state)
|
||||
bool DatabaseOpenWidget::event(QEvent* event)
|
||||
{
|
||||
bool ret = DialogyWidget::event(event);
|
||||
auto type = event->type();
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::Show:
|
||||
case QEvent::WindowActivate: {
|
||||
if (type == QEvent::Show || type == QEvent::WindowActivate) {
|
||||
if (isOnQuickUnlockScreen() && (m_db.isNull() || !canPerformQuickUnlock())) {
|
||||
resetQuickUnlock();
|
||||
}
|
||||
toggleQuickUnlockScreen();
|
||||
m_hideTimer.stop();
|
||||
|
||||
if (type == QEvent::Show) {
|
||||
#ifdef WITH_XC_YUBIKEY
|
||||
#ifdef Q_OS_WIN
|
||||
m_deviceListener->registerHotplugCallback(true,
|
||||
true,
|
||||
YubiKeyInterfaceUSB::YUBICO_USB_VID,
|
||||
DeviceListener::MATCH_ANY,
|
||||
&DeviceListenerWin::DEV_CLS_KEYBOARD);
|
||||
m_deviceListener->registerHotplugCallback(true,
|
||||
true,
|
||||
YubiKeyInterfaceUSB::ONLYKEY_USB_VID,
|
||||
DeviceListener::MATCH_ANY,
|
||||
&DeviceListenerWin::DEV_CLS_KEYBOARD);
|
||||
m_deviceListener->registerHotplugCallback(true,
|
||||
true,
|
||||
YubiKeyInterfaceUSB::YUBICO_USB_VID,
|
||||
DeviceListener::MATCH_ANY,
|
||||
&DeviceListenerWin::DEV_CLS_KEYBOARD);
|
||||
m_deviceListener->registerHotplugCallback(true,
|
||||
true,
|
||||
YubiKeyInterfaceUSB::ONLYKEY_USB_VID,
|
||||
DeviceListener::MATCH_ANY,
|
||||
&DeviceListenerWin::DEV_CLS_KEYBOARD);
|
||||
#else
|
||||
m_deviceListener->registerHotplugCallback(true, true, YubiKeyInterfaceUSB::YUBICO_USB_VID);
|
||||
m_deviceListener->registerHotplugCallback(true, true, YubiKeyInterfaceUSB::ONLYKEY_USB_VID);
|
||||
m_deviceListener->registerHotplugCallback(true, true, YubiKeyInterfaceUSB::YUBICO_USB_VID);
|
||||
m_deviceListener->registerHotplugCallback(true, true, YubiKeyInterfaceUSB::ONLYKEY_USB_VID);
|
||||
#endif
|
||||
#endif
|
||||
m_hideTimer.stop();
|
||||
pollHardwareKey();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case QEvent::Hide: {
|
||||
ret = true;
|
||||
} else if (type == QEvent::Hide || type == QEvent::WindowDeactivate) {
|
||||
// Schedule form clearing if we are hidden
|
||||
if (!isVisible()) {
|
||||
if (!m_hideTimer.isActive()) {
|
||||
m_hideTimer.start();
|
||||
}
|
||||
|
||||
#ifdef WITH_XC_YUBIKEY
|
||||
m_deviceListener->deregisterAllHotplugCallbacks();
|
||||
if (type == QEvent::Hide) {
|
||||
m_deviceListener->deregisterAllHotplugCallbacks();
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
default:;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -501,7 +500,10 @@ void DatabaseOpenWidget::pollHardwareKey(bool manualTrigger)
|
||||
m_pollingHardwareKey = true;
|
||||
m_manualHardwareKeyRefresh = manualTrigger;
|
||||
|
||||
YubiKey::instance()->findValidKeysAsync();
|
||||
// Add a delay, if this is an automatic trigger, to allow the USB device to settle as
|
||||
// the device may not report a valid serial number immediately after plugging in
|
||||
int delay = manualTrigger ? 0 : 500;
|
||||
QTimer::singleShot(delay, this, [] { YubiKey::instance()->findValidKeysAsync(); });
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::hardwareKeyResponse(bool found)
|
||||
|
||||
Reference in new issue
Block a user