mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-03-11 08:54:48 +00:00
Fix unloading ssh keys on database lock
* Fix #5928 - SSH Agent keys are properly removed on database lock. Also fixes crash when keys are still loaded on application close. * Remove dependency on DatabaseWidget within SSH Agent.
This commit is contained in:
parent
0d3d5db87c
commit
a3b9700f90
4 changed files with 28 additions and 29 deletions
|
|
@ -214,13 +214,6 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)
|
|||
m_EntrySearcher = new EntrySearcher(false);
|
||||
m_searchLimitGroup = config()->get(Config::SearchLimitGroup).toBool();
|
||||
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
if (sshAgent()->isEnabled()) {
|
||||
connect(this, SIGNAL(databaseLocked()), sshAgent(), SLOT(databaseLocked()));
|
||||
connect(this, SIGNAL(databaseUnlocked()), sshAgent(), SLOT(databaseUnlocked()));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_XC_KEESHARE
|
||||
// We need to reregister the database to allow exports
|
||||
// from a newly created database
|
||||
|
|
@ -1089,6 +1082,9 @@ void DatabaseWidget::loadDatabase(bool accepted)
|
|||
m_entryBeforeLock = QUuid();
|
||||
m_saveAttempts = 0;
|
||||
emit databaseUnlocked();
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
sshAgent()->databaseUnlocked(m_db);
|
||||
#endif
|
||||
if (config()->get(Config::MinimizeAfterUnlock).toBool()) {
|
||||
getMainWindow()->minimizeOrHide();
|
||||
}
|
||||
|
|
@ -1176,6 +1172,10 @@ void DatabaseWidget::unlockDatabase(bool accepted)
|
|||
processAutoOpen();
|
||||
emit databaseUnlocked();
|
||||
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
sshAgent()->databaseUnlocked(m_db);
|
||||
#endif
|
||||
|
||||
if (senderDialog && senderDialog->intent() == DatabaseOpenDialog::Intent::AutoType) {
|
||||
QList<QSharedPointer<Database>> dbList;
|
||||
dbList.append(m_db);
|
||||
|
|
@ -1597,6 +1597,10 @@ bool DatabaseWidget::lock()
|
|||
m_entryBeforeLock = currentEntry->uuid();
|
||||
}
|
||||
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
sshAgent()->databaseLocked(m_db);
|
||||
#endif
|
||||
|
||||
endSearch();
|
||||
clearAllWidgets();
|
||||
switchToOpenDatabase(m_db->filePath());
|
||||
|
|
|
|||
|
|
@ -601,6 +601,9 @@ MainWindow::MainWindow()
|
|||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
sshAgent()->removeAllIdentities();
|
||||
#endif
|
||||
}
|
||||
|
||||
QList<DatabaseWidget*> MainWindow::getOpenDatabases()
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
#include "SSHAgent.h"
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/Database.h"
|
||||
#include "core/Group.h"
|
||||
#include "core/Metadata.h"
|
||||
#include "crypto/ssh/BinaryStream.h"
|
||||
#include "crypto/ssh/OpenSSHKey.h"
|
||||
#include "sshagent/KeeAgentSettings.h"
|
||||
|
|
@ -31,11 +34,6 @@
|
|||
|
||||
Q_GLOBAL_STATIC(SSHAgent, s_sshAgent);
|
||||
|
||||
SSHAgent::~SSHAgent()
|
||||
{
|
||||
removeAllIdentities();
|
||||
}
|
||||
|
||||
SSHAgent* SSHAgent::instance()
|
||||
{
|
||||
return s_sshAgent;
|
||||
|
|
@ -427,18 +425,15 @@ void SSHAgent::setAutoRemoveOnLock(const OpenSSHKey& key, bool autoRemove)
|
|||
}
|
||||
}
|
||||
|
||||
void SSHAgent::databaseLocked()
|
||||
void SSHAgent::databaseLocked(QSharedPointer<Database> db)
|
||||
{
|
||||
auto* widget = qobject_cast<DatabaseWidget*>(sender());
|
||||
if (!widget) {
|
||||
if (!db) {
|
||||
return;
|
||||
}
|
||||
|
||||
QUuid databaseUuid = widget->database()->uuid();
|
||||
|
||||
auto it = m_addedKeys.begin();
|
||||
while (it != m_addedKeys.end()) {
|
||||
if (it.value().first != databaseUuid) {
|
||||
if (it.value().first != db->uuid()) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -452,16 +447,14 @@ void SSHAgent::databaseLocked()
|
|||
}
|
||||
}
|
||||
|
||||
void SSHAgent::databaseUnlocked()
|
||||
void SSHAgent::databaseUnlocked(QSharedPointer<Database> db)
|
||||
{
|
||||
auto* widget = qobject_cast<DatabaseWidget*>(sender());
|
||||
if (!widget) {
|
||||
if (!db || !isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entry* e : widget->database()->rootGroup()->entriesRecursive()) {
|
||||
if (widget->database()->metadata()->recycleBinEnabled()
|
||||
&& e->group() == widget->database()->metadata()->recycleBin()) {
|
||||
for (Entry* e : db->rootGroup()->entriesRecursive()) {
|
||||
if (db->metadata()->recycleBinEnabled() && e->group() == db->metadata()->recycleBin()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -483,7 +476,7 @@ void SSHAgent::databaseUnlocked()
|
|||
|
||||
// Add key to agent; ignore errors if we have previously added the key
|
||||
bool known_key = m_addedKeys.contains(key);
|
||||
if (!addIdentity(key, settings, widget->database()->uuid()) && !known_key) {
|
||||
if (!addIdentity(key, settings, db->uuid()) && !known_key) {
|
||||
emit error(m_error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include <QtCore>
|
||||
|
||||
#include "crypto/ssh/OpenSSHKey.h"
|
||||
#include "gui/DatabaseWidget.h"
|
||||
#include "sshagent/KeeAgentSettings.h"
|
||||
|
||||
class SSHAgent : public QObject
|
||||
|
|
@ -32,7 +31,7 @@ class SSHAgent : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
~SSHAgent() override;
|
||||
~SSHAgent() override = default;
|
||||
static SSHAgent* instance();
|
||||
|
||||
bool isEnabled() const;
|
||||
|
|
@ -59,8 +58,8 @@ signals:
|
|||
void enabledChanged(bool enabled);
|
||||
|
||||
public slots:
|
||||
void databaseLocked();
|
||||
void databaseUnlocked();
|
||||
void databaseLocked(QSharedPointer<Database> db);
|
||||
void databaseUnlocked(QSharedPointer<Database> db);
|
||||
|
||||
private:
|
||||
const quint8 SSH_AGENT_FAILURE = 5;
|
||||
|
|
|
|||
Loading…
Reference in a new issue