diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index f5bf1b6..c27c495 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -443,43 +443,29 @@ Tx MainWindow::createTxFromChatPage() { int lengthmemo = memoplain.length(); char *memoplainchar = NULL; - memoplainchar = new char[lengthmemo+1]; - strncpy(memoplainchar, memoplain.toLocal8Bit(), lengthmemo +1); - - /////////We convert the CID from QString to unsigned char*, so we can encrypt it later - int lengthcid = cid.length(); - - char *cidchar = NULL; - cidchar = new char[lengthcid+1]; - strncpy(cidchar, cid.toLocal8Bit(), lengthcid +1); - - - - QString pubkey = this->getPubkeyByAddress(addr); - QString passphrase = DataStore::getChatDataStore()->getPassword(); - QString hashEncryptionKey = passphrase; - int length = hashEncryptionKey.length(); + memoplainchar = new char[lengthmemo+1]; + strncpy(memoplainchar, memoplain.toUtf8(), lengthmemo +1); + QString pubkey = this->getPubkeyByAddress(addr); + QString passphraseHash = DataStore::getChatDataStore()->getPassword(); + int length = passphraseHash.length(); ////////////////Generate the secretkey for our message encryption - char *hashEncryptionKeyraw = NULL; - hashEncryptionKeyraw = new char[length+1]; - strncpy(hashEncryptionKeyraw, hashEncryptionKey.toLocal8Bit(), length +1); + char *hashEncryptionKeyraw = NULL; + hashEncryptionKeyraw = new char[length+1]; + strncpy(hashEncryptionKeyraw, passphraseHash.toUtf8(), length+1); #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw) #define MESSAGEAS1_LEN length - unsigned char hash[crypto_kx_SEEDBYTES]; - - crypto_hash_sha256(hash,MESSAGEAS1, MESSAGEAS1_LEN); - + unsigned char sk[crypto_kx_SECRETKEYBYTES]; unsigned char pk[crypto_kx_PUBLICKEYBYTES]; unsigned char server_rx[crypto_kx_SESSIONKEYBYTES], server_tx[crypto_kx_SESSIONKEYBYTES]; if (crypto_kx_seed_keypair(pk,sk, - hash) !=0) { + MESSAGEAS1) !=0) { } ////////////////Get the pubkey from Bob, so we can create the share key @@ -784,29 +770,22 @@ Tx MainWindow::createTxForSafeContactRequest() QString memo = contactRequest.getMemo(); - // QString privkey = rpc->fetchPrivKey(myAddr); QString passphrase = DataStore::getChatDataStore()->getPassword(); - QString hashEncryptionKey = passphrase; - int length = hashEncryptionKey.length(); + int length = passphrase.length(); ////////////////Generate the secretkey for our message encryption - char *hashEncryptionKeyraw = NULL; - hashEncryptionKeyraw = new char[length+1]; - strncpy(hashEncryptionKeyraw, hashEncryptionKey.toLocal8Bit(), length +1); + char *hashEncryptionKeyraw = NULL; + hashEncryptionKeyraw = new char[length+1]; + strncpy(hashEncryptionKeyraw, passphrase.toUtf8(), length +1); + #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw) #define MESSAGEAS1_LEN length - - unsigned char hash[crypto_kx_SEEDBYTES]; - - crypto_hash_sha256(hash,MESSAGEAS1, MESSAGEAS1_LEN); - - unsigned char sk[crypto_kx_SECRETKEYBYTES]; unsigned char pk[crypto_kx_PUBLICKEYBYTES]; if (crypto_kx_seed_keypair(pk,sk, - hash) !=0) { + MESSAGEAS1) !=0) { } QString publicKey = QByteArray(reinterpret_cast(pk), crypto_kx_PUBLICKEYBYTES).toHex(); diff --git a/src/controller.cpp b/src/controller.cpp index 7ce4c2d..72f383d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1026,32 +1026,25 @@ void Controller::refreshTransactions() { { QString passphrase = DataStore::getChatDataStore()->getPassword(); - QString hashEncryptionKey = passphrase; - int length = hashEncryptionKey.length(); + int length = passphrase.length(); ////////////////Generate the secretkey for our message encryption char *hashEncryptionKeyraw = NULL; hashEncryptionKeyraw = new char[length+1]; - strncpy(hashEncryptionKeyraw, hashEncryptionKey.toLocal8Bit(), length +1); + strncpy(hashEncryptionKeyraw, passphrase.toUtf8(), length +1); + const QByteArray pubkeyBobArray = QByteArray::fromHex(publickey.toLatin1()); const unsigned char *pubkeyBob = reinterpret_cast(pubkeyBobArray.constData()); - - - #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)/////////// - #define MESSAGEAS1_LEN length + #define MESSAGEAS1_LEN length - - unsigned char hash1[crypto_kx_SEEDBYTES]; - - 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) { + MESSAGEAS1) !=0) { } unsigned char server_rx[crypto_kx_SESSIONKEYBYTES], server_tx[crypto_kx_SESSIONKEYBYTES]; @@ -1292,32 +1285,24 @@ void Controller::refreshTransactions() { }else{} QString passphrase = DataStore::getChatDataStore()->getPassword(); - QString hashEncryptionKey = passphrase; - int length = hashEncryptionKey.length(); + int length = passphrase.length(); char *hashEncryptionKeyraw = NULL; hashEncryptionKeyraw = new char[length+1]; - strncpy(hashEncryptionKeyraw, hashEncryptionKey.toLocal8Bit(), length +1); - - //const QByteArray ba2 = QByteArray::fromHex(hashEncryptionKey.toLatin1()); - // const unsigned char *hashEncryptionKeyraw = reinterpret_cast(ba2.constData()); + strncpy(hashEncryptionKeyraw, passphrase.toUtf8(), length +1); const QByteArray pubkeyBobArray = QByteArray::fromHex(publickey.toLatin1()); const unsigned char *pubkeyBob = reinterpret_cast(pubkeyBobArray.constData()); - #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)/////////// - #define MESSAGEAS1_LEN length - - - unsigned char hash1[crypto_kx_SEEDBYTES]; + #define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)/////////// + #define MESSAGEAS1_LEN length - crypto_hash_sha256(hash1,MESSAGEAS1, MESSAGEAS1_LEN); - unsigned char sk[crypto_kx_SECRETKEYBYTES]; - unsigned char pk[crypto_kx_PUBLICKEYBYTES]; + unsigned char sk[crypto_kx_SECRETKEYBYTES]; + unsigned char pk[crypto_kx_PUBLICKEYBYTES]; if (crypto_kx_seed_keypair(pk,sk, - hash1) !=0) { + MESSAGEAS1) !=0) { }