mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
WIP: Introduce QuickUnlockManager
This commit is contained in:
parent
e6e4fefb82
commit
df88f121b0
@ -42,7 +42,17 @@ namespace
|
||||
bool isQuickUnlockAvailable()
|
||||
{
|
||||
if (config()->get(Config::Security_QuickUnlock).toBool()) {
|
||||
return getQuickUnlock()->isAvailable();
|
||||
auto qu = QuickUnlockManager::get()->getQuickUnlock();
|
||||
return qu && qu->isAvailable();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool canPerformQuickUnlock(const QUuid& dbUuid)
|
||||
{
|
||||
if (isQuickUnlockAvailable()) {
|
||||
auto qu = QuickUnlockManager::get()->getQuickUnlock();
|
||||
return qu->hasKey(dbUuid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -326,9 +336,9 @@ void DatabaseOpenWidget::openDatabase()
|
||||
// Save Quick Unlock credentials if available
|
||||
if (!blockQuickUnlock && isQuickUnlockAvailable()) {
|
||||
auto keyData = databaseKey->serialize();
|
||||
if (!getQuickUnlock()->setKey(m_db->publicUuid(), keyData) && !getQuickUnlock()->errorString().isEmpty()) {
|
||||
getMainWindow()->displayTabMessage(getQuickUnlock()->errorString(),
|
||||
MessageWidget::MessageType::Warning);
|
||||
auto qu = QuickUnlockManager::get()->getQuickUnlock();
|
||||
if (!qu->setKey(m_db->publicUuid(), keyData) && !qu->errorString().isEmpty()) {
|
||||
getMainWindow()->displayTabMessage(qu->errorString(), MessageWidget::MessageType::Warning);
|
||||
}
|
||||
m_ui->messageWidget->hideMessage();
|
||||
}
|
||||
@ -377,11 +387,12 @@ QSharedPointer<CompositeKey> DatabaseOpenWidget::buildDatabaseKey()
|
||||
if (!m_db.isNull() && canPerformQuickUnlock(m_db->publicUuid())) {
|
||||
// try to retrieve the stored password using quick unlock
|
||||
QByteArray keyData;
|
||||
if (!getQuickUnlock()->getKey(m_db->publicUuid(), keyData)) {
|
||||
auto qu = QuickUnlockManager::get()->getQuickUnlock();
|
||||
if (!qu->getKey(m_db->publicUuid(), keyData)) {
|
||||
m_ui->messageWidget->showMessage(
|
||||
tr("Failed to authenticate with Quick Unlock: %1").arg(getQuickUnlock()->errorString()),
|
||||
tr("Failed to authenticate with Quick Unlock: %1").arg(qu->errorString()),
|
||||
MessageWidget::Error);
|
||||
if (!getQuickUnlock()->hasKey(m_db->publicUuid())) {
|
||||
if (!qu->hasKey(m_db->publicUuid())) {
|
||||
resetQuickUnlock();
|
||||
}
|
||||
return {};
|
||||
@ -616,7 +627,7 @@ void DatabaseOpenWidget::resetQuickUnlock()
|
||||
return;
|
||||
}
|
||||
if (!m_db.isNull()) {
|
||||
getQuickUnlock()->reset(m_db->publicUuid());
|
||||
QuickUnlockManager::get()->getQuickUnlock()->reset(m_db->publicUuid());
|
||||
}
|
||||
load(m_filename);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ const QuickUnlockManager* QuickUnlockManager::get()
|
||||
return quickUnlockManager;
|
||||
}
|
||||
|
||||
QuickUnlockInterface* QuickUnlockManager::getQuickUnlock()
|
||||
QuickUnlockInterface* QuickUnlockManager::getQuickUnlock() const
|
||||
{
|
||||
for (auto* interface : m_interfaces) {
|
||||
if (interface->isAvailable()) {
|
||||
|
@ -51,8 +51,9 @@ public:
|
||||
~QuickUnlockManager();
|
||||
|
||||
static const QuickUnlockManager* get();
|
||||
static bool isAvailable();
|
||||
|
||||
QuickUnlockInterface* getQuickUnlock();
|
||||
QuickUnlockInterface* getQuickUnlock() const;
|
||||
|
||||
private:
|
||||
QList<QuickUnlockInterface*> m_interfaces;
|
||||
|
Loading…
Reference in New Issue
Block a user