Browse Source

Properly close app on welcome back cancel

pull/94/head
fekt 2 years ago
parent
commit
1f7b8186f0
  1. 99
      src/mainwindow.cpp

99
src/mainwindow.cpp

@ -388,11 +388,14 @@ void MainWindow::closeEvent(QCloseEvent* event) {
s.sync(); s.sync();
// Let the RPC know to shut down any running service. // Let the RPC know to shut down any running service.
rpc->shutdownhushd(); if(rpc){
int passphraselenght = DataStore::getChatDataStore()->getPassword().length(); rpc->shutdownhushd();
}
int passphraselength = DataStore::getChatDataStore()->getPassword().length();
// Check is encryption is ON for SDl // Check is encryption is ON for SDl
if(passphraselenght > 0) { if(passphraselength > 0) {
// delete old file before // delete old file before
//auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); //auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
@ -631,25 +634,28 @@ void MainWindow::removeWalletEncryption() {
void MainWindow::removeWalletEncryptionStartUp() { void MainWindow::removeWalletEncryptionStartUp() {
qDebug() << __func__ << ": removing wallet encryption"; qDebug() << __func__ << ": removing wallet encryption";
QDialog d(this); QDialog d(this);
Ui_startup ed; Ui_startup ed;
ed.setupUi(&d); ed.setupUi(&d);
QObject::connect(ed.new_restore, &QPushButton::clicked, [&] { // Connect cancel button to close app on queued connection
QObject::connect(ed.buttonBox, &QDialogButtonBox::rejected, qApp, &QCoreApplication::quit, Qt::QueuedConnection);
d.close(); // Connect new/restore button click
QFile wallet(dirwallet); QObject::connect(ed.new_restore, &QPushButton::clicked, [&] {
QFile walletenc(dirwalletenc);
wallet.remove(); d.close();
walletenc.remove(); QFile wallet(dirwallet);
QFile walletenc(dirwalletenc);
auto cl = new ConnectionLoader(this, rpc); wallet.remove();
cl->loadConnection(); walletenc.remove();
});
auto cl = new ConnectionLoader(this, rpc);
if (d.exec() == QDialog::Accepted) cl->loadConnection();
{ });
if (d.exec() == QDialog::Accepted){
QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs
QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL"); QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL");
@ -666,49 +672,48 @@ void MainWindow::removeWalletEncryptionStartUp() {
sequence1 = new char[length+1]; sequence1 = new char[length+1];
strncpy(sequence1, passphraseHash.toUtf8(), length+1); strncpy(sequence1, passphraseHash.toUtf8(), length+1);
#define MESSAGE ((const unsigned char *) sequence) #define MESSAGE ((const unsigned char *) sequence)
#define MESSAGE_LEN length #define MESSAGE_LEN length
#define hash ((const unsigned char *) sequence1) #define hash ((const unsigned char *) sequence1)
#define PASSWORD sequence #define PASSWORD sequence
#define KEY_LEN crypto_box_SEEDBYTES #define KEY_LEN crypto_box_SEEDBYTES
unsigned char key[KEY_LEN]; unsigned char key[KEY_LEN];
if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash, if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
crypto_pwhash_ALG_DEFAULT) != 0) { crypto_pwhash_ALG_DEFAULT) != 0) {
/* out of memory */ /* out of memory */
qDebug() << __func__ << ": crypto_pwhash failed! Possibly out of memory"; qDebug() << __func__ << ": crypto_pwhash failed! Possibly out of memory";
return; return;
} }
QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex(); QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex();
DataStore::getChatDataStore()->setPassword(passphraseHash1); DataStore::getChatDataStore()->setPassword(passphraseHash1);
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
QString target_encwallet_file = dirwalletenc; QString target_encwallet_file = dirwalletenc;
QString target_decwallet_file = dirwallet; QString target_decwallet_file = dirwallet;
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key);
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
QFile wallet(dirwallet); QFile wallet(dirwallet);
qDebug() << __func__ << ": wallet size=" << wallet.size(); qDebug() << __func__ << ": wallet size=" << wallet.size();
if (wallet.size() == 0) { if (wallet.size() == 0) {
QMessageBox::critical(this, tr("Wallet Encryption Failed"), QMessageBox::critical(this, tr("Wallet Encryption Failed"),
QString("false password please try again"), QString("false password please try again"),
QMessageBox::Ok QMessageBox::Ok
); );
this->removeWalletEncryptionStartUp(); this->removeWalletEncryptionStartUp();
}else{} }else{}
}else{ }else{
this->doClosePw(); this->doClosePw();
} }
} }
QString MainWindow::getPassword() QString MainWindow::getPassword()

Loading…
Cancel
Save