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..89c9012 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 \ @@ -132,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 \ @@ -141,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/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..98996b0 --- /dev/null +++ b/src/Crypto/passwd.cpp @@ -0,0 +1,60 @@ +#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::key(QString password) +{ + + 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 + + unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; + + crypto_hash_sha256(hash, MESSAGE, MESSAGE_LEN); + + qDebug()<<"Generating SaltHash from password: " < +#include +#include + +class PASSWD +{ + public: + static void show_hex_buff(unsigned char buf[]); + static const unsigned char* key(QString); +}; + +#endif \ No newline at end of file diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index d560d98..2a60de1 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -2,6 +2,7 @@ #include #include +#include "../Crypto/passwd.h" FileSystem::FileSystem() { diff --git a/src/encryption.ui b/src/encryption.ui index b4ab606..ae2643b 100644 --- a/src/encryption.ui +++ b/src/encryption.ui @@ -14,71 +14,104 @@ 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 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 + + + true - - - - Confirm Password: + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal - - - - QLineEdit::Password + + + + <html><head/><body><p>16 letters minimum</p></body></html> - + color: red; - Passwords don't match + Passphrase don't match Qt::AlignCenter - + + + + Encryption Passphrase: + + + + QLineEdit::Password - - - - Qt::Horizontal + + + + Confirm Passphrase: - - - - 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 @@ -95,32 +128,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0e231f4..1f16a60 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,15 +21,36 @@ #include "ui_requestContactDialog.h" #include "chatmodel.h" #include "requestdialog.h" +#include "ui_startupencryption.h" +#include "ui_removeencryption.h" #include "websockets.h" +#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; + + +#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) { + // Include css QString theme_name; try @@ -47,12 +68,19 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log")); + // Check for encryption + + + + if(fileExists(dirwalletenc)) + { + this->removeWalletEncryptionStartUp(); + } + ui->memoTxtChat->setAutoFillBackground(false); ui->memoTxtChat->setPlaceholderText("Send Message"); ui->memoTxtChat->setTextColor(Qt::white); - - - + // Status Bar setupStatusBar(); @@ -180,6 +208,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"; @@ -234,6 +268,10 @@ void MainWindow::doClose() { closeEvent(nullptr); } +void MainWindow::doClosePw() { + closeEventpw(nullptr); +} + void MainWindow::closeEvent(QCloseEvent* event) { QSettings s; @@ -243,6 +281,78 @@ 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(dirwalletenc)) + + { + // delete old file before + + //auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile fileoldencryption(dirwalletenc); + fileoldencryption.remove(); + + // Encrypt our wallet.dat + QString str = this->getPassword(); + // 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 = 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(dirwallet); + QFile address(dir.filePath("addresslabels.dat")); + wallet.remove(); + address.remove(); + } + + + // Bubble up + if (event) + QMainWindow::closeEvent(event); +} + +void MainWindow::closeEventpw(QCloseEvent* event) { + // Let the RPC know to shut down any running service. rpc->shutdownhushd(); @@ -253,124 +363,299 @@ void MainWindow::closeEvent(QCloseEvent* event) { 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; 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() >= 16) { ed.lblPasswordMatch->setText(""); ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { - ed.lblPasswordMatch->setText(tr("Passwords don't match")); + ed.lblPasswordMatch->setText(tr("Passphrase don't match or You have entered too few letters (16 minimum)")); 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.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + if (d.exec() == QDialog::Accepted) + { - auto fnShowError = [=](QString title, const json& res) { - QMessageBox::critical(this, title, - tr("Error was:\n") + QString::fromStdString(res.dump()), - QMessageBox::Ok - ); - }; + QString str = ed.txtPassword->text(); // data comes from user inputs + int length = str.length(); + this->setPassword(str); - 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); - } - }); + char *sequence = NULL; + sequence = new char[length+1]; + strncpy(sequence, str.toLocal8Bit(), length +1); - // And then refresh the UI - rpc->refresh(true); - } else { - fnShowError(tr("Wallet Encryption Failed"), res); - } - }); + #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 = dirwallet; + QString target_encWallet_file = dirwalletenc; + + FileEncryption::encrypt(target_enc_file, source_file, key); + FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); + + QFile wallet(dirwallet); + QFile address(dir.filePath("addresslabels.dat")); + wallet.rename(dirwalletbackup); + address.rename(dir.filePath("addresslabels.datBackup")); } } void MainWindow::removeWalletEncryption() { - // 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."), + QDialog d(this); + Ui_removeencryption ed; + ed.setupUi(&d); + + 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.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) + { + 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 = 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(dirwalletenc); + QFile wallet(dirwallet); + + if (wallet.size() > 0) + { + + QMessageBox::information(this, tr("Wallet decryption Success"), + QString("Successfully delete the encryption"), + QMessageBox::Ok + ); + + filencrypted.remove(); + + }else{ + + qDebug()<<"verschlüsselung gescheitert "; + + QMessageBox::critical(this, tr("Wallet Encryption Failed"), + QString("False password, please try again"), QMessageBox::Ok ); - return; + this->removeWalletEncryption(); + } + } + +} - bool ok; - QString password = QInputDialog::getText(this, tr("Wallet Password"), - tr("Please enter your wallet password"), QLineEdit::Password, "", &ok); +void MainWindow::removeWalletEncryptionStartUp() { + QDialog d(this); + Ui_startup ed; + ed.setupUi(&d); - // If cancel was pressed, just return - if (!ok) { - return; - } + // Handle edits on the password box + + 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.lblPasswordMatch->setText(""); + ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } else { + ed.lblPasswordMatch->setText(tr("Passwords don't match or under-lettered")); + 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); + + if (d.exec() == QDialog::Accepted) + { + 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); + + #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 = 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); + + } + + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile wallet(dirwallet); + //QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP"));*/ + + if (wallet.size() > 0) + { + if (fileExists(dirwalletbackup)) + + { + + 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 + ); + + + }else{ - // And then refresh the UI - rpc->refresh(true); - } else { - QMessageBox::critical(this, tr("Wallet Decryption Failed"), - QString::fromStdString(res["error"].get()), + qDebug()<<"verschlüsselung gescheitert "; + + QMessageBox::critical(this, tr("Wallet Encryption Failed"), + QString("false password please try again"), QMessageBox::Ok ); - } - }); + this->removeWalletEncryptionStartUp(); + } + + }else{ + + this->doClosePw(); + } + +} + +QString MainWindow::getPassword() +{ + + return _password; +} + +void MainWindow::setPassword(QString password) +{ + + _password = password; } void MainWindow::setupStatusBar() { diff --git a/src/mainwindow.h b/src/mainwindow.h index 85f4feb..7ec42ba 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(); @@ -86,6 +88,7 @@ public: Logger* logger; void doClose(); + void doClosePw(); QString createHeaderMemo(QString type, QString cid, QString zaddr, int version, int headerNumber); public slots: @@ -100,7 +103,9 @@ private slots: private: + bool fileExists(QString path); void closeEvent(QCloseEvent* event); + void closeEventpw(QCloseEvent* event); void setupSendTab(); @@ -119,6 +124,7 @@ private: void setupStatusBar(); void clearSendForm(); + QString _password; Tx createTxFromSendPage(); bool confirmTx(Tx tx, RecurringPaymentInfo* rpi); @@ -129,6 +135,7 @@ private: void encryptWallet(); void removeWalletEncryption(); + void removeWalletEncryptionStartUp(); void cancelButton(); void sendButton(); diff --git a/src/removeencryption.ui b/src/removeencryption.ui new file mode 100644 index 0000000..77d7239 --- /dev/null +++ b/src/removeencryption.ui @@ -0,0 +1,197 @@ + + + removeencryption + + + + 0 + 0 + 400 + 300 + + + + Remove your Wallet encryption + + + + + 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() + removeencryption + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + removeencryption + close() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/startupencryption.ui b/src/startupencryption.ui new file mode 100644 index 0000000..6abdad1 --- /dev/null +++ b/src/startupencryption.ui @@ -0,0 +1,184 @@ + + + startup + + + + 0 + 0 + 400 + 300 + + + + SDL Startup Decryption + + + + + 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() + startup + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + startup + reject() + + + 316 + 260 + + + 286 + 274 + + + + +