From 9dce18e151f106edee4c830d5eba24fd70e9cb23 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 29 May 2021 18:07:28 -0400 Subject: [PATCH] continue instead of returning after secretstream badness --- src/Chat/Chat.cpp | 4 ++-- src/Chat/Helper/ChatDelegator.h | 3 ++- src/contactmodel.cpp | 18 ++++----------- src/controller.cpp | 40 +++++++++++++++++++-------------- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp index e510291..7cc06c9 100644 --- a/src/Chat/Chat.cpp +++ b/src/Chat/Chat.cpp @@ -107,7 +107,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) QStandardItem *Items = new QStandardItem(c.second.toChatLine()); Items->setData(OUTGOING, Qt::UserRole + 1); - qDebug() << __func__ << ": appending row to OUTGOING chatitems to contact " << p.getName(); + qDebug() << __func__ << ": appending row to OUTGOING chatitems to contact " << p.getName() << " with item " << Items; chat->appendRow(Items); ui->listChat->setModel(chat); @@ -124,7 +124,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) { QStandardItem *Items1 = new QStandardItem(c.second.toChatLine()); Items1->setData(INCOMING, Qt::UserRole + 1); - qDebug() << __func__ << ": appending row to INCOMING chatitems to contact " << p.getName() << "with cid=" << p.getCid(); + qDebug() << __func__ << ": appending row to INCOMING chatitems to contact " << p.getName() << "with cid=" << p.getCid() << " and item " << Items1; chat->appendRow(Items1); ui->listChat->setModel(chat); ui->memoTxtChat->setEnabled(true); diff --git a/src/Chat/Helper/ChatDelegator.h b/src/Chat/Helper/ChatDelegator.h index 6f2032d..d319abb 100644 --- a/src/Chat/Helper/ChatDelegator.h +++ b/src/Chat/Helper/ChatDelegator.h @@ -1,4 +1,4 @@ -// Copyright 2019-2020 The Hush developers +// Copyright 2019-2021 The Hush developers // GPLv3 #ifndef CHATDELEGATOR_H @@ -42,6 +42,7 @@ inline ListViewDelegate::ListViewDelegate(QObject *parent): QAbstractItemDelegat } +//TODO: this data must be kept in sync with sizeHint(), refactor inline void ListViewDelegate::paint(QPainter *painter, QStyleOptionViewItem const &option, QModelIndex const &index) const { QTextDocument bodydoc; diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index f3d529f..b398f33 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -1,4 +1,4 @@ -// Copyright 2019-2020 The Hush developers +// Copyright 2019-2021 The Hush developers // GPLv3 #include "contactmodel.h" @@ -18,11 +18,6 @@ void ContactModel::addLabel(QString addr, QString label) QString ContactModel::getContactbyAddress(QString addr) { - for(auto& pair : this->AddressMap) - { - - } - if(this->AddressMap.count(addr) > 0) { return this->AddressMap[addr]; @@ -65,9 +60,7 @@ void MainWindow::showRequesthush() { for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) { - if (p.getName() == label) - - { + if (p.getName() == label) { QString addr = p.getPartnerAddress(); QString myzaddr = p.getMyAddress(); @@ -135,7 +128,8 @@ void MainWindow::showRequesthush() { } } - if (d.exec() == QDialog::Accepted) { + + if (d.exec() == QDialog::Accepted) { // Construct a hush Payment URI with the data and pay it immediately. CAmount amount = CAmount::fromDecimalString(req.txtAmount->text()); QString memoURI = "hush:" + req.lblAddressInfo->text() @@ -150,10 +144,6 @@ void MainWindow::showRequesthush() { // sapling address this->payhushURI(sendURI, req.lblAddressInfo->text()); - - } } - - diff --git a/src/controller.cpp b/src/controller.cpp index 40f6a6d..e5dea64 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -950,15 +950,13 @@ void Controller::refreshTransactions() { // First, check if there's outgoing metadata if (!it["outgoing_metadata"].is_null()) { - for (auto o: it["outgoing_metadata"].get()) - - { + for (auto o: it["outgoing_metadata"].get()) { // if (chatModel->getCidByTx(txid) == QString("0xdeadbeef")){ QString address; address = QString::fromStdString(o["address"]); - // Sent items are -ve + // Sent items are negative CAmount amount = CAmount::fromqint64(-1* o["value"].get()); // Check for Memos @@ -979,7 +977,7 @@ void Controller::refreshTransactions() { QString headerbytes = ""; QString publickey = ""; if (!o["memo"].is_null()) { - memo = QString::fromStdString(o["memo"].get()); + memo = QString::fromStdString(o["memo"].get()); if (memo.startsWith("{")) { try { @@ -1008,7 +1006,6 @@ void Controller::refreshTransactions() { cid = chatModel->getCidByTx(txid); } - if (chatModel->getHeaderByTx(txid) != QString("0xdeadbeef")) { headerbytes = chatModel->getHeaderByTx(txid); @@ -1042,6 +1039,8 @@ void Controller::refreshTransactions() { if (crypto_kx_seed_keypair(pk, sk, MESSAGEAS1) !=0) { main->logger->write("Keypair outgoing error"); + qDebug() << "refreshTransactions: crypto_kx_seed_keypair error"; + continue; } unsigned char server_rx[crypto_kx_SESSIONKEYBYTES], server_tx[crypto_kx_SESSIONKEYBYTES]; @@ -1054,8 +1053,8 @@ void Controller::refreshTransactions() { if (crypto_kx_server_session_keys(server_rx, server_tx, pk, sk, pubkeyBob) != 0) { main->logger->write("Suspicious client public outgoing key, bail out "); - qDebug() << "Suspicious client public outgoing key, aborting!"; - return; + qDebug() << "refreshTransactions: Suspicious client public outgoing key, aborting!"; + continue; } const QByteArray ba = QByteArray::fromHex(memo.toUtf8()); @@ -1090,14 +1089,14 @@ void Controller::refreshTransactions() { // 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() << __func__ << ": crypto_secretstream_xchacha20poly1305_init_pull error!"; - return; + qDebug() << "refreshTransactions: crypto_secretstream_xchacha20poly1305_init_pull error!"; + continue; } if (crypto_secretstream_xchacha20poly1305_pull(&state, decrypted, NULL, tag, MESSAGE2, CIPHERTEXT1_LEN, NULL, 0) != 0) { /* Invalid/incomplete/corrupted ciphertext - abort */ - qDebug() << __func__ << ": crypto_secretstream_xchacha20poly1305_pull error!"; - return; + qDebug() << "refreshTransactions: crypto_secretstream_xchacha20poly1305_pull error!"; + continue; } std::string decryptedMemo(reinterpret_cast(decrypted),MESSAGE1_LEN); @@ -1125,6 +1124,7 @@ void Controller::refreshTransactions() { false ); + qDebug() << "refreshTransactions: adding chatItem with memodecrypt=" << memodecrypt; DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); // updateUIBalances(); } @@ -1270,6 +1270,8 @@ void Controller::refreshTransactions() { if (crypto_kx_seed_keypair(pk, sk, MESSAGEAS1) !=0) { main->logger->write("Suspicious outgoing key pair, bail out "); + qDebug() << "refreshTransactions: (incoming) crypto_kx_seed_keypair error!"; + continue; } unsigned char client_rx[crypto_kx_SESSIONKEYBYTES], client_tx[crypto_kx_SESSIONKEYBYTES]; @@ -1277,10 +1279,11 @@ void Controller::refreshTransactions() { ////////////////Get the pubkey from Bob, so we can create the share key /////Create the shared key for sending the message - if (crypto_kx_client_session_keys(client_rx, client_tx, pk, sk, pubkeyBob) != 0) { main->logger->write("Suspicious client public incoming key, bail out "); + qDebug() << "refreshTransactions: (incoming) crypto_kx_client_session_keys error!"; + continue; } const QByteArray ba = QByteArray::fromHex(memo.toUtf8()); @@ -1312,15 +1315,15 @@ void Controller::refreshTransactions() { // crypto_secretstream_xchacha20poly1305_keygen(client_rx); if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, client_rx) != 0) { main->logger->write("Invalid header incoming, no need to go any further "); - qDebug() << __func__ << ":crypto_secretstream_xchacha20poly1305_init_pull error!"; - return; + qDebug() <<"refreshTransactions: (incoming) crypto_secretstream_xchacha20poly1305_init_pull error!"; + continue; } if (crypto_secretstream_xchacha20poly1305_pull (&state, decrypted, NULL, tag, MESSAGE2, CIPHERTEXT1_LEN, NULL, 0) != 0) { main->logger->write("Invalid/incomplete/corrupted ciphertext - abort"); - qDebug() << __func__ << ":crypto_secretstream_xchacha20poly1305_pull error!"; - return; + qDebug() << "refreshTransactions: (incoming) crypto_secretstream_xchacha20poly1305_pull error!"; + continue; } std::string decryptedMemo(reinterpret_cast(decrypted),MESSAGE1_LEN); @@ -1347,6 +1350,7 @@ void Controller::refreshTransactions() { isContact ); + qDebug() << "refreshTransactions: adding chatItem with memodecrypt=" << memodecrypt; DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); } else { @@ -1368,6 +1372,8 @@ void Controller::refreshTransactions() { isNotarized, isContact ); + + qDebug() << "refreshTransactions: adding chatItem with memo=" << memo; DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); } }