Make saving of the entered password work to.toStdString
Also when testing a preexisting connection config it will now decode a potential stored password.
This commit is contained in:
parent
c00a0452d1
commit
87cfb84997
6 changed files with 117 additions and 70 deletions
|
|
@ -83,14 +83,14 @@ void ConnectionController::createConnection()
|
|||
{
|
||||
ConnectionConfig cc;
|
||||
cc.setUuid(QUuid::createUuid());
|
||||
ConnectionConfigurationWidget::editExistingInWindow(this, cc);
|
||||
ConnectionConfigurationWidget::editExistingInWindow(this, cc, [this] (ConnectionConfigurationWidget &w) -> void { saveConnection(w); });
|
||||
}
|
||||
|
||||
void ConnectionController::editConnection(QModelIndex index)
|
||||
{
|
||||
auto config = ConnectionTreeModel::getConfigFromModelIndex(index);
|
||||
if (config) {
|
||||
ConnectionConfigurationWidget::editExistingInWindow(this, *config);
|
||||
ConnectionConfigurationWidget::editExistingInWindow(this, *config, [this] (ConnectionConfigurationWidget &w) -> void { saveConnection(w); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,10 +100,20 @@ void ConnectionController::editCopy(QModelIndex index)
|
|||
if (config) {
|
||||
auto cc = *config;
|
||||
cc.setUuid(QUuid::createUuid());
|
||||
ConnectionConfigurationWidget::editExistingInWindow(this, cc);
|
||||
ConnectionConfigurationWidget::editExistingInWindow(this, cc, [this] (ConnectionConfigurationWidget &w) -> void { saveConnection(w); });
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionController::saveConnection(ConnectionConfigurationWidget &w)
|
||||
{
|
||||
auto cc = w.data();
|
||||
auto grp = w.group();
|
||||
if (w.savePassword()) {
|
||||
encryptPassword(cc);
|
||||
}
|
||||
m_connectionTreeModel->save(grp, cc);
|
||||
}
|
||||
|
||||
void ConnectionController::addGroup()
|
||||
{
|
||||
auto result = QInputDialog::getText(nullptr, tr("Add new connection group"),
|
||||
|
|
@ -142,8 +152,8 @@ bool ConnectionController::retrieveConnectionPassword(ConnectionConfig &cc)
|
|||
auto enc_pwd = cc.encodedPassword();
|
||||
if (!enc_pwd.isEmpty()) {
|
||||
std::string pw;
|
||||
bool result = decodePassword(getPskId(cc),
|
||||
std::string_view(enc_pwd.data(), enc_pwd.size()) , pw);// getPasswordFromPskdb(getPskId(cc), 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;
|
||||
|
|
@ -161,19 +171,14 @@ bool ConnectionController::retrieveConnectionPassword(ConnectionConfig &cc)
|
|||
auto password = dlg->password();
|
||||
cc.setPassword(password);
|
||||
if (dlg->saveChecked()) {
|
||||
auto ba = password.toUtf8();
|
||||
std::string pw(ba.data(), static_cast<size_t>(ba.size()));
|
||||
std::string encoded_pw;
|
||||
if (encodePassword(getPskId(cc), pw, encoded_pw)) {
|
||||
cc.setEncodedPassword({ encoded_pw.data(), static_cast<int>(encoded_pw.size()) });
|
||||
}
|
||||
encryptPassword(cc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConnectionController::decodePassword(const std::string &password_id, const std::string_view &enc_password, std::string &password)
|
||||
bool ConnectionController::retrieveFromPasswordManager(const std::string &password_id, const std::string_view &enc_password, std::string &password)
|
||||
{
|
||||
if (!UnlockPasswordManagerIfNeeded())
|
||||
return false;
|
||||
|
|
@ -182,13 +187,27 @@ bool ConnectionController::decodePassword(const std::string &password_id, const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ConnectionController::encodePassword(const std::string &password_id, const std::string &password, std::string &enc_password)
|
||||
bool ConnectionController::encryptPassword(ConnectionConfig &cc)
|
||||
{
|
||||
if (!UnlockPasswordManagerIfNeeded())
|
||||
return false;
|
||||
if (!UnlockPasswordManagerIfNeeded())
|
||||
return false;
|
||||
|
||||
enc_password = m_passwordManager->encrypt(password_id, password);
|
||||
return true;
|
||||
std::string password = cc.password().toStdString();
|
||||
std::string password_id = getPskId(cc.uuid());
|
||||
std::string enc_password = m_passwordManager->encrypt(password_id, password);
|
||||
cc.setEncodedPassword({ enc_password.data(), static_cast<int>(enc_password.size()) });
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConnectionController::decodeConnectionPassword(QUuid id, QByteArray encoded, QString &out_password)
|
||||
{
|
||||
std::string password_id = getPskId(id);
|
||||
std::string enc(encoded.data(), encoded.size());
|
||||
std::string password;
|
||||
bool res = retrieveFromPasswordManager(password_id, enc, password);
|
||||
if (res)
|
||||
out_password = QString::fromStdString(password);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ConnectionController::UnlockPasswordManagerIfNeeded()
|
||||
|
|
@ -236,13 +255,13 @@ bool ConnectionController::UnlockPasswordManagerIfNeeded()
|
|||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ConnectionController::getPskId(const ConnectionConfig &cc)
|
||||
std::string ConnectionController::getPskId(QUuid connectionid)
|
||||
{
|
||||
std::string id = "dbpw/";
|
||||
id += cc.uuid().toString().toUtf8().data();
|
||||
id += connectionid.toString().toUtf8().data();
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue