From f872c0af6b3a8c6116c580cf9883ac21e14b4d6b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Jul 2021 22:25:47 -0400 Subject: [PATCH 1/9] add debugging --- lib/src/lib.rs | 2 +- src/mainwindow.cpp | 71 +++++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 7bd193f..6f73c6d 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -223,4 +223,4 @@ pub extern fn litelib_rust_free_string(s: *mut c_char) { if s.is_null() { return } CString::from_raw(s) }; -} \ No newline at end of file +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b1b4037..150da2f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -516,16 +516,22 @@ void MainWindow::encryptWallet() { } void MainWindow::removeWalletEncryption() { + qDebug() << __func__ << ": removing wallet encryption"; QDialog d(this); Ui_removeencryption ed; ed.setupUi(&d); + qDebug() << __func__ << ": done with setupUi"; + if (fileExists(dirwalletenc) == false) { QMessageBox::information(this, tr("Wallet is not encrypted"), tr("Your wallet is not encrypted with a passphrase."), QMessageBox::Ok ); + qDebug() << __func__ << ": wallet=" << dirwalletenc << " does NOT exist"; return; + } else { + qDebug() << __func__ << ": wallet=" << dirwalletenc << " exists"; } auto fnPasswordEdited = [=](const QString&) { @@ -545,12 +551,16 @@ void MainWindow::removeWalletEncryption() { QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); + qDebug() << __func__ << ": connected GUI events"; + if (d.exec() == QDialog::Accepted) { QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL"); int length = passphrase.length(); + qDebug() << __func__ << ": Passphrase length = " << length; + char *sequence = NULL; sequence = new char[length+1]; strncpy(sequence, passphrase.toUtf8(), length +1); @@ -561,7 +571,6 @@ void MainWindow::removeWalletEncryption() { sequence1 = new char[length+1]; strncpy(sequence1, passphraseHash.toUtf8(), length+1); - #define hash ((const unsigned char *) sequence1) #define PASSWORD sequence #define KEY_LEN crypto_box_SEEDBYTES @@ -571,43 +580,41 @@ void MainWindow::removeWalletEncryption() { 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() << "crypto_pwhash failed!"; - return; + qDebug() << __func__ << ": crypto_pwhash failed! Possibly out of memory"; + return; } - auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QString target_encwallet_file = dirwalletenc; - QString target_decwallet_file = dirwallet; - - FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QString target_encwallet_file = dirwalletenc; + QString target_decwallet_file = dirwallet; + FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); - QFile filencrypted(dirwalletenc); - QFile wallet(dirwallet); + QFile filencrypted(dirwalletenc); + QFile wallet(dirwallet); + + qDebug() << __func__ << ": wallet size=" << wallet.size(); if (wallet.size() > 0) { QMessageBox::information(this, tr("Wallet decryption Success"), QString("Successfully delete the encryption"), QMessageBox::Ok ); - filencrypted.remove(); - } else { - QMessageBox::critical(this, tr("Wallet Encryption Failed"), QString("False password, please try again"), QMessageBox::Ok ); - this->removeWalletEncryption(); + this->removeWalletEncryption(); } - } } void MainWindow::removeWalletEncryptionStartUp() { + qDebug() << __func__ << ": removing wallet encryption"; QDialog d(this); Ui_startup ed; ed.setupUi(&d); @@ -652,30 +659,29 @@ void MainWindow::removeWalletEncryptionStartUp() { unsigned char key[KEY_LEN]; - if (crypto_pwhash - (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, + if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash, crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_ALG_DEFAULT) != 0) { - /* out of memory */ -} - QString passphraseHash1 = QByteArray(reinterpret_cast(key), KEY_LEN).toHex(); - DataStore::getChatDataStore()->setPassword(passphraseHash1); + /* out of memory */ + qDebug() << __func__ << ": crypto_pwhash failed! Possibly out of memory"; + return; + } - auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QString passphraseHash1 = QByteArray(reinterpret_cast(key), KEY_LEN).toHex(); + DataStore::getChatDataStore()->setPassword(passphraseHash1); - QString target_encwallet_file = dirwalletenc; - QString target_decwallet_file = dirwallet; + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); + QString target_encwallet_file = dirwalletenc; + QString target_decwallet_file = dirwallet; - + FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key); - auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - QFile wallet(dirwallet); + auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + QFile wallet(dirwallet); + qDebug() << __func__ << ": wallet size=" << wallet.size(); - if (wallet.size() == 0) - { - + if (wallet.size() == 0) { QMessageBox::critical(this, tr("Wallet Encryption Failed"), QString("false password please try again"), QMessageBox::Ok @@ -684,7 +690,6 @@ void MainWindow::removeWalletEncryptionStartUp() { }else{} }else{ - this->doClosePw(); } From e6d3c8db51752179e630ab271eba4eea53dd2ac2 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Thu, 8 Jul 2021 12:14:09 -0400 Subject: [PATCH 2/9] added rustc and cargo checks to build.sh --- build.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.sh b/build.sh index 9a8211c..a7ecdca 100755 --- a/build.sh +++ b/build.sh @@ -13,6 +13,18 @@ else JOBS=1 fi +# check if rustc and cargo are installed, otherwise exit with error +if ! command -v rustc &> /dev/null +then + echo "rustc could not be found. Please install it and try again." + exit +fi +if ! command -v cargo &> /dev/null +then + echo "cargo could not be found. Please install it and try again." + exit +fi + VERSION=$(cat src/version.h |cut -d\" -f2) echo "Compiling SilentDragonLite $VERSION with $JOBS threads..." CONF=silentdragon-lite.pro From 760729f1b1833e4a4fdb398abfed09e405c633ff Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 22 Jul 2021 22:54:58 -0400 Subject: [PATCH 3/9] more useful debug log --- src/controller.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 6388842..3ba422b 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1083,21 +1083,20 @@ void Controller::refreshTransactions() { unsigned char tag[crypto_secretstream_xchacha20poly1305_TAG_FINAL]; crypto_secretstream_xchacha20poly1305_state state; - /////Our decrypted message is now in decrypted. We need it as QString to render it - /////Only the QString gives weird data, so convert first to std::string - // crypto_secretstream_xchacha20poly1305_keygen(client_rx); if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, server_tx) != 0) { /* Invalid header, no need to go any further */ - qDebug() << "refreshTransactions: crypto_secretstream_xchacha20poly1305_init_pull error!"; + qDebug() << "refreshTransactions: crypto_secretstream_xchacha20poly1305_init_pull error! Invalid header"; continue; } if (crypto_secretstream_xchacha20poly1305_pull(&state, decrypted, NULL, tag, MESSAGE2, CIPHERTEXT1_LEN, NULL, 0) != 0) { /* Invalid/incomplete/corrupted ciphertext - abort */ - qDebug() << "refreshTransactions: crypto_secretstream_xchacha20poly1305_pull error!"; + qDebug() << "refreshTransactions: crypto_secretstream_xchacha20poly1305_pull error! Invalid ciphertext"; continue; } + /////Our decrypted message is now in decrypted. We need it as QString to render it + /////Only the QString gives weird data, so convert first to std::string std::string decryptedMemo(reinterpret_cast(decrypted),MESSAGE1_LEN); memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); From 4a82643ba1346f80cc1c47d75b87055d500a3af1 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 26 Jul 2021 11:38:23 -0400 Subject: [PATCH 4/9] copyright and tweaks --- res/libsodium/buildlibsodium.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/res/libsodium/buildlibsodium.sh b/res/libsodium/buildlibsodium.sh index a1de376..ca2cf77 100755 --- a/res/libsodium/buildlibsodium.sh +++ b/res/libsodium/buildlibsodium.sh @@ -1,7 +1,10 @@ #!/bin/bash +# Copyright 2019-2021 The Hush developers +# Released under the GPLv3 # First thing to do is see if libsodium.a exists in the res folder. If it does, then there's nothing to do if [ -f res/libsodium.a ]; then + echo "libsodium is already built! Nothing to do" exit 0 fi @@ -10,10 +13,14 @@ echo "Building libsodium" # Go into the lib sodium directory cd res/libsodium if [ ! -f libsodium-1.0.18.tar.gz ]; then + echo "Downloading libsodium" curl -LO https://github.com/MyHush/libsodium/releases/download/1.0.18/libsodium-1.0.18.tar.gz fi +# TODO: check libsodium downloaded correctly + if [ ! -d libsodium-1.0.18 ]; then + echo "Unpacking libsodium" tar xf libsodium-1.0.18.tar.gz fi From e303f0b12b0bc70a5a87033da40e74fea990a2be Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 26 Jul 2021 11:38:34 -0400 Subject: [PATCH 5/9] update ignored files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f5e679c..e11f42d 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ silentdragonlite_plugin_import.cpp silentdragonlite_resource.rc SilentDragonLite .gdb_history +.*sw? +core From e7eed1052aec94af4f6acb79d2250fd05061e39d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 26 Jul 2021 11:40:49 -0400 Subject: [PATCH 6/9] Git not github --- DEVELOPING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index 24ca797..b703e66 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -52,7 +52,7 @@ make -j$(nproc) install ``` # Build MXE (Cross-compiled Qt5 for Windows in Linux) ``` -mkdir ~/github && cd ~/github +mkdir ~/git && cd ~/git git clone https://github.com/mxe/mxe.git cd mxe From fc474d797dc170126a9451d4336bad3d36101cf4 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 26 Jul 2021 11:50:39 -0400 Subject: [PATCH 7/9] Add error checking to libsodium build --- res/libsodium/buildlibsodium.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/res/libsodium/buildlibsodium.sh b/res/libsodium/buildlibsodium.sh index ca2cf77..6c57381 100755 --- a/res/libsodium/buildlibsodium.sh +++ b/res/libsodium/buildlibsodium.sh @@ -1,33 +1,45 @@ #!/bin/bash # Copyright 2019-2021 The Hush developers # Released under the GPLv3 +VERSION=1.0.18 # First thing to do is see if libsodium.a exists in the res folder. If it does, then there's nothing to do if [ -f res/libsodium.a ]; then - echo "libsodium is already built! Nothing to do" + echo "libsodium $VERSION is already built! Nothing to do" exit 0 fi -echo "Building libsodium" +echo "Building libsodium $VERSION" # Go into the lib sodium directory cd res/libsodium if [ ! -f libsodium-1.0.18.tar.gz ]; then - echo "Downloading libsodium" + echo "Downloading libsodium $VERSION" curl -LO https://github.com/MyHush/libsodium/releases/download/1.0.18/libsodium-1.0.18.tar.gz fi -# TODO: check libsodium downloaded correctly +if [ ! -f libsodium-1.0.18.tar.gz ]; then + echo "Unable to download libsodium $VERSION !!! Aborting" + exit 1 +fi if [ ! -d libsodium-1.0.18 ]; then - echo "Unpacking libsodium" + echo "Unpacking libsodium $VERSION" tar xf libsodium-1.0.18.tar.gz fi +if [ ! -d libsodium-1.0.18 ]; then + echo "Unable to unpack libsodium $VERSION !!! Aborting" + exit 1 +fi + # Now build it cd libsodium-1.0.18 +echo "Configuring libsodium $VERSION" LIBS="" ./configure make clean + +echo "Compiling libsodium $VERSION" if [[ "$OSTYPE" == "darwin"* ]]; then make CFLAGS="-mmacosx-version-min=10.11" CPPFLAGS="-mmacosx-version-min=10.11" -j4 else @@ -35,5 +47,10 @@ else fi cd .. +if [ ! -e libsodium-1.0.18/src/libsodium/.libs/libsodium.a ]; then + echo "Unable to compile libsodium $VERSION !!! Aborting" + exit 1 +fi + # copy the library to the parents's res/ folder cp libsodium-1.0.18/src/libsodium/.libs/libsodium.a ../ From 3ab6c3254b319b22557dcc37f32e78097e060565 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 26 Jul 2021 23:06:37 -0400 Subject: [PATCH 8/9] Give a useful error if curl is not installed --- res/libsodium/buildlibsodium.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/res/libsodium/buildlibsodium.sh b/res/libsodium/buildlibsodium.sh index 6c57381..d6efc58 100755 --- a/res/libsodium/buildlibsodium.sh +++ b/res/libsodium/buildlibsodium.sh @@ -11,6 +11,12 @@ fi echo "Building libsodium $VERSION" +if ! command -v curl &> /dev/null +then + echo "curl could not be found. Please install it and try again." + exit 1 +fi + # Go into the lib sodium directory cd res/libsodium if [ ! -f libsodium-1.0.18.tar.gz ]; then From aebaa01e19229e3efed2ea5b248e7bde8db2ff2e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 26 Jul 2021 23:08:21 -0400 Subject: [PATCH 9/9] Set error code correctly when cargo or rustc not found --- build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index a7ecdca..8938b8a 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ #!/bin/bash # Copyright 2019-2021 The Hush Developers +# Released under the GPLv3 UNAME=$(uname) @@ -17,12 +18,12 @@ fi if ! command -v rustc &> /dev/null then echo "rustc could not be found. Please install it and try again." - exit + exit 1 fi if ! command -v cargo &> /dev/null then echo "cargo could not be found. Please install it and try again." - exit + exit 1 fi VERSION=$(cat src/version.h |cut -d\" -f2)