From 173ec6ccdc7bb9f2f075a0ec3a605e6fcd1a6b21 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Mon, 1 Jun 2020 22:47:13 +0200 Subject: [PATCH] fix for incoming memos --- src/controller.cpp | 69 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index f4475cd..a4f315d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -995,10 +995,13 @@ void Controller::refreshTransactions() { const QByteArray ba2 = QByteArray::fromHex(hashEncryptionKey.toLatin1()); const unsigned char *hashEncryptionKeyraw = reinterpret_cast(ba2.constData()); #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw) - #define MESSAGEAS1_LEN length + #define MESSAGEAS1_LEN length + const QByteArray pubkeyBobArray = QByteArray::fromHex(publickey.toLatin1()); + const unsigned char *pubkeyBob = reinterpret_cast(pubkeyBobArray.constData()); - #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)///////////static atm, in future we will use the Passphrase here + + #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)/////////// #define MESSAGEAS1_LEN 12 @@ -1015,6 +1018,17 @@ void Controller::refreshTransactions() { } unsigned char client_rx[crypto_kx_SESSIONKEYBYTES], client_tx[crypto_kx_SESSIONKEYBYTES]; + + + ////////////////Get the pubkey from Bob, so we can create the share key + + + /////Create the shared key for sending the message + + if (crypto_kx_server_session_keys(client_rx, client_tx, + pk, sk, pubkeyBob) != 0) { + /* Suspicious client public key, bail out */ + } const QByteArray ba = QByteArray::fromHex(memo.toLatin1()); @@ -1243,6 +1257,11 @@ void Controller::refreshTransactions() { int lengthcid = cid.length(); + QString passphrase = main->getPassword(); + QString hashEncryptionKey = passphrase; + int length = hashEncryptionKey.length(); + + qDebug()<<"Encryption String :"< 0)) { - #define MESSAGEAS ((const unsigned char *) cidchar) - #define MESSAGEAS_LEN lengthcid + const QByteArray ba2 = QByteArray::fromHex(hashEncryptionKey.toLatin1()); + const unsigned char *hashEncryptionKeyraw = reinterpret_cast(ba2.constData()); + #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw) + #define MESSAGEAS1_LEN length + + const QByteArray pubkeyBobArray = QByteArray::fromHex(publickey.toLatin1()); + const unsigned char *pubkeyBob = reinterpret_cast(pubkeyBobArray.constData()); + + + #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)/////////// + #define MESSAGEAS1_LEN 12 + + + unsigned char hash1[crypto_kx_SECRETKEYBYTES]; + + crypto_hash_sha256(hash1,MESSAGEAS1, MESSAGEAS1_LEN); + unsigned char sk[crypto_kx_SECRETKEYBYTES]; + unsigned char pk[crypto_kx_PUBLICKEYBYTES]; + + if (crypto_kx_seed_keypair(pk,sk, + hash1) !=0) { - unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES]; - crypto_hash_sha256(hash,MESSAGEAS, MESSAGEAS_LEN); + } + + unsigned char client_rx[crypto_kx_SESSIONKEYBYTES], client_tx[crypto_kx_SESSIONKEYBYTES]; + + + ////////////////Get the pubkey from Bob, so we can create the share key + + + /////Create the shared key for sending the message + + if (crypto_kx_server_session_keys(client_rx, client_tx, + pk, sk, pubkeyBob) != 0) { + /* Suspicious client public key, bail out */ + } + const QByteArray ba = QByteArray::fromHex(memo.toLatin1()); const unsigned char *encryptedMemo = reinterpret_cast(ba.constData()); @@ -1284,8 +1335,8 @@ 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 - - if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, hash) != 0) { + // crypto_secretstream_xchacha20poly1305_keygen(client_rx); + if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, client_rx) != 0) { /* Invalid header, no need to go any further */ } @@ -1300,7 +1351,7 @@ void Controller::refreshTransactions() { QString memodecrypt = QString::fromUtf8( decryptedMemo.data(), decryptedMemo.size()); //////////////Give us the output of the decrypted message as debug to see if it was successfully - qDebug()<<"OUT decrypt:" << memodecrypt; + qDebug()<<"OUT decrypt:" << memodecrypt; ChatItem item = ChatItem(