From dd738a6fee7bed1282844b38ee0cf83838dbd6f3 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Fri, 12 Jun 2020 06:20:24 +0200 Subject: [PATCH 1/7] push version to 1.3.3 --- src/chatmodel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index fe4e92b..f5bf1b6 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -158,10 +158,12 @@ void MainWindow::renderContactRequest(){ QString label_contact = index.data(Qt::DisplayRole).toString(); QStandardItemModel* contactMemo = new QStandardItemModel(); + qDebug()< Date: Fri, 12 Jun 2020 06:20:40 +0200 Subject: [PATCH 2/7] push version to 1.3.3 --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 0b92eaa..927bb5b 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define APP_VERSION "1.3.2-Chat-Beta" +#define APP_VERSION "1.3.3" From 05809afeb139c189bd1f9e34601f01e9e512f2b1 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Fri, 12 Jun 2020 23:50:50 +0200 Subject: [PATCH 3/7] decrypt addrbook only if needed, show only memos in requests --- src/addressbook.cpp | 114 ++++++++++++++++++++++++++++++++++++++------ src/chatmodel.cpp | 6 +-- src/mainwindow.cpp | 32 ++++++------- 3 files changed, 118 insertions(+), 34 deletions(-) diff --git a/src/addressbook.cpp b/src/addressbook.cpp index e2f481d..5061438 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -386,13 +386,53 @@ AddressBook::AddressBook() void AddressBook::readFromStorage() { - QFile file(AddressBook::writeableFile()); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QString target_decaddr_file = dir.filePath("addresslabels.dat"); + QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); + QFile file(target_encaddr_file); + QFile file1(target_decaddr_file); if (file.exists()) { + + qDebug() << "Existiert"; + QString password = DataStore::getChatDataStore()->getPassword(); + 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); + + #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 */ + } + + + + FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); + qDebug() << "entschlüsselt"; + allLabels.clear(); - file.open(QIODevice::ReadOnly); - QDataStream in(&file); // read the data serialized from the file + file1.open(QIODevice::ReadOnly); + QDataStream in(&file1); // read the data serialized from the file QString version; in >> version; QList> stuff; @@ -405,6 +445,8 @@ void AddressBook::readFromStorage() auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); QFile address(dir.filePath(filename)); + qDebug() << "is v1"; + address.rename(dir.filePath("addresslabels.bak")); }else{ @@ -419,21 +461,16 @@ void AddressBook::readFromStorage() // qDebug() << "Read " << version << " Hush contacts from disk..."; - file.close(); + file1.close(); + + FileEncryption::encrypt(target_encaddr_file, target_decaddr_file, key); + file1.remove(); } else { qDebug() << "No Hush contacts found on disk!"; } - // Special. - // Add the default silentdragon donation address if it isn't already present - // QList allAddresses; - // std::transform(allLabels.begin(), allLabels.end(), - // std::back_inserter(allAddresses), [=] (auto i) { return i.getPartnerAddress(); }); - // if (!allAddresses.contains(Settings::getDonationAddr(true))) { - // allLabels.append(QPair("silentdragon donation", Settings::getDonationAddr(true))); - // } } @@ -442,12 +479,49 @@ void AddressBook::writeToStorage() //FileSystem::getInstance()->writeContacts(AddressBook::writeableFile(), DataStore::getContactDataStore()->dump()); // FileSystem::getInstance()->writeContactsOldFormat(AddressBook::writeableFile(), allLabels); + + QString password = DataStore::getChatDataStore()->getPassword(); + 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); + + #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 */ + } + + - - QFile file(AddressBook::writeableFile()); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QString target_encaddr_file = dir.filePath("addresslabels.dat.enc"); + QString target_decaddr_file = dir.filePath("addresslabels.dat"); + + FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); + + QFile file(target_decaddr_file); file.open(QIODevice::ReadWrite | QIODevice::Truncate); QDataStream out(&file); // we will serialize the data into the file QList> contacts; + for(auto &item: allLabels) { QList c; @@ -456,10 +530,20 @@ void AddressBook::writeToStorage() c.push_back(item.getMyAddress()); c.push_back(item.getCid()); c.push_back(item.getAvatar()); - contacts.push_back(c); + contacts.push_back(c); + } out << QString("v2") << contacts; + qDebug()<<"schreibe in Datei: "; file.close(); + + + FileEncryption::encrypt(target_encaddr_file, target_decaddr_file , key); + QFile file1(target_decaddr_file); + file1.remove(); + + qDebug()<<"encrypt Addrbook writeToStorage"; + } QString AddressBook::writeableFile() diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index f5bf1b6..4db379b 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -163,7 +163,7 @@ void MainWindow::renderContactRequest(){ - if ((c.second.isOutgoing() == false) && (label_contact == c.second.getRequestZaddr())) + if ((c.second.isOutgoing() == false) && (label_contact == c.second.getRequestZaddr() && (c.second.getMemo().startsWith("{") == false))) { @@ -194,12 +194,12 @@ void MainWindow::renderContactRequest(){ QString label_contactold = index.data(Qt::DisplayRole).toString(); QStandardItemModel* contactMemo = new QStandardItemModel(); - if ((c.second.isOutgoing() == false) && (label_contactold == c.second.getContact())) + if ((c.second.isOutgoing() == false) && (label_contactold == c.second.getContact()) && (c.second.getMemo().startsWith("{") == false)) { QStandardItem* Items = new QStandardItem(c.second.getMemo()); - contactMemo->appendRow(Items); + contactMemo->appendRow(Items); requestContact.requestMemo->setModel(contactMemo); requestContact.requestMemo->show(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 338c8b2..61657a1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -338,20 +338,20 @@ void MainWindow::closeEvent(QCloseEvent* event) { 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 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_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")); + // QFile address(dir.filePath("addresslabels.dat")); wallet.remove(); - address.remove(); + //address.remove(); } @@ -432,18 +432,18 @@ void MainWindow::encryptWallet() { 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 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_enc_file, source_file, key); FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key); QFile wallet(dirwallet); - QFile address(dir.filePath("addresslabels.dat")); + // QFile address(dir.filePath("addresslabels.dat")); wallet.rename(dirwalletbackup); - address.rename(dir.filePath("addresslabels.datBackup")); + // address.rename(dir.filePath("addresslabels.datBackup")); QMessageBox::information(this, tr("Wallet Encryption Success"), QString("Successfully encrypted your wallet"), @@ -520,11 +520,11 @@ void MainWindow::removeWalletEncryption() { 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"); + // 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); + // FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); QFile filencrypted(dirwalletenc); QFile wallet(dirwallet); @@ -595,11 +595,11 @@ void MainWindow::removeWalletEncryptionStartUp() { 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"); + // 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); + // FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key); } From da2ea0fbf57bed138ba5cd92e8ed18702b7fbf03 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Fri, 12 Jun 2020 23:55:37 +0200 Subject: [PATCH 4/7] fix zaddr for deposit hush dialog #140 --- src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 61657a1..ef5845b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1169,7 +1169,7 @@ void MainWindow::setupBalancesTab() { QList allAddresses; allAddresses = getRPC()->getModel()->getAllZAddresses(); - QString depositzaddr = allAddresses[1]; + QString depositzaddr = allAddresses[0]; deposithush.qrcodeDisplayDeposit->setQrcodeString(depositzaddr); deposithush.zaddr->setText(depositzaddr); From 05004478d19ccb7c65b277641088c7004a07ce34 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 13 Jun 2020 00:40:42 +0200 Subject: [PATCH 5/7] auto create hushchat zaddr at contact request --- src/DataStore/ChatDataStore.cpp | 12 ++++++++++++ src/DataStore/ChatDataStore.h | 6 +++++- src/addressbook.cpp | 2 +- src/chatmodel.cpp | 24 ++++++++++-------------- src/contactrequest.ui | 16 ---------------- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/DataStore/ChatDataStore.cpp b/src/DataStore/ChatDataStore.cpp index 82f9db3..bcb1751 100644 --- a/src/DataStore/ChatDataStore.cpp +++ b/src/DataStore/ChatDataStore.cpp @@ -39,6 +39,18 @@ QString ChatDataStore::getPassword() return _password; } +QString ChatDataStore::getSendZaddr() +{ + + return _zaddr; +} + +void ChatDataStore::setSendZaddr(QString zaddr) +{ + + _zaddr = zaddr; +} + void ChatDataStore::setPassword(QString password) { diff --git a/src/DataStore/ChatDataStore.h b/src/DataStore/ChatDataStore.h index c1233b6..aa05662 100644 --- a/src/DataStore/ChatDataStore.h +++ b/src/DataStore/ChatDataStore.h @@ -26,9 +26,13 @@ class ChatDataStore std::map getAllOldContactRequests(); std::map getAllMemos(); QString getPassword(); + QString getSendZaddr(); - void setPassword(QString Password); + void setSendZaddr(QString Password); QString _password; + + void setPassword(QString zaddr); + QString _zaddr; QString dump(); diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 5061438..3897678 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -439,7 +439,7 @@ void AddressBook::readFromStorage() in >> stuff; //////////////found old addrbook, and rename it to .bak - if (version != "v2") + if (version == "v1") { auto filename = QStringLiteral("addresslabels.dat"); auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 4db379b..91c51b2 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -710,8 +710,8 @@ void::MainWindow::addContact() request.setupUi(&dialog); Settings::saveRestore(&dialog); -QObject::connect(request.newZaddr, &QPushButton::clicked, [&] () { - try + + try { bool sapling = true; rpc->createNewZaddr(sapling, [=] (json reply) { @@ -720,6 +720,9 @@ QObject::connect(request.newZaddr, &QPushButton::clicked, [&] () { request.myzaddr->setText(myAddr); ui->listReceiveAddresses->insertItem(0, myAddr); ui->listReceiveAddresses->setCurrentIndex(0); + DataStore::getChatDataStore()->setSendZaddr(myAddr); + + qDebug()<<"Zaddr: "<getSendZaddr(); QString type = "Cont"; QString addr = contactRequest.getReceiverAddress(); @@ -835,16 +841,6 @@ void MainWindow::ContactRequest() { return; } - if (contactRequest.getSenderAddress().size() > 80) { - - QMessageBox msg(QMessageBox::Critical, tr("Missing HushChat Address"), - tr("You have to create your HushChat address to send a contact request,\n"), - QMessageBox::Ok, this); - - msg.exec(); - return; - } - int max = 235; QString chattext = contactRequest.getMemo();; int size = chattext.size(); diff --git a/src/contactrequest.ui b/src/contactrequest.ui index d187eb1..6f6a529 100644 --- a/src/contactrequest.ui +++ b/src/contactrequest.ui @@ -122,22 +122,6 @@ - - - - - 0 - 0 - - - - Create New Address - - - false - - - From c8553cee151e7cabe70fb54e5e0db6ad5eb76b92 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 13 Jun 2020 00:44:53 +0200 Subject: [PATCH 6/7] Disallow chat input when no contact is selected #137 --- src/mainwindow.cpp | 3 +++ src/mainwindow.ui | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ef5845b..d839cea 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1344,6 +1344,8 @@ void MainWindow::setupTransactionsTab() { void MainWindow::setupchatTab() { + ui->memoTxtChat->setEnabled(false); + /////////////Setting Icons for Chattab and different themes auto theme = Settings::getInstance()->get_theme_name(); @@ -1530,6 +1532,7 @@ void MainWindow::setupchatTab() { ui->listContactWidget->addAction(HushAction); ui->listContactWidget->addAction(requestHushAction); ui->listContactWidget->addAction(subatomicAction); + ui->memoTxtChat->setEnabled(true); /*QObject::connect(requestHushAction, &QAction::triggered, [=]() { QModelIndex index = ui->listContactWidget->currentIndex(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 8471227..cf6fa57 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -59,7 +59,7 @@ - 2 + 5 From 1c020691b15c17b4e6f612108cf039cfd66e48e7 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 13 Jun 2020 01:01:26 +0200 Subject: [PATCH 7/7] backup encrypted addresslabels to restore it later if needed --- src/chatmodel.cpp | 20 +------------------- src/firsttimewizard.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 91c51b2..a563398 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -734,25 +734,7 @@ void::MainWindow::addContact() QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces); - - QObject::connect(request.sendRequestButton, &QPushButton::clicked, [&] () { - - QString addr = request.zaddr->text(); - QString myAddr = request.myzaddr->text().trimmed(); - QString memo = request.memorequest->toPlainText().trimmed(); - QString avatar = QString(":/icons/res/") + request.comboBoxAvatar->currentText() + QString(".png"); - QString label = request.labelRequest->text().trimmed(); - - - contactRequest.setSenderAddress(myAddr); - contactRequest.setReceiverAddress(addr); - contactRequest.setMemo(memo); - contactRequest.setCid(cid); - contactRequest.setAvatar(avatar); - contactRequest.setLabel(label); - - }); - + QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::saveandsendContact); diff --git a/src/firsttimewizard.cpp b/src/firsttimewizard.cpp index 5ef96bb..ca22f4f 100644 --- a/src/firsttimewizard.cpp +++ b/src/firsttimewizard.cpp @@ -16,6 +16,18 @@ FirstTimeWizard::FirstTimeWizard(bool dangerous, QString server) this->dangerous = dangerous; this->server = server; + ////backup addresslabels.dat if there is one, to restore it later + + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QString addressbook = dir.filePath("addresslabels.dat.enc"); + QFile file(addressbook); + + if (file.exists()) + { + file.rename(dir.filePath("addresslabels.dat.enc-backup")); + + } + // Create the pages setPage(Page_NewOrRestore, new NewOrRestorePage(this)); setPage(Page_New, new NewSeedPage(this));