Browse Source

Abort when we see corrupted ciphertext

pull/24/head
Duke Leto 3 years ago
parent
commit
d826ca8c92
  1. 8
      src/Chat/Chat.cpp
  2. 126
      src/controller.cpp

8
src/Chat/Chat.cpp

@ -22,8 +22,7 @@ void ChatMemoEdit::updateDisplayChat() {
if (lenDisplayLabelchat) if (lenDisplayLabelchat)
lenDisplayLabelchat->setStyleSheet(""); lenDisplayLabelchat->setStyleSheet("");
} } else {
else {
// Overweight // Overweight
if (sendChatButton) if (sendChatButton)
sendChatButton->setEnabled(false); sendChatButton->setEnabled(false);
@ -62,8 +61,7 @@ void ChatMemoEditRequest::updateDisplayChatRequest() {
if (lenDisplayLabelchatRequest) if (lenDisplayLabelchatRequest)
lenDisplayLabelchatRequest->setStyleSheet(""); lenDisplayLabelchatRequest->setStyleSheet("");
} } else {
else {
// Overweight // Overweight
if (sendRequestButton) if (sendRequestButton)
sendRequestButton->setEnabled(false); sendRequestButton->setEnabled(false);
@ -85,6 +83,7 @@ void ChatMemoEditRequest::SetSendRequestButton(QPushButton* button) {
void ChatMemoEditRequest::setLenDisplayLabelChatRequest(QLabel* label) { void ChatMemoEditRequest::setLenDisplayLabelChatRequest(QLabel* label) {
this->lenDisplayLabelchatRequest = label; this->lenDisplayLabelchatRequest = label;
} }
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
{ {
@ -140,4 +139,3 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
} }
} }

126
src/controller.cpp

@ -980,8 +980,7 @@ void Controller::refreshTransactions() {
memo = QString::fromStdString(o["memo"].get<json::string_t>()); memo = QString::fromStdString(o["memo"].get<json::string_t>());
if (memo.startsWith("{")) { if (memo.startsWith("{")) {
try try {
{
QJsonDocument headermemo = QJsonDocument::fromJson(memo.toUtf8()); QJsonDocument headermemo = QJsonDocument::fromJson(memo.toUtf8());
cid = headermemo["cid"].toString(); cid = headermemo["cid"].toString();
@ -990,10 +989,8 @@ void Controller::refreshTransactions() {
chatModel->addCid(txid, cid); chatModel->addCid(txid, cid);
chatModel->addHeader(txid, headerbytes); chatModel->addHeader(txid, headerbytes);
} } catch (...) {
catch (...) qDebug() << "Invalid JSON in memo detected! memo=" << memo;
{
// on any exception caught
} }
} }
@ -1002,18 +999,14 @@ void Controller::refreshTransactions() {
if (confirmations > getLag()) if (confirmations > getLag())
{ {
isNotarized = true; isNotarized = true;
} } else {
else
{
isNotarized = false; isNotarized = false;
} }
if (chatModel->getCidByTx(txid) != QString("0xdeadbeef")) if (chatModel->getCidByTx(txid) != QString("0xdeadbeef"))
{ {
cid = chatModel->getCidByTx(txid); cid = chatModel->getCidByTx(txid);
} } else {
else
{
cid = ""; cid = "";
} }
@ -1021,18 +1014,14 @@ void Controller::refreshTransactions() {
if (chatModel->getHeaderByTx(txid) != QString("0xdeadbeef")) if (chatModel->getHeaderByTx(txid) != QString("0xdeadbeef"))
{ {
headerbytes = chatModel->getHeaderByTx(txid); headerbytes = chatModel->getHeaderByTx(txid);
} } else {
else
{
headerbytes = ""; headerbytes = "";
} }
if (main->getPubkeyByAddress(address) != QString("0xdeadbeef")) if (main->getPubkeyByAddress(address) != QString("0xdeadbeef"))
{ {
publickey = main->getPubkeyByAddress(address); publickey = main->getPubkeyByAddress(address);
} } else {
else
{
publickey = ""; publickey = "";
} }
@ -1163,9 +1152,7 @@ void Controller::refreshTransactions() {
"send", datetime, address, txid,confirmations, items "send", datetime, address, txid,confirmations, items
}); });
} } else {
else
{
{ // Incoming Transaction { // Incoming Transaction
address = (it["address"].is_null() ? "" : QString::fromStdString(it["address"])); address = (it["address"].is_null() ? "" : QString::fromStdString(it["address"]));
@ -1175,10 +1162,9 @@ void Controller::refreshTransactions() {
if (!it["memo"].is_null()) { if (!it["memo"].is_null()) {
memo = QString::fromStdString(it["memo"]); memo = QString::fromStdString(it["memo"]);
} }
items.push_back(TransactionItemDetail{ items.push_back(TransactionItemDetail{ address,
address,
CAmount::fromqint64(it["amount"].get<json::number_integer_t>()), CAmount::fromqint64(it["amount"].get<json::number_integer_t>()),
memo memo
}); });
TransactionItem tx{ TransactionItem tx{
@ -1186,102 +1172,73 @@ void Controller::refreshTransactions() {
}; };
txdata.push_back(tx); txdata.push_back(tx);
QString type; QString type = "";
QString publickey; QString publickey = "";
QString headerbytes; QString headerbytes = "";
QString cid; QString cid = "";
QString requestZaddr; QString requestZaddr = "";
QString contactname; QString contactname = "";
bool isContact; bool isContact = false;
if (!it["memo"].is_null()) { if (!it["memo"].is_null()) {
if (memo.startsWith("{")) { if (memo.startsWith("{")) {
try try {
{
QJsonDocument headermemo = QJsonDocument::fromJson(memo.toUtf8()); QJsonDocument headermemo = QJsonDocument::fromJson(memo.toUtf8());
cid = headermemo["cid"].toString(); cid = headermemo["cid"].toString();
type = headermemo["t"].toString(); type = headermemo["t"].toString();
requestZaddr = headermemo["z"].toString(); requestZaddr = headermemo["z"].toString();
headerbytes = headermemo["e"].toString(); headerbytes = headermemo["e"].toString();
publickey = headermemo["p"].toString(); publickey = headermemo["p"].toString();
chatModel->addCid(txid, cid); chatModel->addCid(txid, cid);
chatModel->addrequestZaddr(txid, requestZaddr); chatModel->addrequestZaddr(txid, requestZaddr);
chatModel->addHeader(txid, headerbytes); chatModel->addHeader(txid, headerbytes);
if (publickey.length() > 10){ // TODO: better validation of valid public key
main->addPubkey(requestZaddr, publickey); if (publickey.length() > 10){
} main->addPubkey(requestZaddr, publickey);
}
} catch (...) {
qDebug() << __func__ << ": Invalid JSON in memo! memo=" << memo.toUtf8();
} }
catch (...) }
{
// on any exception
}
}
if (chatModel->getCidByTx(txid) != QString("0xdeadbeef")) if (chatModel->getCidByTx(txid) != QString("0xdeadbeef"))
{ {
cid = chatModel->getCidByTx(txid); cid = chatModel->getCidByTx(txid);
} }
else
{
cid = "";
}
if (chatModel->getrequestZaddrByTx(txid) != QString("0xdeadbeef")) if (chatModel->getrequestZaddrByTx(txid) != QString("0xdeadbeef"))
{ {
requestZaddr = chatModel->getrequestZaddrByTx(txid); requestZaddr = chatModel->getrequestZaddrByTx(txid);
} }
else
{
requestZaddr = "";
}
if (chatModel->getHeaderByTx(txid) != QString("0xdeadbeef")) if (chatModel->getHeaderByTx(txid) != QString("0xdeadbeef"))
{ {
headerbytes = chatModel->getHeaderByTx(txid); headerbytes = chatModel->getHeaderByTx(txid);
} }
else
{
headerbytes = "";
}
if (main->getPubkeyByAddress(requestZaddr) != QString("0xdeadbeef")) if (main->getPubkeyByAddress(requestZaddr) != QString("0xdeadbeef"))
{ {
publickey = main->getPubkeyByAddress(requestZaddr); publickey = main->getPubkeyByAddress(requestZaddr);
} }
else
{
publickey = "";
}
if (contactModel->getContactbyAddress(requestZaddr) != QString("0xdeadbeef")) if (contactModel->getContactbyAddress(requestZaddr) != QString("0xdeadbeef"))
{ {
isContact = true; isContact = true;
contactname = contactModel->getContactbyAddress(requestZaddr); contactname = contactModel->getContactbyAddress(requestZaddr);
} }
else
{
isContact = false;
contactname = "";
}
bool isNotarized; bool isNotarized = false;
if (confirmations > getLag()) if (confirmations > getLag())
{ {
isNotarized = true; isNotarized = true;
} }
else
{
isNotarized = false;
}
int position = it["position"].get<json::number_integer_t>(); int position = it["position"].get<json::number_integer_t>();
@ -1361,11 +1318,15 @@ void Controller::refreshTransactions() {
// crypto_secretstream_xchacha20poly1305_keygen(client_rx); // crypto_secretstream_xchacha20poly1305_keygen(client_rx);
if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, client_rx) != 0) { if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, client_rx) != 0) {
main->logger->write("Invalid header incoming, no need to go any further "); main->logger->write("Invalid header incoming, no need to go any further ");
qDebug() << "crypto_secretstream_xchacha20poly1305_init_pull error!";
return;
} }
if (crypto_secretstream_xchacha20poly1305_pull if (crypto_secretstream_xchacha20poly1305_pull
(&state, decrypted, NULL, tag, MESSAGE2, CIPHERTEXT1_LEN, NULL, 0) != 0) { (&state, decrypted, NULL, tag, MESSAGE2, CIPHERTEXT1_LEN, NULL, 0) != 0) {
main->logger->write("Invalid/incomplete/corrupted ciphertext - abort"); main->logger->write("Invalid/incomplete/corrupted ciphertext - abort");
qDebug() << "crypto_secretstream_xchacha20poly1305_pull error!";
return;
} }
std::string decryptedMemo(reinterpret_cast<char*>(decrypted),MESSAGE1_LEN); std::string decryptedMemo(reinterpret_cast<char*>(decrypted),MESSAGE1_LEN);
@ -1375,8 +1336,7 @@ void Controller::refreshTransactions() {
memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size());
// } ////Give us the output of the decrypted message as debug to see if it was successfully
//////////////Give us the output of the decrypted message as debug to see if it was successfully
ChatItem item = ChatItem( ChatItem item = ChatItem(
datetime, datetime,
@ -1395,15 +1355,11 @@ void Controller::refreshTransactions() {
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
} } else {
else
{
// //
} }
} } else {
else
{
ChatItem item = ChatItem( ChatItem item = ChatItem(
datetime, datetime,
address, address,

Loading…
Cancel
Save