Added the capability to reset the password manager
Also some documentation about the password manager.
This commit is contained in:
parent
f8528143ac
commit
4fa2189b27
17 changed files with 233 additions and 85 deletions
|
|
@ -6,7 +6,9 @@
|
|||
#include "DatabaseWindow.h"
|
||||
#include "BackupDialog.h"
|
||||
#include "PasswordPromptDialog.h"
|
||||
#include "ScopeGuard.h"
|
||||
#include "ConnectionConfigurationWidget.h"
|
||||
#include <QSqlQuery>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
|
@ -156,33 +158,36 @@ std::shared_ptr<PasswordManager> ConnectionController::passwordManager()
|
|||
|
||||
bool ConnectionController::retrieveConnectionPassword(ConnectionConfig &cc)
|
||||
{
|
||||
auto enc_pwd = cc.encodedPassword();
|
||||
if (!enc_pwd.isEmpty()) {
|
||||
std::string pw;
|
||||
auto enc_pwd = cc.encodedPassword();
|
||||
if (!enc_pwd.isEmpty())
|
||||
{
|
||||
std::string pw;
|
||||
bool result = retrieveFromPasswordManager(getPskId(cc.uuid()),
|
||||
std::string_view(enc_pwd.data(), enc_pwd.size()) , pw);
|
||||
if (result) {
|
||||
cc.setPassword(QString::fromUtf8(pw.data(), pw.size()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Geen else hier want als voorgaande blok niet geretourneerd heeft moeten we wachtwoord
|
||||
// ook aan de gebruiker vragen zoals hier gebeurd.
|
||||
QString str = cc.makeLongDescription();
|
||||
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::SaveOption, nullptr);
|
||||
dlg->setCaption(tr("Connection password prompt"));
|
||||
dlg->setDescription(QString(tr("Please provide password for connection %1")).arg(str));
|
||||
int exec_result = dlg->exec();
|
||||
if (result)
|
||||
{
|
||||
cc.setPassword(QString::fromUtf8(pw.data(), pw.size()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Geen else hier want als voorgaande blok niet geretourneerd heeft moeten we wachtwoord
|
||||
// ook aan de gebruiker vragen zoals hier gebeurd.
|
||||
QString str = cc.makeLongDescription();
|
||||
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::SaveOption, nullptr);
|
||||
dlg->setCaption(tr("Connection password prompt"));
|
||||
dlg->setDescription(QString(tr("Please provide password for connection %1")).arg(str));
|
||||
int exec_result = dlg->exec();
|
||||
|
||||
if (exec_result == QDialog::Accepted) {
|
||||
auto password = dlg->password();
|
||||
cc.setPassword(password);
|
||||
if (dlg->saveChecked()) {
|
||||
if (exec_result == QDialog::Accepted)
|
||||
{
|
||||
auto password = dlg->password();
|
||||
cc.setPassword(password);
|
||||
if (dlg->saveChecked())
|
||||
encryptPassword(cc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConnectionController::retrieveFromPasswordManager(const std::string &password_id, const std::string_view &enc_password, std::string &password)
|
||||
|
|
@ -224,29 +229,48 @@ bool ConnectionController::decodeConnectionPassword(QUuid id, QByteArray encoded
|
|||
return res;
|
||||
}
|
||||
|
||||
void ConnectionController::resetPasswordManager()
|
||||
{
|
||||
auto&& user_cfg_db = m_masterController->userConfigDatabase();
|
||||
user_cfg_db.transaction();
|
||||
try
|
||||
{
|
||||
m_passwordManager->resetMasterPassword(user_cfg_db);
|
||||
m_connectionTreeModel->clearAllPasswords();
|
||||
user_cfg_db.commit();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
user_cfg_db.rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool ConnectionController::UnlockPasswordManagerIfNeeded()
|
||||
{
|
||||
auto&& user_cfg_db = m_masterController->userConfigDatabase();
|
||||
if (m_passwordManager->initialized(user_cfg_db)) {
|
||||
if (!m_passwordManager->locked())
|
||||
return true;
|
||||
auto&& user_cfg_db = m_masterController->userConfigDatabase();
|
||||
if (m_passwordManager->initialized(user_cfg_db))
|
||||
{
|
||||
if (!m_passwordManager->locked())
|
||||
return true;
|
||||
|
||||
while (true) {
|
||||
// ask user for passphrase
|
||||
while (true)
|
||||
{
|
||||
PassphraseResult pp_result = PassphrasePrompt();
|
||||
if (!pp_result.success)
|
||||
break; // leave this retry loop
|
||||
break;
|
||||
|
||||
// user gave OK, if succeeds return true otherwise loop a prompt for password again.
|
||||
if (m_passwordManager->openDatabase(user_cfg_db, pp_result.passphrase)) {
|
||||
// user gave OK, if succeeds return true otherwise loop a prompt for password again.
|
||||
if (m_passwordManager->openDatabase(user_cfg_db, pp_result.passphrase))
|
||||
{
|
||||
setRelockTimer(pp_result.rememberForMinutes);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
InitializePasswordManager();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue