Lot of password related changes all over the place.

Password is no longer saved with the connection list.
Password is not entered along with other connection credentials.
Password is now asked for when required.
Still working on saving the password and auto retrieving it from the password manager.
This commit is contained in:
eelke 2018-11-04 11:26:20 +01:00
parent 6b9b602c64
commit 2230a4bd61
21 changed files with 508 additions and 195 deletions

View file

@ -7,6 +7,21 @@
#include <QStandardItemModel>
#include "ConnectionListModel.h"
#include <QDir>
#include <QStandardPaths>
QString pskFileName()
{
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(".");
}
path += "/psk.ini";
return path;
}
ConnectionManagerWindow::ConnectionManagerWindow(MasterController *master, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::ConnectionManagerWindow)
@ -53,9 +68,13 @@ void ConnectionManagerWindow::on_currentChanged(const QModelIndex &current,
{
int currow = current.row();
auto clm = m_masterController->getConnectionListModel();
clm->save(prevSelection);
if (prevSelection)
clm->save(*prevSelection);
m_mapper->setCurrentIndex(currow);
prevSelection = currow;
if (currow >= 0)
prevSelection = static_cast<size_t>(currow);
else
prevSelection.reset();
}
void ConnectionManagerWindow::on_actionDelete_connection_triggered()
@ -82,7 +101,6 @@ void ConnectionManagerWindow::setupWidgetMappings()
m_mapper->addMapping(ui->edtHost, 2);
m_mapper->addMapping(ui->spinPort, 3);
m_mapper->addMapping(ui->edtUser, 4);
m_mapper->addMapping(ui->edtPassword, 5);
m_mapper->addMapping(ui->edtDbname, 6);
m_mapper->toFirst();
}
@ -90,7 +108,13 @@ void ConnectionManagerWindow::setupWidgetMappings()
void ConnectionManagerWindow::on_actionConnect_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
m_masterController->openSqlWindowForConnection(ci.row());
if (ci.isValid()) {
auto r = static_cast<size_t>(ci.row());
m_masterController->openSqlWindowForConnection(r);
}
else {
// TODO can we give unobtrusive message why it didn't work?
}
}
void ConnectionManagerWindow::on_actionQuit_application_triggered()
@ -117,68 +141,3 @@ void ConnectionManagerWindow::on_actionManage_server_triggered()
}
#include <botan/botan.h>
//#include <botan/base64.h>
//#include <botan/pbkdf.h>
//#include <botan/block_cipher.h>
//#include <botan/hex.h>
#include <botan/cryptobox.h>
void ConnectionManagerWindow::on_testButton_clicked()
{
std::string error = Botan::runtime_version_check(BOTAN_VERSION_MAJOR,
BOTAN_VERSION_MINOR,
BOTAN_VERSION_PATCH);
if (error.empty()) {
// Botan::AutoSeeded_RNG rng;
// Botan::secure_vector<Botan::byte> salt =
// //{ 0x3f, 0x0a, 0xb0, 0x11, 0x44, 0xfe, 0x9d, 0xf7, 0x85, 0xd3, 0x11, 0x38, 0xe2, 0xdf, 0x31, 0x42 };
// rng.random_vec(16);
// // salt should be random and saved with encrypted data so it can be used when we decrypt
// std::string password = "Hello kitty";
// std::unique_ptr<Botan::PBKDF> pbkdf(Botan::get_pbkdf("PBKDF2(SHA-256)"));
// Botan::OctetString aes256_key = pbkdf->derive_key(32, password, salt.data(), salt.size(), 10000);
// std::string plaintext("Your great-grandfather gave this watch to your granddad for good luck. Unfortunately, Dane's luck wasn't as good as his old man's.");
// Botan::secure_vector<uint8_t> pt(plaintext.data(),plaintext.data()+plaintext.length());
// std::unique_ptr<Botan::Cipher_Mode> enc(Botan::get_cipher_mode("AES-256/CBC/PKCS7", Botan::ENCRYPTION));
// enc->set_key(aes256_key);
// //generate fresh nonce (IV)
// //std::unique_ptr<Botan::RandomNumberGenerator> rng(new Botan::AutoSeeded_RNG);
// std::vector<uint8_t> iv(enc->default_nonce_length());
// rng.randomize(iv.data(), iv.size());
// enc->start(iv);
// enc->finish(pt);
// //std::cout << std::endl << enc->name() << " with iv " << Botan::hex_encode(iv) << std::endl << Botan::hex_encode(pt);
//std::string s = aes256_key.as_string();// + "\n" + t.format_string();
std::string passphrase = "my passphrase";
std::string plaintext("password1234");
try {
Botan::AutoSeeded_RNG rng;
std::string encrypted = Botan::CryptoBox::encrypt((const uint8_t*)plaintext.data(), plaintext.length(), passphrase, rng);
std::string decrypted = Botan::CryptoBox::decrypt(encrypted, passphrase);
std::string s = encrypted + "\n" + decrypted;
QMessageBox::information(this, "pglab",
QString::fromUtf8(s.c_str()), QMessageBox::Yes);
}
catch (Botan::Decoding_Error &/*e*/) {
QMessageBox::information(this, "pglab",
tr("Failure to decrypt"), QMessageBox::Yes);
}
}
else {
QMessageBox ::information(this, "pglab",
QString::fromUtf8(error.c_str()), QMessageBox::Yes);
}
}