WIP: Introduce QuickUnlockManager

This commit is contained in:
Jonathan White 2023-11-27 08:49:50 -05:00
parent e6e4fefb82
commit df88f121b0
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
3 changed files with 22 additions and 10 deletions

View File

@ -42,7 +42,17 @@ namespace
bool isQuickUnlockAvailable() bool isQuickUnlockAvailable()
{ {
if (config()->get(Config::Security_QuickUnlock).toBool()) { 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; return false;
} }
@ -326,9 +336,9 @@ void DatabaseOpenWidget::openDatabase()
// Save Quick Unlock credentials if available // Save Quick Unlock credentials if available
if (!blockQuickUnlock && isQuickUnlockAvailable()) { if (!blockQuickUnlock && isQuickUnlockAvailable()) {
auto keyData = databaseKey->serialize(); auto keyData = databaseKey->serialize();
if (!getQuickUnlock()->setKey(m_db->publicUuid(), keyData) && !getQuickUnlock()->errorString().isEmpty()) { auto qu = QuickUnlockManager::get()->getQuickUnlock();
getMainWindow()->displayTabMessage(getQuickUnlock()->errorString(), if (!qu->setKey(m_db->publicUuid(), keyData) && !qu->errorString().isEmpty()) {
MessageWidget::MessageType::Warning); getMainWindow()->displayTabMessage(qu->errorString(), MessageWidget::MessageType::Warning);
} }
m_ui->messageWidget->hideMessage(); m_ui->messageWidget->hideMessage();
} }
@ -377,11 +387,12 @@ QSharedPointer<CompositeKey> DatabaseOpenWidget::buildDatabaseKey()
if (!m_db.isNull() && canPerformQuickUnlock(m_db->publicUuid())) { if (!m_db.isNull() && canPerformQuickUnlock(m_db->publicUuid())) {
// try to retrieve the stored password using quick unlock // try to retrieve the stored password using quick unlock
QByteArray keyData; 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( 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); MessageWidget::Error);
if (!getQuickUnlock()->hasKey(m_db->publicUuid())) { if (!qu->hasKey(m_db->publicUuid())) {
resetQuickUnlock(); resetQuickUnlock();
} }
return {}; return {};
@ -616,7 +627,7 @@ void DatabaseOpenWidget::resetQuickUnlock()
return; return;
} }
if (!m_db.isNull()) { if (!m_db.isNull()) {
getQuickUnlock()->reset(m_db->publicUuid()); QuickUnlockManager::get()->getQuickUnlock()->reset(m_db->publicUuid());
} }
load(m_filename); load(m_filename);
} }

View File

@ -50,7 +50,7 @@ const QuickUnlockManager* QuickUnlockManager::get()
return quickUnlockManager; return quickUnlockManager;
} }
QuickUnlockInterface* QuickUnlockManager::getQuickUnlock() QuickUnlockInterface* QuickUnlockManager::getQuickUnlock() const
{ {
for (auto* interface : m_interfaces) { for (auto* interface : m_interfaces) {
if (interface->isAvailable()) { if (interface->isAvailable()) {

View File

@ -51,8 +51,9 @@ public:
~QuickUnlockManager(); ~QuickUnlockManager();
static const QuickUnlockManager* get(); static const QuickUnlockManager* get();
static bool isAvailable();
QuickUnlockInterface* getQuickUnlock(); QuickUnlockInterface* getQuickUnlock() const;
private: private:
QList<QuickUnlockInterface*> m_interfaces; QList<QuickUnlockInterface*> m_interfaces;