From fe8a52b9c7ed2c8bc55050fe52fda77a81825d2d Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 11:30:27 +0200 Subject: [PATCH 01/22] add crypto_generichash for pw --- src/mainwindow.cpp | 68 ++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0e231f4..9af5c43 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,6 +22,8 @@ #include "chatmodel.h" #include "requestdialog.h" #include "websockets.h" +#include "sodium.h" +#include "sodium/crypto_generichash_blake2b.h" #include using json = nlohmann::json; @@ -251,17 +253,23 @@ void MainWindow::closeEvent(QCloseEvent* event) { QMainWindow::closeEvent(event); } +void dump_hex_buff(unsigned char buf[], unsigned int len) +{ + int i; + for (i=0; igetModel()->getEncryptionStatus(); + /* auto encStatus = rpc->getModel()->getEncryptionStatus(); if (encStatus.first) { QMessageBox::information(this, tr("Wallet is already encrypted"), tr("Your wallet is already encrypted with a password.\nPlease use 'Remove Wallet Encryption' if you want to remove the wallet encryption."), QMessageBox::Ok ); return; - } + }*/ QDialog d(this); Ui_encryptionDialog ed; @@ -278,12 +286,13 @@ void MainWindow::encryptWallet() { ed.lblPasswordMatch->setText(tr("Passwords don't match")); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } + }; QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); - ed.txtPassword->setText(""); + /* ed.txtPassword->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); auto fnShowError = [=](QString title, const json& res) { @@ -291,32 +300,43 @@ void MainWindow::encryptWallet() { tr("Error was:\n") + QString::fromStdString(res.dump()), QMessageBox::Ok ); - }; + };*/ if (d.exec() == QDialog::Accepted) { - rpc->encryptWallet(ed.txtPassword->text(), [=](json res) { - if (isJsonResultSuccess(res)) { - // Save the wallet - rpc->saveWallet([=] (json reply) { - if (isJsonResultSuccess(reply)) { - QMessageBox::information(this, tr("Wallet Encrypted"), - tr("Your wallet was successfully encrypted! The password will be needed to send funds or export private keys."), - QMessageBox::Ok - ); - } else { - fnShowError(tr("Wallet Encryption Failed"), reply); - } - }); + QString str = ed.txtPassword->text(); // data comes from a db in my case + int length = str.length(); + + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, str.toLocal8Bit(), length +1); + + #define MESSAGE ((const unsigned char *) sequence) + #define MESSAGE_LEN length + + + + qDebug()<<"Generating cryptographic key from password: " <refresh(true); - } else { - fnShowError(tr("Wallet Encryption Failed"), res); - } - }); - } } +} +//The following snippet demonstrates how to calculate the hash of a very long message using the init/update/final interface: + + + void MainWindow::removeWalletEncryption() { // Check if wallet is already encrypted auto encStatus = rpc->getModel()->getEncryptionStatus(); From 52f7a64417d74264a2d7f9cae9cd49d12041f423 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 11:38:58 +0200 Subject: [PATCH 02/22] add qdebugs --- src/mainwindow.cpp | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9af5c43..128d4c8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -261,15 +261,6 @@ void dump_hex_buff(unsigned char buf[], unsigned int len) } void MainWindow::encryptWallet() { - // Check if wallet is already encrypted - /* auto encStatus = rpc->getModel()->getEncryptionStatus(); - if (encStatus.first) { - QMessageBox::information(this, tr("Wallet is already encrypted"), - tr("Your wallet is already encrypted with a password.\nPlease use 'Remove Wallet Encryption' if you want to remove the wallet encryption."), - QMessageBox::Ok - ); - return; - }*/ QDialog d(this); Ui_encryptionDialog ed; @@ -292,18 +283,9 @@ void MainWindow::encryptWallet() { QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); - /* ed.txtPassword->setText(""); - ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - - auto fnShowError = [=](QString title, const json& res) { - QMessageBox::critical(this, title, - tr("Error was:\n") + QString::fromStdString(res.dump()), - QMessageBox::Ok - ); - };*/ - if (d.exec() == QDialog::Accepted) { - QString str = ed.txtPassword->text(); // data comes from a db in my case + + QString str = ed.txtPassword->text(); // data comes from user inputs int length = str.length(); char *sequence = NULL; @@ -313,8 +295,6 @@ void MainWindow::encryptWallet() { #define MESSAGE ((const unsigned char *) sequence) #define MESSAGE_LEN length - - qDebug()<<"Generating cryptographic key from password: " < Date: Sat, 23 May 2020 12:21:49 +0200 Subject: [PATCH 03/22] debug password --- src/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 128d4c8..42b511c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -295,10 +295,10 @@ void MainWindow::encryptWallet() { #define MESSAGE ((const unsigned char *) sequence) #define MESSAGE_LEN length - qDebug()<<"Generating cryptographic key from password: " < Date: Sat, 23 May 2020 12:44:13 +0200 Subject: [PATCH 04/22] encrypt addresslabels --- src/mainwindow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 42b511c..9138c7c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -307,6 +307,11 @@ void MainWindow::encryptWallet() { qDebug()<<"secret key generated:\n"; dump_hex_buff(hash,crypto_secretstream_xchacha20poly1305_KEYBYTES); + + QString source_file = "/home/denio/.local/share/Hush/SilentDragonLite/addresslabel.dat"; + QString target_file = "/home/denio/.local/share/Hush/SilentDragonLite/addresslabel-encrypt.dat"; + + FileEncryption::encrypt(target_file, source_file, hash); d.exec(); From a72ba09ee3680741347fb9cd81efc7cdbbf9695a Mon Sep 17 00:00:00 2001 From: Strider <127.0.0.1@404.found> Date: Sat, 23 May 2020 15:23:07 +0200 Subject: [PATCH 05/22] update// added some stuff --- .gdb_history | 6 ++++ peda-session-SilentDragonLite.txt | 2 +- silentdragon-lite.pro | 3 +- src/Crypto/FileEncryption.cpp | 48 +++++++++++++++++++------------ src/Crypto/FileEncryption.h | 6 ++++ src/Crypto/passwd.cpp | 39 +++++++++++++++++++++++++ src/Crypto/passwd.h | 14 +++++++++ src/FileSystem/FileSystem.cpp | 8 ++++++ 8 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 src/Crypto/passwd.cpp create mode 100644 src/Crypto/passwd.h diff --git a/.gdb_history b/.gdb_history index 4e303b8..06f6849 100644 --- a/.gdb_history +++ b/.gdb_history @@ -48,3 +48,9 @@ b FileSystem::writeContacts r n q +r +b FileEncryption::encrypt +r +s +n +q diff --git a/peda-session-SilentDragonLite.txt b/peda-session-SilentDragonLite.txt index f57fa7c..6f620bf 100644 --- a/peda-session-SilentDragonLite.txt +++ b/peda-session-SilentDragonLite.txt @@ -1,2 +1,2 @@ -break FileSystem::writeContacts +break FileEncryption::encrypt diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index 86f38b0..7d3a281 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -83,7 +83,8 @@ SOURCES += \ src/Chat/Helper/ChatIDGenerator.cpp \ src/Chat/Chat.cpp \ src/FileSystem/FileSystem.cpp \ - src/Crypto/FileEncryption.cpp + src/Crypto/FileEncryption.cpp \ + src/Crypto/passwd.cpp HEADERS += \ src/firsttimewizard.h \ diff --git a/src/Crypto/FileEncryption.cpp b/src/Crypto/FileEncryption.cpp index 0100585..fae9bbc 100644 --- a/src/Crypto/FileEncryption.cpp +++ b/src/Crypto/FileEncryption.cpp @@ -7,42 +7,48 @@ void FileEncryption::showConfig() int FileEncryption::encrypt(QString target_file, QString source_file, const unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES]) { - unsigned char buf_in[FILEENCRYPTION_CHUNK_SIZE]; - unsigned char buf_out[FILEENCRYPTION_CHUNK_SIZE + crypto_secretstream_xchacha20poly1305_ABYTES]; + unsigned char plain_data[FILEENCRYPTION_CHUNK_SIZE]; + unsigned char cipher_data[FILEENCRYPTION_CHUNK_SIZE + crypto_secretstream_xchacha20poly1305_ABYTES]; unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES]; - crypto_secretstream_xchacha20poly1305_state st; - FILE *fp_t, *fp_s; - unsigned long long out_len; + crypto_secretstream_xchacha20poly1305_state state; + FILE *target, *source; + unsigned long long cipher_len; size_t rlen; int eof; unsigned char tag; - fp_s = fopen(source_file.toStdString().c_str(), "rb"); - fp_t = fopen(target_file.toStdString().c_str(), "wb"); - crypto_secretstream_xchacha20poly1305_init_push(&st, header, key); - fwrite(header, 1, sizeof header, fp_t); + if(!FileEncryption::exists(source_file.toStdString())) + { + qDebug() << "File not exits" << source_file; + return -1; + } + + source = fopen(source_file.toStdString().c_str(), "rb"); + target = fopen(target_file.toStdString().c_str(), "wb"); + crypto_secretstream_xchacha20poly1305_init_push(&state, header, key); + fwrite(header, 1, sizeof header, target); do { - rlen = fread(buf_in, 1, sizeof buf_in, fp_s); - eof = feof(fp_s); + rlen = fread(plain_data, 1, sizeof plain_data, source); + eof = feof(source); tag = eof ? crypto_secretstream_xchacha20poly1305_TAG_FINAL : 0; crypto_secretstream_xchacha20poly1305_push( - &st, - buf_out, - &out_len, - buf_in, + &state, + cipher_data, + &cipher_len, + plain_data, rlen, NULL, 0, tag ); - fwrite(buf_out, 1, (size_t) out_len, fp_t); + fwrite(cipher_data, 1, (size_t) cipher_len, target); } while (! eof); - fclose(fp_t); - fclose(fp_s); + fclose(target); + fclose(source); return 0; } @@ -59,6 +65,12 @@ int FileEncryption::decrypt(QString target_file, QString source_file, const unsi int ret = -1; unsigned char tag; + if(!FileEncryption::exists(source_file.toStdString())) + { + qDebug() << "File not exits" << source_file; + return -1; + } + fp_s = fopen(source_file.toStdString().c_str(), "rb"); fp_t = fopen(target_file.toStdString().c_str(), "wb"); fread(header, 1, sizeof header, fp_s); diff --git a/src/Crypto/FileEncryption.h b/src/Crypto/FileEncryption.h index 6db8977..c7a09d5 100644 --- a/src/Crypto/FileEncryption.h +++ b/src/Crypto/FileEncryption.h @@ -3,11 +3,17 @@ #include #include #include +#include #define FILEENCRYPTION_CHUNK_SIZE 4096 class FileEncryption { + private: + inline static bool exists (const std::string& name) { + std::ifstream f(name.c_str()); + return f.good(); + } public: static void showConfig(); static int encrypt(QString target_file, QString source_file, const unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES]); diff --git a/src/Crypto/passwd.cpp b/src/Crypto/passwd.cpp new file mode 100644 index 0000000..83d5b27 --- /dev/null +++ b/src/Crypto/passwd.cpp @@ -0,0 +1,39 @@ +#include "passwd.h" + +void PASSWD::show_hex_buff(unsigned char buf[]) +{ + int i; + for (uint8_t i=0; i < crypto_secretstream_xchacha20poly1305_KEYBYTES; i++) + printf("%02X ", buf[i]); + printf("\n"); +} + +const unsigned char* PASSWD::hash(QString password) +{ + /*std::string data = password.toStdString(); + + unsigned char hash[crypto_generichash_BYTES]; + + crypto_generichash(hash, sizeof hash, + (const unsigned char*)data.c_str(), data.size(), + NULL, 0); + + //qDebug() << PASSWD::convertToHexString(hash); + return (const unsigned char*)hash;*/ + + int length = password.length(); + + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, password.toLocal8Bit(), length +1); + + #define MESSAGE ((const unsigned char *) sequence) + #define MESSAGE_LEN length + + qDebug()<<"Generating cryptographic key from password: " < +#include +#include + +class PASSWD +{ + public: + static void show_hex_buff(unsigned char buf[]); + static const unsigned char* hash(QString); +}; + +#endif \ No newline at end of file diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index d560d98..74a0440 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -2,6 +2,7 @@ #include #include +#include "../Crypto/passwd.h" FileSystem::FileSystem() { @@ -85,6 +86,13 @@ void FileSystem::writeContactsOldFormat(QString file, QList contact QList FileSystem::readContactsOldFormat(QString file) { + const unsigned char* data=PASSWD::hash(QString("Hello world")); + PASSWD::show_hex_buff((unsigned char*) data); + QString source_file = "/tmp/addresslabels.dat"; + QString target_file = "/tmp/addresslabels.dat.enc"; + FileEncryption::encrypt(target_file, source_file, data); + FileEncryption::decrypt("/tmp/addresslabels.dat.dec", target_file, data); + QList contacts; QFile _file(file); if (_file.exists()) From 6c3065684798252946de771b340e9447ab55c293 Mon Sep 17 00:00:00 2001 From: Strider <127.0.0.1@404.found> Date: Sat, 23 May 2020 19:36:04 +0200 Subject: [PATCH 06/22] update// addedh better stuff --- src/Crypto/passwd.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Crypto/passwd.cpp b/src/Crypto/passwd.cpp index 83d5b27..160e631 100644 --- a/src/Crypto/passwd.cpp +++ b/src/Crypto/passwd.cpp @@ -31,8 +31,21 @@ const unsigned char* PASSWD::hash(QString password) #define MESSAGE_LEN length qDebug()<<"Generating cryptographic key from password: " < Date: Sat, 23 May 2020 19:50:36 +0200 Subject: [PATCH 07/22] update// added really goody stuff :D --- src/FileSystem/FileSystem.cpp | 7 ------ src/mainwindow.cpp | 46 ++++++++++++----------------------- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index 74a0440..2a60de1 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -86,13 +86,6 @@ void FileSystem::writeContactsOldFormat(QString file, QList contact QList FileSystem::readContactsOldFormat(QString file) { - const unsigned char* data=PASSWD::hash(QString("Hello world")); - PASSWD::show_hex_buff((unsigned char*) data); - QString source_file = "/tmp/addresslabels.dat"; - QString target_file = "/tmp/addresslabels.dat.enc"; - FileEncryption::encrypt(target_file, source_file, data); - FileEncryption::decrypt("/tmp/addresslabels.dat.dec", target_file, data); - QList contacts; QFile _file(file); if (_file.exists()) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9138c7c..a2566ad 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,6 +25,9 @@ #include "sodium.h" #include "sodium/crypto_generichash_blake2b.h" #include +#include "FileSystem/FileSystem.h" +#include "Crypto/passwd.h" +#include "Crypto/FileEncryption.h" using json = nlohmann::json; @@ -283,39 +286,20 @@ void MainWindow::encryptWallet() { QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); - if (d.exec() == QDialog::Accepted) { - - QString str = ed.txtPassword->text(); // data comes from user inputs - int length = str.length(); - - char *sequence = NULL; - sequence = new char[length+1]; - strncpy(sequence, str.toLocal8Bit(), length +1); - - #define MESSAGE ((const unsigned char *) sequence) - #define MESSAGE_LEN length - - qDebug()<<"Generating cryptographic key from password: " <text()); + PASSWD::show_hex_buff((unsigned char*) key); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QString source_file = dir.filePath("addresslabels.dat"); + QString target_enc_file = dir.filePath("addresslabels.dat.enc"); + QString target_dec_file = dir.filePath("addresslabels.dat.dec"); + FileEncryption::encrypt(target_enc_file, source_file, key); + FileEncryption::decrypt(target_dec_file, target_enc_file, key); -d.exec(); + d.exec(); -} + } } From 735a673da3adff867a46896044cc6e6dd0b25676 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 20:43:42 +0200 Subject: [PATCH 08/22] gui element to decrypt --- src/mainwindow.cpp | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a2566ad..3fae23e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -293,18 +293,51 @@ void MainWindow::encryptWallet() { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); QString source_file = dir.filePath("addresslabels.dat"); QString target_enc_file = dir.filePath("addresslabels.dat.enc"); - QString target_dec_file = dir.filePath("addresslabels.dat.dec"); + //QString target_dec_file = dir.filePath("addresslabels.dat.dec"); FileEncryption::encrypt(target_enc_file, source_file, key); - FileEncryption::decrypt(target_dec_file, target_enc_file, key); + // FileEncryption::decrypt(target_dec_file, target_enc_file, key); - d.exec(); + d.exec(); } } void MainWindow::removeWalletEncryption() { - // Check if wallet is already encrypted + QDialog d(this); + Ui_encryptionDialog ed; + ed.setupUi(&d); + + // Handle edits on the password box + auto fnPasswordEdited = [=](const QString&) { + // Enable the OK button if the passwords match. + if (!ed.txtPassword->text().isEmpty() && + ed.txtPassword->text() == ed.txtConfirmPassword->text()) { + ed.lblPasswordMatch->setText(""); + ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } else { + ed.lblPasswordMatch->setText(tr("Passwords don't match")); + ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } + + }; + + QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); + QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); + + if (d.exec() == QDialog::Accepted) + { + const unsigned char* key=PASSWD::hash(ed.txtPassword->text()); + PASSWD::show_hex_buff((unsigned char*) key); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QString target_enc_file = dir.filePath("addresslabels.dat.enc"); + QString target_dec_file = dir.filePath("addresslabels.dat"); + FileEncryption::decrypt(target_dec_file, target_enc_file, key); + + d.exec(); + + } + /*// Check if wallet is already encrypted auto encStatus = rpc->getModel()->getEncryptionStatus(); if (!encStatus.first) { QMessageBox::information(this, tr("Wallet is not encrypted"), @@ -317,6 +350,8 @@ void MainWindow::removeWalletEncryption() { bool ok; QString password = QInputDialog::getText(this, tr("Wallet Password"), tr("Please enter your wallet password"), QLineEdit::Password, "", &ok); + + qDebug() << password; // If cancel was pressed, just return if (!ok) { @@ -356,7 +391,7 @@ void MainWindow::removeWalletEncryption() { QMessageBox::Ok ); } - }); + }); */ } void MainWindow::setupStatusBar() { From 5bb1634311768889640a34c9a5e3d8262dcd1b74 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 21:27:46 +0200 Subject: [PATCH 09/22] check for fileencryption before sdl start --- src/mainwindow.cpp | 14 +++++++++++++- src/mainwindow.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3fae23e..08b0bf5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -56,7 +56,12 @@ MainWindow::MainWindow(QWidget *parent) : ui->memoTxtChat->setPlaceholderText("Send Message"); ui->memoTxtChat->setTextColor(Qt::white); - + + // Check for encryption + if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("addresslabels.dat.enc"))) + { + this->removeWalletEncryption(); + } // Status Bar setupStatusBar(); @@ -185,6 +190,12 @@ MainWindow::MainWindow(QWidget *parent) : createWebsocket(wormholecode); } } + +bool MainWindow::fileExists(QString path) +{ + QFileInfo check_file(path); + return (check_file.exists() && check_file.isFile()); +} void MainWindow::createWebsocket(QString wormholecode) { qDebug() << "Listening for app connections on port 8777"; @@ -332,6 +343,7 @@ void MainWindow::removeWalletEncryption() { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); QString target_enc_file = dir.filePath("addresslabels.dat.enc"); QString target_dec_file = dir.filePath("addresslabels.dat"); + FileEncryption::decrypt(target_dec_file, target_enc_file, key); d.exec(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 85f4feb..9a6f02f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -100,6 +100,7 @@ private slots: private: + bool fileExists(QString path); void closeEvent(QCloseEvent* event); From e4dce6b06bc0b892422505777834c16b2fd5323e Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 22:50:50 +0200 Subject: [PATCH 10/22] encrypt wallet.dat also and check for it - work in progress --- src/mainwindow.cpp | 117 ++++++++++++++++++++++----------------------- src/mainwindow.h | 1 + 2 files changed, 57 insertions(+), 61 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 08b0bf5..88b33dd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent) : // Check for encryption if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("addresslabels.dat.enc"))) { - this->removeWalletEncryption(); + this->removeWalletEncryptionStartUp(); } // Status Bar @@ -302,16 +302,16 @@ void MainWindow::encryptWallet() { const unsigned char* key=PASSWD::hash(ed.txtPassword->text()); PASSWD::show_hex_buff((unsigned char*) key); auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString source_file = dir.filePath("addresslabels.dat"); QString target_enc_file = dir.filePath("addresslabels.dat.enc"); - //QString target_dec_file = dir.filePath("addresslabels.dat.dec"); + QString sourceWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); + QString target_encWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat.enc"); + FileEncryption::encrypt(target_enc_file, source_file, key); - // FileEncryption::decrypt(target_dec_file, target_enc_file, key); - - d.exec(); - + FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); } - + d.exec(); } void MainWindow::removeWalletEncryption() { @@ -341,69 +341,64 @@ void MainWindow::removeWalletEncryption() { const unsigned char* key=PASSWD::hash(ed.txtPassword->text()); PASSWD::show_hex_buff((unsigned char*) key); auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - QString target_enc_file = dir.filePath("addresslabels.dat.enc"); - QString target_dec_file = dir.filePath("addresslabels.dat"); + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); + QString target_decaddr_file = dir.filePath("addresslabels.dat"); + QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat.enc"); + QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); - FileEncryption::decrypt(target_dec_file, target_enc_file, key); + + FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); + FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - d.exec(); + } - /*// Check if wallet is already encrypted - auto encStatus = rpc->getModel()->getEncryptionStatus(); - if (!encStatus.first) { - QMessageBox::information(this, tr("Wallet is not encrypted"), - tr("Your wallet is not encrypted with a password."), - QMessageBox::Ok - ); - return; - } + d.exec(); +} - bool ok; - QString password = QInputDialog::getText(this, tr("Wallet Password"), - tr("Please enter your wallet password"), QLineEdit::Password, "", &ok); - - qDebug() << password; +void MainWindow::removeWalletEncryptionStartUp() { + QDialog d(this); + Ui_encryptionDialog ed; + ed.setupUi(&d); - // If cancel was pressed, just return - if (!ok) { - return; - } + // Handle edits on the password box + auto fnPasswordEdited = [=](const QString&) { + // Enable the OK button if the passwords match. + if (!ed.txtPassword->text().isEmpty() && + ed.txtPassword->text() == ed.txtConfirmPassword->text()) { + ed.lblPasswordMatch->setText(""); + ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } else { + ed.lblPasswordMatch->setText(tr("Passwords don't match")); + ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } - if (password.isEmpty()) { - QMessageBox::critical(this, tr("Wallet Decryption Failed"), - tr("Please enter a password to decrypt your wallet!"), - QMessageBox::Ok - ); - return; - } + }; - rpc->removeWalletEncryption(password, [=] (json res) { - if (isJsonResultSuccess(res)) { - // Save the wallet - rpc->saveWallet([=] (json reply) { - if(isJsonResultSuccess(reply)) { - QMessageBox::information(this, tr("Wallet Encryption Removed"), - tr("Your wallet was successfully decrypted! You will no longer need a password to send funds or export private keys."), - QMessageBox::Ok - ); - } else { - QMessageBox::critical(this, tr("Wallet Decryption Failed"), - QString::fromStdString(reply["error"].get()), - QMessageBox::Ok - ); - } - }); + QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); + QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); - // And then refresh the UI - rpc->refresh(true); - } else { - QMessageBox::critical(this, tr("Wallet Decryption Failed"), - QString::fromStdString(res["error"].get()), - QMessageBox::Ok - ); - } - }); */ + if (d.exec() == QDialog::Accepted) + { + const unsigned char* key=PASSWD::hash(ed.txtPassword->text()); + PASSWD::show_hex_buff((unsigned char*) key); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); + QString target_decaddr_file = dir.filePath("addresslabels.dat"); + QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat.enc"); + QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); + + + FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); + QThread::sleep(1); + FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); + + + + } + } void MainWindow::setupStatusBar() { diff --git a/src/mainwindow.h b/src/mainwindow.h index 9a6f02f..7384fc2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -130,6 +130,7 @@ private: void encryptWallet(); void removeWalletEncryption(); + void removeWalletEncryptionStartUp(); void cancelButton(); void sendButton(); From b03b926052cae5f9976e85b061b6dfce19b4b70f Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 23:13:58 +0200 Subject: [PATCH 11/22] new window for startup encryption process --- src/startupencryption.ui | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/startupencryption.ui diff --git a/src/startupencryption.ui b/src/startupencryption.ui new file mode 100644 index 0000000..fb923db --- /dev/null +++ b/src/startupencryption.ui @@ -0,0 +1,72 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + + From 4ea9a5e493c3c598da152bf2a84cbd793675daf8 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 23 May 2020 23:14:17 +0200 Subject: [PATCH 12/22] new window for startup encryption process --- silentdragon-lite.pro | 1 + src/encryption.ui | 114 ++++++++++++++-------------- src/mainwindow.cpp | 3 +- src/startupencryption.ui | 158 +++++++++++++++++++++++++++++++++------ 4 files changed, 195 insertions(+), 81 deletions(-) diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index 7d3a281..4fe9ad0 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -133,6 +133,7 @@ FORMS += \ src/confirm.ui \ src/privkey.ui \ src/memodialog.ui \ + src/startupencryption.ui \ src/viewalladdresses.ui \ src/connection.ui \ src/addressbook.ui \ diff --git a/src/encryption.ui b/src/encryption.ui index b4ab606..27c25a0 100644 --- a/src/encryption.ui +++ b/src/encryption.ui @@ -13,32 +13,50 @@ Encrypt Your Wallet - - - + + + - Qt::Horizontal + Qt::Vertical - + + + 20 + 40 + + + - - + + - Encryption Password: + <html><head/><body><p><span style=" font-size:14pt; color:#ef2929;">WARNING:</span> If you forget your password, the only way to recover the wallet is from the seed phrase. If you dont have Backup your seed phrase, please do it now!</p></body></html> + + + Qt::AlignCenter + + + true - - - - Confirm Password: + + + + Qt::Vertical - + + + 20 + 40 + + + - - - - QLineEdit::Password + + + + Qt::Horizontal @@ -55,6 +73,13 @@ + + + + Encryption Password: + + + @@ -62,27 +87,28 @@ - - - - Qt::Horizontal + + + + Confirm Password: - - - - WARNING: If you forget your password, the only way to recover the wallet is from the seed phrase. - - - Qt::AlignCenter + + + + QLineEdit::Password - - true + + + + + + Qt::Horizontal - + Qt::Horizontal @@ -95,32 +121,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 88b33dd..8985b3f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,6 +21,7 @@ #include "ui_requestContactDialog.h" #include "chatmodel.h" #include "requestdialog.h" +#include "ui_startupencryption.h" #include "websockets.h" #include "sodium.h" #include "sodium/crypto_generichash_blake2b.h" @@ -359,7 +360,7 @@ void MainWindow::removeWalletEncryption() { void MainWindow::removeWalletEncryptionStartUp() { QDialog d(this); - Ui_encryptionDialog ed; + Ui_startup ed; ed.setupUi(&d); // Handle edits on the password box diff --git a/src/startupencryption.ui b/src/startupencryption.ui index fb923db..6abdad1 100644 --- a/src/startupencryption.ui +++ b/src/startupencryption.ui @@ -1,10 +1,8 @@ - - - - - Dialog - - + + + startup + + 0 0 @@ -12,40 +10,155 @@ 300 - - Dialog + + SDL Startup Decryption - - + + - 30 - 240 + 50 + 260 341 32 - + Qt::Horizontal - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + 10 + 229 + 127 + 25 + + + + Confirm Password: + + + + + + 10 + 166 + 382 + 3 + + + + Qt::Horizontal + + + + + + 162 + 229 + 230 + 25 + + + + QLineEdit::Password + + + + + + 10 + 58 + 382 + 56 + + + + <html><head/><body><p>If you have forgotten your password, restore your wallet with your seed!</p></body></html> + + + Qt::AlignCenter + + + true + + + + + + 10 + 260 + 382 + 3 + + + + Qt::Horizontal + + + + + + 10 + 198 + 146 + 25 + + + + Encryption Password: + + + + + + 10 + 175 + 382 + 17 + + + + color: red; + + + Passwords don't match + + + Qt::AlignCenter + + + + + + 162 + 198 + 230 + 25 + + + + QLineEdit::Password + + - buttonBox accepted() - Dialog + startup accept() - + 248 254 - + 157 274 @@ -54,14 +167,14 @@ buttonBox rejected() - Dialog + startup reject() - + 316 260 - + 286 274 @@ -69,4 +182,3 @@ - From e2d6cb01c6da3127aaf2964bf3d03bd01716c265 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 08:49:22 +0200 Subject: [PATCH 13/22] add startup check for encryption, encrypt if sdl close --- src/Crypto/passwd.cpp | 58 ++++++------ src/Crypto/passwd.h | 2 +- src/encryption.ui | 27 +++--- src/mainwindow.cpp | 205 +++++++++++++++++++++++++++++++++++------- 4 files changed, 226 insertions(+), 66 deletions(-) diff --git a/src/Crypto/passwd.cpp b/src/Crypto/passwd.cpp index 160e631..98996b0 100644 --- a/src/Crypto/passwd.cpp +++ b/src/Crypto/passwd.cpp @@ -8,19 +8,9 @@ void PASSWD::show_hex_buff(unsigned char buf[]) printf("\n"); } -const unsigned char* PASSWD::hash(QString password) +const unsigned char* PASSWD::key(QString password) { - /*std::string data = password.toStdString(); - - unsigned char hash[crypto_generichash_BYTES]; - - crypto_generichash(hash, sizeof hash, - (const unsigned char*)data.c_str(), data.size(), - NULL, 0); - - //qDebug() << PASSWD::convertToHexString(hash); - return (const unsigned char*)hash;*/ - + int length = password.length(); char *sequence = NULL; @@ -29,24 +19,42 @@ const unsigned char* PASSWD::hash(QString password) #define MESSAGE ((const unsigned char *) sequence) #define MESSAGE_LEN length + + unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; + + crypto_hash_sha256(hash, MESSAGE, MESSAGE_LEN); + + qDebug()<<"Generating SaltHash from password: " < Encrypt Your Wallet - + @@ -27,7 +27,7 @@ - + <html><head/><body><p><span style=" font-size:14pt; color:#ef2929;">WARNING:</span> If you forget your password, the only way to recover the wallet is from the seed phrase. If you dont have Backup your seed phrase, please do it now!</p></body></html> @@ -53,14 +53,21 @@ - + Qt::Horizontal - + + + + <html><head/><body><p>10 letters minimum</p></body></html> + + + + color: red; @@ -73,42 +80,42 @@ - + Encryption Password: - + QLineEdit::Password - + Confirm Password: - + QLineEdit::Password - + Qt::Horizontal - + Qt::Horizontal diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8985b3f..e7d175b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + // Include css QString theme_name; try @@ -53,17 +54,16 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log")); - ui->memoTxtChat->setAutoFillBackground(false); - ui->memoTxtChat->setPlaceholderText("Send Message"); - ui->memoTxtChat->setTextColor(Qt::white); - - - // Check for encryption - if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("addresslabels.dat.enc"))) + // Check for encryption + if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"))) { this->removeWalletEncryptionStartUp(); } + ui->memoTxtChat->setAutoFillBackground(false); + ui->memoTxtChat->setPlaceholderText("Send Message"); + ui->memoTxtChat->setTextColor(Qt::white); + // Status Bar setupStatusBar(); @@ -263,6 +263,69 @@ void MainWindow::closeEvent(QCloseEvent* event) { // Let the RPC know to shut down any running service. rpc->shutdownhushd(); + +// Check is encryption is ON for SDl + if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"))) + + { + + + // delete old file before + + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile file1(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); + file1.remove(); + + // Encrypt our wallet.dat + QString str = "123";///just for testing. We set the user pw here + // QString str = ed.txtPassword->text(); // data comes from user inputs + int length = str.length(); + + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, str.toLocal8Bit(), length +1); + + #define MESSAGE ((const unsigned char *) sequence) + #define MESSAGE_LEN length + + unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; + + crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN); + + #define PASSWORD sequence + #define KEY_LEN crypto_box_SEEDBYTES + + + + /////////we use the Hash of the Password as Salt, not perfect but still a good solution. + + unsigned char key[KEY_LEN]; + + if (crypto_pwhash + (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, + crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, + crypto_pwhash_ALG_DEFAULT) != 0) { + /* out of memory */ +} + + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + // auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QString source_file = dir.filePath("addresslabels.dat"); + QString target_enc_file = dir.filePath("addresslabels.dat.enc"); + QString sourceWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); + QString target_encWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); + + FileEncryption::encrypt(target_enc_file, source_file, key); + FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); + + } +///////////////// we rename the plaintext wallet.dat to Backup, for testing. + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile file1(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + file1.remove(); + QFile file(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + file.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + // Bubble up if (event) QMainWindow::closeEvent(event); @@ -282,14 +345,17 @@ void MainWindow::encryptWallet() { ed.setupUi(&d); // Handle edits on the password box + + auto fnPasswordEdited = [=](const QString&) { // Enable the OK button if the passwords match. + QString password = ed.txtPassword->text(); if (!ed.txtPassword->text().isEmpty() && - ed.txtPassword->text() == ed.txtConfirmPassword->text()) { + ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 10) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { - ed.lblPasswordMatch->setText(tr("Passwords don't match")); + ed.lblPasswordMatch->setText(tr("Passwords don't match or You have entered too few letters (10 minimum)")); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } @@ -300,19 +366,49 @@ void MainWindow::encryptWallet() { if (d.exec() == QDialog::Accepted) { - const unsigned char* key=PASSWD::hash(ed.txtPassword->text()); - PASSWD::show_hex_buff((unsigned char*) key); + + QString str = ed.txtPassword->text(); // data comes from user inputs + int length = str.length(); + + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, str.toLocal8Bit(), length +1); + + #define MESSAGE ((const unsigned char *) sequence) + #define MESSAGE_LEN length + + unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; + + crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN); + + #define PASSWORD sequence + #define KEY_LEN crypto_box_SEEDBYTES + + + + /////////we use the Hash of the Password as Salt, not perfect but still a good solution. + + unsigned char key[KEY_LEN]; + + if (crypto_pwhash + (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, + crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, + crypto_pwhash_ALG_DEFAULT) != 0) { + /* out of memory */ +} + + qDebug()<<"Generating cryptographic key from password: " <text()); - PASSWD::show_hex_buff((unsigned char*) key); + QString str = ed.txtPassword->text(); // data comes from user inputs + int length = str.length(); + + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, str.toLocal8Bit(), length +1); + + #define MESSAGE ((const unsigned char *) sequence) + #define MESSAGE_LEN length + + unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; + + crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN); + + #define PASSWORD sequence + #define KEY_LEN crypto_box_SEEDBYTES + + + + /////////we use the Hash of the Password as Salt, not perfect but still a good solution. + + unsigned char key[KEY_LEN]; + + if (crypto_pwhash + (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, + crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, + crypto_pwhash_ALG_DEFAULT) != 0) { + /* out of memory */ +} auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); QString target_decaddr_file = dir.filePath("addresslabels.dat"); - QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat.enc"); + QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); @@ -354,8 +477,7 @@ void MainWindow::removeWalletEncryption() { - } - d.exec(); + } } void MainWindow::removeWalletEncryptionStartUp() { @@ -367,11 +489,11 @@ void MainWindow::removeWalletEncryptionStartUp() { auto fnPasswordEdited = [=](const QString&) { // Enable the OK button if the passwords match. if (!ed.txtPassword->text().isEmpty() && - ed.txtPassword->text() == ed.txtConfirmPassword->text()) { + ed.txtPassword->text() == ed.txtConfirmPassword->text()) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { - ed.lblPasswordMatch->setText(tr("Passwords don't match")); + ed.lblPasswordMatch->setText(tr("Passwords don't match or under-lettered")); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } @@ -382,22 +504,45 @@ void MainWindow::removeWalletEncryptionStartUp() { if (d.exec() == QDialog::Accepted) { - const unsigned char* key=PASSWD::hash(ed.txtPassword->text()); - PASSWD::show_hex_buff((unsigned char*) key); + QString str = ed.txtPassword->text(); // data comes from user inputs + int length = str.length(); + + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, str.toLocal8Bit(), length +1); + + #define MESSAGE ((const unsigned char *) sequence) + #define MESSAGE_LEN length + + unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; + + crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN); + + #define PASSWORD sequence + #define KEY_LEN crypto_box_SEEDBYTES + + + + /////////we use the Hash of the Password as Salt, not perfect but still a good solution. + + unsigned char key[KEY_LEN]; + + if (crypto_pwhash + (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, + crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, + crypto_pwhash_ALG_DEFAULT) != 0) { + /* out of memory */ + } auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); + QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); QString target_decaddr_file = dir.filePath("addresslabels.dat"); - QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat.enc"); - QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); - FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); - QThread::sleep(1); + // QThread::sleep(1); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - - - } } From 833ed7fc97cf91d779b4c11d813b57f1cf2e8d7b Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 09:10:39 +0200 Subject: [PATCH 14/22] new gui elements for encryption --- src/removeencryption.ui | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/removeencryption.ui diff --git a/src/removeencryption.ui b/src/removeencryption.ui new file mode 100644 index 0000000..fb923db --- /dev/null +++ b/src/removeencryption.ui @@ -0,0 +1,72 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + + From feb745457be289b60039095ba5e402ae18314a48 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 09:11:12 +0200 Subject: [PATCH 15/22] new gui elements for encryption --- silentdragon-lite.pro | 1 + src/encryption.ui | 10 +-- src/mainwindow.cpp | 39 +++++---- src/removeencryption.ui | 171 ++++++++++++++++++++++++++++++++++------ 4 files changed, 173 insertions(+), 48 deletions(-) diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index 4fe9ad0..89c9012 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -143,6 +143,7 @@ FORMS += \ src/requestContactDialog.ui \ src/newrecurring.ui \ src/requestdialog.ui \ + src/removeencryption.ui \ src/recurringmultiple.ui \ src/chatbubbleme.ui \ src/chatbubblepartner.ui diff --git a/src/encryption.ui b/src/encryption.ui index e0b3e2f..ae2643b 100644 --- a/src/encryption.ui +++ b/src/encryption.ui @@ -30,7 +30,7 @@ - <html><head/><body><p><span style=" font-size:14pt; color:#ef2929;">WARNING:</span> If you forget your password, the only way to recover the wallet is from the seed phrase. If you dont have Backup your seed phrase, please do it now!</p></body></html> + <html><head/><body><p><span style=" font-size:14pt; color:#ef2929;">WARNING:</span> If you forget your passphrase the only way to recover the wallet is from the seed phrase. If you dont have Backup your seed phrase, please do it now!</p></body></html> Qt::AlignCenter @@ -63,7 +63,7 @@ - <html><head/><body><p>10 letters minimum</p></body></html> + <html><head/><body><p>16 letters minimum</p></body></html> @@ -73,7 +73,7 @@ color: red; - Passwords don't match + Passphrase don't match Qt::AlignCenter @@ -83,7 +83,7 @@ - Encryption Password: + Encryption Passphrase: @@ -97,7 +97,7 @@ - Confirm Password: + Confirm Passphrase: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e7d175b..fd5be39 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,7 +21,8 @@ #include "ui_requestContactDialog.h" #include "chatmodel.h" #include "requestdialog.h" -#include "ui_startupencryption.h" +#include "ui_startupencryption.h" +#include "ui_removeencryption.h" #include "websockets.h" #include "sodium.h" #include "sodium/crypto_generichash_blake2b.h" @@ -268,18 +269,16 @@ void MainWindow::closeEvent(QCloseEvent* event) { if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"))) { - - // delete old file before auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QFile file1(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); - file1.remove(); + QFile fileoldencryption(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); + fileoldencryption.remove(); - // Encrypt our wallet.dat - QString str = "123";///just for testing. We set the user pw here - // QString str = ed.txtPassword->text(); // data comes from user inputs - int length = str.length(); + // Encrypt our wallet.dat + QString str = "123";///just for testing. We set the user pw here + // QString str = ed.txtPassword->text(); // data comes from user inputs + int length = str.length(); char *sequence = NULL; sequence = new char[length+1]; @@ -309,7 +308,7 @@ void MainWindow::closeEvent(QCloseEvent* event) { } auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - // auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + // auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString source_file = dir.filePath("addresslabels.dat"); QString target_enc_file = dir.filePath("addresslabels.dat.enc"); QString sourceWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); @@ -318,14 +317,16 @@ void MainWindow::closeEvent(QCloseEvent* event) { FileEncryption::encrypt(target_enc_file, source_file, key); FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); - } -///////////////// we rename the plaintext wallet.dat to Backup, for testing. - auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QFile file1(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); - file1.remove(); + ///////////////// we rename the plaintext wallet.dat to Backup, for testing. + + QFile fileoldbackup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + fileoldbackup.remove(); QFile file(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); file.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + } + + // Bubble up if (event) QMainWindow::closeEvent(event); @@ -351,11 +352,11 @@ void MainWindow::encryptWallet() { // Enable the OK button if the passwords match. QString password = ed.txtPassword->text(); if (!ed.txtPassword->text().isEmpty() && - ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 10) { + ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { - ed.lblPasswordMatch->setText(tr("Passwords don't match or You have entered too few letters (10 minimum)")); + ed.lblPasswordMatch->setText(tr("Passphrase don't match or You have entered too few letters (16 minimum)")); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } @@ -413,7 +414,7 @@ void MainWindow::encryptWallet() { void MainWindow::removeWalletEncryption() { QDialog d(this); - Ui_encryptionDialog ed; + Ui_removeencryption ed; ed.setupUi(&d); // Handle edits on the password box @@ -475,8 +476,6 @@ void MainWindow::removeWalletEncryption() { FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - - } } diff --git a/src/removeencryption.ui b/src/removeencryption.ui index fb923db..15f4f30 100644 --- a/src/removeencryption.ui +++ b/src/removeencryption.ui @@ -1,10 +1,8 @@ - - - - - Dialog - - + + + removeencryption + + 0 0 @@ -12,40 +10,168 @@ 300 - - Dialog + + Remove your Wallet encryption - - + + - 30 - 240 + 50 + 260 341 32 - + Qt::Horizontal - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + 260 + 170 + 133 + 23 + + + + <html><head/><body><p>16 letters minimum</p></body></html> + + + + + + 10 + 229 + 157 + 25 + + + + Confirm Passphrase: + + + + + + 10 + 164 + 382 + 3 + + + + Qt::Horizontal + + + + + + 173 + 229 + 219 + 25 + + + + QLineEdit::Password + + + + + + 10 + 56 + 382 + 56 + + + + <html><head/><body><p><span style=" font-size:14pt; color:#ef2929;">WARNING:</span> If yo remove your encryption, all your Data is Plaintext on your Disk!</p></body></html> + + + Qt::AlignCenter + + + true + + + + + + 10 + 260 + 382 + 3 + + + + Qt::Horizontal + + + + + + 10 + 198 + 157 + 25 + + + + Encryption Passphrase: + + + + + + 10 + 175 + 243 + 17 + + + + color: red; + + + Passphrase don't match + + + Qt::AlignCenter + + + + + + 173 + 198 + 219 + 25 + + + + QLineEdit::Password + + - buttonBox accepted() - Dialog + removeencryption accept() - + 248 254 - + 157 274 @@ -54,14 +180,14 @@ buttonBox rejected() - Dialog + removeencryption reject() - + 316 260 - + 286 274 @@ -69,4 +195,3 @@ - From c12a4ffe73ba0969d23b412403709cb33ec14459 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 09:39:50 +0200 Subject: [PATCH 16/22] use userpw for encryption at sdl close --- src/mainwindow.cpp | 15 ++++++++++++++- src/mainwindow.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fd5be39..5bb0740 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -276,7 +276,7 @@ void MainWindow::closeEvent(QCloseEvent* event) { fileoldencryption.remove(); // Encrypt our wallet.dat - QString str = "123";///just for testing. We set the user pw here + QString str = this->getPassword(); // QString str = ed.txtPassword->text(); // data comes from user inputs int length = str.length(); @@ -351,6 +351,7 @@ void MainWindow::encryptWallet() { auto fnPasswordEdited = [=](const QString&) { // Enable the OK button if the passwords match. QString password = ed.txtPassword->text(); + this->setPassword(password); if (!ed.txtPassword->text().isEmpty() && ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { ed.lblPasswordMatch->setText(""); @@ -546,6 +547,18 @@ void MainWindow::removeWalletEncryptionStartUp() { } +QString MainWindow::getPassword() +{ + + return _password; +} + +void MainWindow::setPassword(QString password) +{ + + _password = password; +} + void MainWindow::setupStatusBar() { // Status Bar loadingLabel = new QLabel(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 7384fc2..e80af01 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -51,6 +51,8 @@ public: QString doSendChatTxValidations(Tx tx); QString doSendRequestTxValidations(Tx tx); QString getCid(); + QString getPassword(); + void setPassword(QString Password); void replaceWormholeClient(WormholeClient* newClient); bool isWebsocketListening(); @@ -120,6 +122,7 @@ private: void setupStatusBar(); void clearSendForm(); + QString _password; Tx createTxFromSendPage(); bool confirmTx(Tx tx, RecurringPaymentInfo* rpi); From 06b3f0370f9de519c5cc9e3cd9849eb098003a6d Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 09:55:01 +0200 Subject: [PATCH 17/22] use userpw for encryption at sdl close --- src/mainwindow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5bb0740..49f4f72 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -477,6 +477,9 @@ void MainWindow::removeWalletEncryption() { FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); + QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); + filencrypted.remove(); + } } @@ -486,6 +489,8 @@ void MainWindow::removeWalletEncryptionStartUp() { ed.setupUi(&d); // Handle edits on the password box + QString password = ed.txtPassword->text(); + auto fnPasswordEdited = [=](const QString&) { // Enable the OK button if the passwords match. if (!ed.txtPassword->text().isEmpty() && @@ -506,7 +511,7 @@ void MainWindow::removeWalletEncryptionStartUp() { { QString str = ed.txtPassword->text(); // data comes from user inputs int length = str.length(); - + this->setPassword(str); char *sequence = NULL; sequence = new char[length+1]; strncpy(sequence, str.toLocal8Bit(), length +1); From 0071ee1f093ce4399c5fe6522485eeceb4356897 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 12:35:20 +0200 Subject: [PATCH 18/22] check for wrong password --- src/mainwindow.cpp | 67 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 49f4f72..ee93f6f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -466,21 +466,46 @@ void MainWindow::removeWalletEncryption() { crypto_pwhash_ALG_DEFAULT) != 0) { /* out of memory */ } + + QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); + filencrypted.remove(); + + { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); - QString target_decaddr_file = dir.filePath("addresslabels.dat"); QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); + QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); + QString target_decaddr_file = dir.filePath("addresslabels.dat"); - FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); - filencrypted.remove(); - } + + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + + if (filencrypted.size() > 0) + { + + QMessageBox::information(this, tr("Wallet Encryption Success"), + QString("SDL is ready to Rock"), + QMessageBox::Ok + ); + }else{ + + qDebug()<<"verschlüsselung gescheitert "; + + QMessageBox::critical(this, tr("Wallet Encryption Failed"), + QString("false password please try again"), + QMessageBox::Ok + ); + this->removeWalletEncryptionStartUp(); + } + + } + } void MainWindow::removeWalletEncryptionStartUp() { @@ -532,12 +557,15 @@ void MainWindow::removeWalletEncryptionStartUp() { unsigned char key[KEY_LEN]; - if (crypto_pwhash + if (crypto_pwhash (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_ALG_DEFAULT) != 0) { /* out of memory */ } + + + { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); @@ -546,8 +574,31 @@ void MainWindow::removeWalletEncryptionStartUp() { QString target_decaddr_file = dir.filePath("addresslabels.dat"); FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); - // QThread::sleep(1); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); + + } + + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + + if (filencrypted.size() > 0) + { + + QMessageBox::information(this, tr("Wallet Encryption Success"), + QString("SDL is ready to Rock"), + QMessageBox::Ok + ); + }else{ + + qDebug()<<"verschlüsselung gescheitert "; + + QMessageBox::critical(this, tr("Wallet Encryption Failed"), + QString("false password please try again"), + QMessageBox::Ok + ); + this->removeWalletEncryptionStartUp(); + } + } } From d5138b8fa247a55635f67ca7ecabf86f01d42b4f Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 13:15:57 +0200 Subject: [PATCH 19/22] prevent to open sdl without pw --- src/mainwindow.cpp | 73 +++++++++++++++++++++++++---------------- src/mainwindow.h | 2 ++ src/removeencryption.ui | 2 +- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ee93f6f..681391a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -252,6 +252,10 @@ void MainWindow::doClose() { closeEvent(nullptr); } +void MainWindow::doClosePw() { + closeEventpw(nullptr); +} + void MainWindow::closeEvent(QCloseEvent* event) { QSettings s; @@ -261,8 +265,7 @@ void MainWindow::closeEvent(QCloseEvent* event) { s.sync(); - // Let the RPC know to shut down any running service. - rpc->shutdownhushd(); + // Check is encryption is ON for SDl @@ -318,27 +321,30 @@ void MainWindow::closeEvent(QCloseEvent* event) { FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); ///////////////// we rename the plaintext wallet.dat to Backup, for testing. - - QFile fileoldbackup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); - fileoldbackup.remove(); + QFile file(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); file.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); } - + // Let the RPC know to shut down any running service. + rpc->shutdownhushd(); // Bubble up if (event) QMainWindow::closeEvent(event); } -void dump_hex_buff(unsigned char buf[], unsigned int len) -{ - int i; - for (i=0; ishutdownhushd(); + + // Bubble up + if (event) + QMainWindow::closeEvent(event); } + void MainWindow::encryptWallet() { QDialog d(this); @@ -351,7 +357,7 @@ void MainWindow::encryptWallet() { auto fnPasswordEdited = [=](const QString&) { // Enable the OK button if the passwords match. QString password = ed.txtPassword->text(); - this->setPassword(password); + if (!ed.txtPassword->text().isEmpty() && ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { ed.lblPasswordMatch->setText(""); @@ -371,6 +377,7 @@ void MainWindow::encryptWallet() { QString str = ed.txtPassword->text(); // data comes from user inputs int length = str.length(); + this->setPassword(str); char *sequence = NULL; sequence = new char[length+1]; @@ -399,8 +406,6 @@ void MainWindow::encryptWallet() { /* out of memory */ } - qDebug()<<"Generating cryptographic key from password: " <text(); auto fnPasswordEdited = [=](const QString&) { // Enable the OK button if the passwords match. if (!ed.txtPassword->text().isEmpty() && - ed.txtPassword->text() == ed.txtConfirmPassword->text()) { + ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { @@ -466,11 +472,9 @@ void MainWindow::removeWalletEncryption() { crypto_pwhash_ALG_DEFAULT) != 0) { /* out of memory */ } + - QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); - filencrypted.remove(); - - { + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); @@ -481,29 +485,35 @@ void MainWindow::removeWalletEncryption() { FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - } + - auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); if (filencrypted.size() > 0) { - QMessageBox::information(this, tr("Wallet Encryption Success"), + QMessageBox::information(this, tr("Wallet decryption Success"), QString("SDL is ready to Rock"), QMessageBox::Ok - ); + ); + + filencrypted.remove(); + }else{ qDebug()<<"verschlüsselung gescheitert "; QMessageBox::critical(this, tr("Wallet Encryption Failed"), - QString("false password please try again"), + QString("false password, please try again"), QMessageBox::Ok ); this->removeWalletEncryptionStartUp(); } + }else{ + + this->doClosePw(); } } @@ -514,12 +524,12 @@ void MainWindow::removeWalletEncryptionStartUp() { ed.setupUi(&d); // Handle edits on the password box - QString password = ed.txtPassword->text(); auto fnPasswordEdited = [=](const QString&) { + QString password = ed.txtPassword->text(); // Enable the OK button if the passwords match. if (!ed.txtPassword->text().isEmpty() && - ed.txtPassword->text() == ed.txtConfirmPassword->text()) { + ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { @@ -580,6 +590,8 @@ void MainWindow::removeWalletEncryptionStartUp() { auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + if (filencrypted.size() > 0) { @@ -587,7 +599,9 @@ void MainWindow::removeWalletEncryptionStartUp() { QMessageBox::information(this, tr("Wallet Encryption Success"), QString("SDL is ready to Rock"), QMessageBox::Ok - ); + ); + + backup.remove(); }else{ qDebug()<<"verschlüsselung gescheitert "; @@ -599,8 +613,11 @@ void MainWindow::removeWalletEncryptionStartUp() { this->removeWalletEncryptionStartUp(); } + }else{ + + this->doClosePw(); } - + } QString MainWindow::getPassword() diff --git a/src/mainwindow.h b/src/mainwindow.h index e80af01..7ec42ba 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -88,6 +88,7 @@ public: Logger* logger; void doClose(); + void doClosePw(); QString createHeaderMemo(QString type, QString cid, QString zaddr, int version, int headerNumber); public slots: @@ -104,6 +105,7 @@ private: bool fileExists(QString path); void closeEvent(QCloseEvent* event); + void closeEventpw(QCloseEvent* event); void setupSendTab(); diff --git a/src/removeencryption.ui b/src/removeencryption.ui index 15f4f30..77d7239 100644 --- a/src/removeencryption.ui +++ b/src/removeencryption.ui @@ -181,7 +181,7 @@ buttonBox rejected() removeencryption - reject() + close() 316 From 79aecae12ea603fc29e02b7723e23d5978627392 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 13:25:12 +0200 Subject: [PATCH 20/22] rename to .backup at sdl end --- src/mainwindow.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 681391a..cd2bd34 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -266,7 +266,8 @@ void MainWindow::closeEvent(QCloseEvent* event) { s.sync(); - + // Let the RPC know to shut down any running service. + rpc->shutdownhushd(); // Check is encryption is ON for SDl if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"))) @@ -324,10 +325,10 @@ void MainWindow::closeEvent(QCloseEvent* event) { QFile file(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); file.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + } - // Let the RPC know to shut down any running service. - rpc->shutdownhushd(); + // Bubble up if (event) @@ -591,6 +592,7 @@ void MainWindow::removeWalletEncryptionStartUp() { auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + if (filencrypted.size() > 0) From 309c1acbcc5ac274b5893014f39a8e6f569d2694 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 15:24:06 +0200 Subject: [PATCH 21/22] some gui fixes --- src/mainwindow.cpp | 58 ++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cd2bd34..a8c5e03 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -323,10 +323,10 @@ void MainWindow::closeEvent(QCloseEvent* event) { ///////////////// we rename the plaintext wallet.dat to Backup, for testing. - QFile file(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); - file.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); - - + QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile address(dir.filePath("addresslabels.dat")); + wallet.remove(); + address.remove(); } @@ -416,6 +416,11 @@ void MainWindow::encryptWallet() { FileEncryption::encrypt(target_enc_file, source_file, key); FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); + + QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile address(dir.filePath("addresslabels.dat")); + wallet.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBackup")); + address.rename(dir.filePath("addresslabels.datBackup")); } } @@ -424,12 +429,11 @@ void MainWindow::removeWalletEncryption() { Ui_removeencryption ed; ed.setupUi(&d); - // Handle edits on the password box - QString password = ed.txtPassword->text(); - auto fnPasswordEdited = [=](const QString&) { + auto fnPasswordEdited = [=](const QString&) { + QString password = ed.txtPassword->text(); // Enable the OK button if the passwords match. if (!ed.txtPassword->text().isEmpty() && - ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { + ed.txtPassword->text() == ed.txtConfirmPassword->text() && password.size() >= 16) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { @@ -485,17 +489,15 @@ void MainWindow::removeWalletEncryption() { FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - - - - QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); + QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); - if (filencrypted.size() > 0) + if (wallet.size() > 0) { QMessageBox::information(this, tr("Wallet decryption Success"), - QString("SDL is ready to Rock"), + QString("Successfully delete the encryption"), QMessageBox::Ok ); @@ -506,15 +508,12 @@ void MainWindow::removeWalletEncryption() { qDebug()<<"verschlüsselung gescheitert "; QMessageBox::critical(this, tr("Wallet Encryption Failed"), - QString("false password, please try again"), + QString("False password, please try again"), QMessageBox::Ok ); - this->removeWalletEncryptionStartUp(); + this->removeWalletEncryption(); } - }else{ - - this->doClosePw(); } } @@ -590,20 +589,29 @@ void MainWindow::removeWalletEncryptionStartUp() { } auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); - QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP")); + QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + //QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP"));*/ - - - if (filencrypted.size() > 0) + if (wallet.size() > 0) { + if (fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.datBackup"))) + + { + + QMessageBox::warning(this, tr("You have still Plaintextdata on your disk!"), + QString("WARNING: Delete it only if you have a backup of your Wallet Seed."), + QMessageBox::Ok + ); + // backup.remove(); + + } QMessageBox::information(this, tr("Wallet Encryption Success"), QString("SDL is ready to Rock"), QMessageBox::Ok ); - backup.remove(); + }else{ qDebug()<<"verschlüsselung gescheitert "; From c79bf0046d8dd0e5e6b3bdb4b8f03519b1f76f36 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 24 May 2020 16:51:55 +0200 Subject: [PATCH 22/22] fix for win --- src/mainwindow.cpp | 54 ++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a8c5e03..1f16a60 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -33,6 +33,19 @@ using json = nlohmann::json; + + +#ifdef Q_OS_WIN +auto dirwallet = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite/silentdragonlite-wallet.dat"); +auto dirwalletenc = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite/silentdragonlite-wallet-enc.dat"); +auto dirwalletbackup = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite/silentdragonlite-wallet.datBackup"); +#endif +#ifdef Q_OS_UNIX +auto dirwallet = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.dat"); +auto dirwalletenc = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); +auto dirwalletbackup = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.datBackup"); +#endif + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -56,7 +69,10 @@ MainWindow::MainWindow(QWidget *parent) : logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log")); // Check for encryption - if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"))) + + + + if(fileExists(dirwalletenc)) { this->removeWalletEncryptionStartUp(); } @@ -270,13 +286,13 @@ void MainWindow::closeEvent(QCloseEvent* event) { rpc->shutdownhushd(); // Check is encryption is ON for SDl - if(fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"))) + if(fileExists(dirwalletenc)) { // delete old file before - auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QFile fileoldencryption(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); + //auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile fileoldencryption(dirwalletenc); fileoldencryption.remove(); // Encrypt our wallet.dat @@ -315,15 +331,15 @@ void MainWindow::closeEvent(QCloseEvent* event) { // auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString source_file = dir.filePath("addresslabels.dat"); QString target_enc_file = dir.filePath("addresslabels.dat.enc"); - QString sourceWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); - QString target_encWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); + QString sourceWallet_file = dirwallet; + QString target_encWallet_file = dirwalletenc; FileEncryption::encrypt(target_enc_file, source_file, key); FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); ///////////////// we rename the plaintext wallet.dat to Backup, for testing. - QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile wallet(dirwallet); QFile address(dir.filePath("addresslabels.dat")); wallet.remove(); address.remove(); @@ -411,15 +427,15 @@ void MainWindow::encryptWallet() { auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); QString source_file = dir.filePath("addresslabels.dat"); QString target_enc_file = dir.filePath("addresslabels.dat.enc"); - QString sourceWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); - QString target_encWallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); + QString sourceWallet_file = dirwallet; + QString target_encWallet_file = dirwalletenc; FileEncryption::encrypt(target_enc_file, source_file, key); FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); - QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile wallet(dirwallet); QFile address(dir.filePath("addresslabels.dat")); - wallet.rename(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBackup")); + wallet.rename(dirwalletbackup); address.rename(dir.filePath("addresslabels.datBackup")); } } @@ -482,16 +498,16 @@ void MainWindow::removeWalletEncryption() { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); - QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); + QString target_encwallet_file = dirwalletenc; + QString target_decwallet_file = dirwallet; QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); QString target_decaddr_file = dir.filePath("addresslabels.dat"); FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); - QFile filencrypted(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat")); - QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile filencrypted(dirwalletenc); + QFile wallet(dirwallet); if (wallet.size() > 0) { @@ -578,8 +594,8 @@ void MainWindow::removeWalletEncryptionStartUp() { { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QString target_encwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet-enc.dat"); - QString target_decwallet_file = dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat"); + QString target_encwallet_file = dirwalletenc; + QString target_decwallet_file = dirwallet; QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); QString target_decaddr_file = dir.filePath("addresslabels.dat"); @@ -589,12 +605,12 @@ void MainWindow::removeWalletEncryptionStartUp() { } auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QFile wallet(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.dat")); + QFile wallet(dirwallet); //QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP"));*/ if (wallet.size() > 0) { - if (fileExists(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.datBackup"))) + if (fileExists(dirwalletbackup)) {