diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 591a9c0..ae81ae2 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -392,7 +392,7 @@ void AddressBook::readFromStorage() QDataStream in(&file); // read the data serialized from the file QString version; in >> version; - qDebug() << "Detected old addressbook format"; + // qDebug() << "Detected old addressbook format"; // Convert old addressbook format v1 to v2 QList> stuff; in >> stuff; @@ -408,7 +408,7 @@ void AddressBook::readFromStorage() allLabels.push_back(contact); } - qDebug() << "Read " << version << " Hush contacts from disk..."; + // qDebug() << "Read " << version << " Hush contacts from disk..."; file.close(); } else diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 5df7693..8d5d32f 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -422,7 +422,7 @@ Tx MainWindow::createTxFromChatPage() { QString pubkey = this->getPubkeyByAddress(addr); QString passphrase = this->getPassword(); - QString hashEncryptionKey = "Test"; + QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); qDebug()<<"Pubkey Erstellung :"<refresh(true); + rpc->refresh(true); } QString MainWindow::doSendChatTxValidations(Tx tx) { @@ -733,7 +733,7 @@ Tx MainWindow::createTxForSafeContactRequest() QString memo = contactRequest.getMemo(); // QString privkey = rpc->fetchPrivKey(myAddr); QString passphrase = this->getPassword(); - QString hashEncryptionKey = "Test"; + QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); qDebug()<<"Encryption String :"<getHeaderByTx(txid) != QString("0xdeadbeef")){ headerbytes = chatModel->getHeaderByTx(txid); - qDebug()<<"headerbytes outgoing found"<getPubkeyByAddress(address); - qDebug()<<"Pubkey outgoing found"< 0)) { - /*for (auto &p : AddressBook::getInstance()->getAllAddressLabels()) - { - - if (p.getPartnerAddress() == address) - { pubkey = p.getPubkey(); - }else {pubkey = ""; - }*/ + //QString myAddr = p.getMyAddress(); QString passphrase = main->getPassword(); - QString hashEncryptionKey = "Test"; + QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); - qDebug()<<"Encryption String :"<(pubkeyBobArray.constData()); - qDebug()<<"Pubkey benutzt incoming transaction:"<(ba1.constData()); - qDebug()<<"Header benutzt incoming transaction:"<(decrypted),MESSAGE1_LEN); - + QString memodecrypt; /////Now we can convert it to QString - QString memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); + if (ui->decryptionMessage->isChecked()){ + memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); + DataStore::getChatDataStore()->clear(); + this->refresh(true); + chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); + }else{ memodecrypt = memo; + DataStore::getChatDataStore()->clear(); + this->refresh(true); + chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); + } + //////////////Give us the output of the decrypted message as debug to see if it was successfully qDebug()<<"OUT decrypt:" << memodecrypt; @@ -1094,7 +1098,7 @@ void Controller::refreshTransactions() { DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); - // } + }else{ @@ -1143,7 +1147,6 @@ void Controller::refreshTransactions() { model->markAddressUsed(address); QString memo; - QString test; if (!it["memo"].is_null()) { memo = QString::fromStdString(it["memo"]); } @@ -1205,10 +1208,11 @@ void Controller::refreshTransactions() { chatModel->addrequestZaddr(txid, requestZaddr); chatModel->addHeader(txid, headerbytes); - if (publickey.length() > 0){ + if (publickey.length() > 10){ main->addPubkey(requestZaddr, publickey); } - + qDebug()<<"Scane HM Incoming:"; + qDebug()<<"Scane HM Incoming:"<getHeaderByTx(txid) != QString("0xdeadbeef")){ headerbytes = chatModel->getHeaderByTx(txid); - qDebug()<<"HEADERBYTE INCOMING"<getPubkeyByAddress(requestZaddr) != QString("0xdeadbeef")){ publickey = main->getPubkeyByAddress(requestZaddr); - qDebug()<<"Incoming Pubkey :"< 20)) + { + + int lengthcid = cid.length(); QString passphrase = main->getPassword(); - QString hashEncryptionKey = "Test"; + QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); - qDebug()<<"Encryption String :"< 0)) - { - //const QByteArray ba2 = QByteArray::fromHex(hashEncryptionKey.toLatin1()); // const unsigned char *hashEncryptionKeyraw = reinterpret_cast(ba2.constData()); @@ -1296,7 +1301,7 @@ void Controller::refreshTransactions() { } - unsigned char server_rx[crypto_kx_SESSIONKEYBYTES], server_tx[crypto_kx_SESSIONKEYBYTES]; + unsigned char client_rx[crypto_kx_SESSIONKEYBYTES], client_tx[crypto_kx_SESSIONKEYBYTES]; ////////////////Get the pubkey from Bob, so we can create the share key @@ -1304,7 +1309,7 @@ void Controller::refreshTransactions() { /////Create the shared key for sending the message - if (crypto_kx_server_session_keys(server_rx, server_tx, + if (crypto_kx_client_session_keys(client_rx, client_tx, pk, sk, pubkeyBob) != 0) { /* Suspicious client public key, bail out */ } @@ -1338,7 +1343,7 @@ void Controller::refreshTransactions() { /////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) { + if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, client_rx) != 0) { /* Invalid header, no need to go any further */ } @@ -1350,10 +1355,22 @@ void Controller::refreshTransactions() { std::string decryptedMemo(reinterpret_cast(decrypted),MESSAGE1_LEN); /////Now we can convert it to QString - QString memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); + QString memodecrypt; + if (ui->decryptionMessage->isChecked()){ + memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); + DataStore::getChatDataStore()->clear(); + this->refresh(true); + chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); + }else{ memodecrypt = memo; + DataStore::getChatDataStore()->clear(); + this->refresh(true); + chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); + } + + // } //////////////Give us the output of the decrypted message as debug to see if it was successfully - qDebug()<<"OUT decrypt:" << memodecrypt; + ChatItem item = ChatItem( @@ -1372,12 +1389,13 @@ void Controller::refreshTransactions() { ); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); + qDebug()<<"Pushe decrypte Items:"; }else{ - - ChatItem item = ChatItem( + qDebug()<<"Pushe plain Items 1:"; + ChatItem item = ChatItem( datetime, address, QString(""), @@ -1392,13 +1410,15 @@ void Controller::refreshTransactions() { isContact ); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); + + qDebug()<<"Pushe Plain items 2:"; } } } - } } + } // Calculate the total unspent amount that's pending. This will need to be // shown in the UI so the user can keep track of pending funds @@ -1410,7 +1430,8 @@ void Controller::refreshTransactions() { } } } - getModel()->setTotalPending(totalPending); + + getModel()->setTotalPending(totalPending); // Update UI Balance updateUIBalances(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index de58411..a715861 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1703,6 +1703,19 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 900 + 10 + 281 + 23 + + + + Message encryption/decryption ON + + listContactWidget label_39 contactNameMemo @@ -1714,6 +1727,7 @@ listChat memoTxtChat sendChatButton + decryptionMessage