End user can now specify how long password manager remembers the master key.
Closes $24
This commit is contained in:
parent
d489f11e52
commit
7f88b98cdd
2 changed files with 31 additions and 3 deletions
|
|
@ -10,12 +10,21 @@
|
||||||
#include "ConnectionConfigurationWidget.h"
|
#include "ConnectionConfigurationWidget.h"
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
ConnectionController::ConnectionController(MasterController *parent)
|
ConnectionController::ConnectionController(MasterController *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_masterController(parent)
|
, m_masterController(parent)
|
||||||
{}
|
, m_relockTimer(new QTimer(this))
|
||||||
|
{
|
||||||
|
m_relockTimer->setSingleShot(true);
|
||||||
|
m_relockTimer->setTimerType(Qt::VeryCoarseTimer);
|
||||||
|
// Force signal to go through queue so when the password manager is relocked after 0msec
|
||||||
|
// the code that retrieves the password is garanteed to run before the signal is handled
|
||||||
|
// because only after the password is retrieved the loop has a chance to run.
|
||||||
|
m_relockTimer->callOnTimeout(this, &ConnectionController::relock, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionController::~ConnectionController()
|
ConnectionController::~ConnectionController()
|
||||||
{
|
{
|
||||||
|
|
@ -194,7 +203,7 @@ bool ConnectionController::UnlockPasswordManagerIfNeeded()
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// ask user for passphrase
|
// ask user for passphrase
|
||||||
auto dlg = std::make_unique<PasswordPromptDialog>(nullptr, nullptr);
|
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::RememberPassword, nullptr);
|
||||||
dlg->setCaption(tr("Unlock password manager"));
|
dlg->setCaption(tr("Unlock password manager"));
|
||||||
dlg->setDescription(tr("Enter password for password manager"));
|
dlg->setDescription(tr("Enter password for password manager"));
|
||||||
int exec_result = dlg->exec();
|
int exec_result = dlg->exec();
|
||||||
|
|
@ -205,10 +214,16 @@ bool ConnectionController::UnlockPasswordManagerIfNeeded()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// user gave OK, if succeeds return true otherwise loop a prompt for password again.
|
// user gave OK, if succeeds return true otherwise loop a prompt for password again.
|
||||||
if (m_passwordManager->openDatabase(user_cfg_db, dlg->password()))
|
if (m_passwordManager->openDatabase(user_cfg_db, dlg->password())) {
|
||||||
|
int rem = dlg->remember();
|
||||||
|
if (rem >= 0) {
|
||||||
|
int timeout = rem * 60 * 1000; /// rem is in minutes, timeout in millisec
|
||||||
|
m_relockTimer->start(timeout);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// Ask user for passphrase + confirmation, clearly instruct this is first setup
|
// Ask user for passphrase + confirmation, clearly instruct this is first setup
|
||||||
// create
|
// create
|
||||||
|
|
@ -234,5 +249,10 @@ std::string ConnectionController::getPskId(const ConnectionConfig &cc)
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionController::relock()
|
||||||
|
{
|
||||||
|
m_passwordManager->closeDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class ConnectionList;
|
||||||
class ConnectionTreeModel;
|
class ConnectionTreeModel;
|
||||||
class ConnectionManagerWindow;
|
class ConnectionManagerWindow;
|
||||||
class PasswordManager;
|
class PasswordManager;
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class ConnectionController : public QObject {
|
class ConnectionController : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -43,6 +44,7 @@ private:
|
||||||
ConnectionList *m_connectionList = nullptr;
|
ConnectionList *m_connectionList = nullptr;
|
||||||
ConnectionTreeModel *m_connectionTreeModel = nullptr;
|
ConnectionTreeModel *m_connectionTreeModel = nullptr;
|
||||||
ConnectionManagerWindow *m_connectionManagerWindow = nullptr;
|
ConnectionManagerWindow *m_connectionManagerWindow = nullptr;
|
||||||
|
QTimer *m_relockTimer = nullptr;
|
||||||
|
|
||||||
/** Using long lived object so it can remember its master password for sometime
|
/** Using long lived object so it can remember its master password for sometime
|
||||||
* if the user wishes it.
|
* if the user wishes it.
|
||||||
|
|
@ -57,9 +59,15 @@ private:
|
||||||
bool decodePassword(const std::string &password_id, const std::string &enc_password, std::string &password);
|
bool decodePassword(const std::string &password_id, const std::string &enc_password, std::string &password);
|
||||||
bool encodePassword(const std::string &password_id, const std::string &password, std::string &enc_password);
|
bool encodePassword(const std::string &password_id, const std::string &password, std::string &enc_password);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \return bool: succeeded, int: relock timeout
|
||||||
|
///
|
||||||
bool UnlockPasswordManagerIfNeeded();
|
bool UnlockPasswordManagerIfNeeded();
|
||||||
|
|
||||||
static std::string getPskId(const ConnectionConfig &cc);
|
static std::string getPskId(const ConnectionConfig &cc);
|
||||||
|
private slots:
|
||||||
|
void relock();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue