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()
{
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);
}

View File

@ -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()) {

View File

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