mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-23 06:50:58 -04:00
parent
f20b531430
commit
7d0dc67180
3 changed files with 73 additions and 59 deletions
|
@ -56,19 +56,6 @@ namespace
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool canPerformQuickUnlock(const QString& filename)
|
||||
{
|
||||
if (isQuickUnlockAvailable()) {
|
||||
#if defined(Q_CC_MSVC)
|
||||
return getWindowsHello()->hasKey(filename);
|
||||
#elif defined(Q_OS_MACOS)
|
||||
return TouchID::getInstance().containsKey(filename);
|
||||
#endif
|
||||
}
|
||||
Q_UNUSED(filename);
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
|
||||
|
@ -191,50 +178,57 @@ void DatabaseOpenWidget::toggleHardwareKeyComponent(bool state)
|
|||
}
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::showEvent(QShowEvent* event)
|
||||
bool DatabaseOpenWidget::event(QEvent* event)
|
||||
{
|
||||
DialogyWidget::showEvent(event);
|
||||
if (isOnQuickUnlockScreen()) {
|
||||
m_ui->quickUnlockButton->setFocus();
|
||||
if (!canPerformQuickUnlock(m_filename)) {
|
||||
bool ret = DialogyWidget::event(event);
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::Show:
|
||||
case QEvent::WindowActivate: {
|
||||
if (isOnQuickUnlockScreen() && (m_db.isNull() || !canPerformQuickUnlock())) {
|
||||
resetQuickUnlock();
|
||||
}
|
||||
} else {
|
||||
m_ui->editPassword->setFocus();
|
||||
}
|
||||
m_hideTimer.stop();
|
||||
toggleQuickUnlockScreen();
|
||||
m_hideTimer.stop();
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::hideEvent(QHideEvent* event)
|
||||
{
|
||||
DialogyWidget::hideEvent(event);
|
||||
|
||||
// Schedule form clearing if we are hidden
|
||||
if (!isVisible()) {
|
||||
m_hideTimer.start();
|
||||
return true;
|
||||
}
|
||||
|
||||
case QEvent::Hide: {
|
||||
// Schedule form clearing if we are hidden
|
||||
if (!isVisible()) {
|
||||
m_hideTimer.start();
|
||||
}
|
||||
|
||||
#ifdef WITH_XC_YUBIKEY
|
||||
m_deviceListener->deregisterAllHotplugCallbacks();
|
||||
m_deviceListener->deregisterAllHotplugCallbacks();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
default:;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool DatabaseOpenWidget::unlockingDatabase()
|
||||
|
@ -257,12 +251,7 @@ void DatabaseOpenWidget::load(const QString& filename)
|
|||
}
|
||||
}
|
||||
|
||||
if (canPerformQuickUnlock(m_filename)) {
|
||||
m_ui->centralStack->setCurrentIndex(1);
|
||||
m_ui->quickUnlockButton->setFocus();
|
||||
} else {
|
||||
m_ui->editPassword->setFocus();
|
||||
}
|
||||
toggleQuickUnlockScreen();
|
||||
|
||||
#ifdef WITH_XC_YUBIKEY
|
||||
// Do initial auto-poll
|
||||
|
@ -279,8 +268,11 @@ void DatabaseOpenWidget::clearForms()
|
|||
m_ui->keyFileLineEdit->setShowPassword(false);
|
||||
m_ui->keyFileLineEdit->setClearButtonEnabled(true);
|
||||
m_ui->hardwareKeyCombo->clear();
|
||||
m_ui->centralStack->setCurrentIndex(0);
|
||||
m_db.reset();
|
||||
toggleQuickUnlockScreen();
|
||||
|
||||
QString error;
|
||||
m_db.reset(new Database());
|
||||
m_db->open(m_filename, nullptr, &error);
|
||||
}
|
||||
|
||||
QSharedPointer<Database> DatabaseOpenWidget::database()
|
||||
|
@ -403,7 +395,7 @@ QSharedPointer<CompositeKey> DatabaseOpenWidget::buildDatabaseKey()
|
|||
{
|
||||
auto databaseKey = QSharedPointer<CompositeKey>::create();
|
||||
|
||||
if (canPerformQuickUnlock(m_filename)) {
|
||||
if (!m_db.isNull() && canPerformQuickUnlock()) {
|
||||
// try to retrieve the stored password using Windows Hello
|
||||
QByteArray keyData;
|
||||
#ifdef Q_CC_MSVC
|
||||
|
@ -602,11 +594,34 @@ void DatabaseOpenWidget::setUserInteractionLock(bool state)
|
|||
m_unlockingDatabase = state;
|
||||
}
|
||||
|
||||
bool DatabaseOpenWidget::isOnQuickUnlockScreen()
|
||||
bool DatabaseOpenWidget::canPerformQuickUnlock() const
|
||||
{
|
||||
if (!m_db.isNull() && isQuickUnlockAvailable()) {
|
||||
#if defined(Q_CC_MSVC)
|
||||
return getWindowsHello()->hasKey(m_filename);
|
||||
#elif defined(Q_OS_MACOS)
|
||||
return TouchID::getInstance().containsKey(m_filename);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DatabaseOpenWidget::isOnQuickUnlockScreen() const
|
||||
{
|
||||
return m_ui->centralStack->currentIndex() == 1;
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::toggleQuickUnlockScreen()
|
||||
{
|
||||
if (canPerformQuickUnlock()) {
|
||||
m_ui->centralStack->setCurrentIndex(1);
|
||||
m_ui->quickUnlockButton->setFocus();
|
||||
} else {
|
||||
m_ui->centralStack->setCurrentIndex(0);
|
||||
m_ui->editPassword->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseOpenWidget::triggerQuickUnlock()
|
||||
{
|
||||
if (isOnQuickUnlockScreen()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue