From 7cdb021a1fb3e54e4526981399bfa7db9fb103a0 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 11 Jun 2018 14:05:30 -0400 Subject: [PATCH] pass correct nonce to chacha20 --- libi2pd/NTCP2.cpp | 13 ++++++++++--- libi2pd/NTCP2.h | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index 6b21e900..f3baa06c 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -47,6 +47,11 @@ namespace transport } } + void NTCP2Session::Done () + { + m_Server.GetService ().post (std::bind (&NTCP2Session::Terminate, shared_from_this ())); + } + bool NTCP2Session::KeyDerivationFunction1 (const uint8_t * rs, const uint8_t * pub, uint8_t * derived) { static const char protocolName[] = "Noise_XK_25519_ChaChaPoly_SHA256"; // 32 bytes @@ -111,7 +116,9 @@ namespace transport // 4 bytes reserved // sign and encrypt options i2p::crypto::Poly1305HMAC (((uint32_t *)options) + 4, (uint32_t *)key, options, 16); // calculate MAC first - i2p::crypto::chacha20 (options, 16, 0, key); // then encrypt + uint8_t nonce[12]; + memset (nonce, 0, 12); + i2p::crypto::chacha20 (options, 16, nonce, key); // then encrypt // create buffer m_SessionRequestBuffer = new uint8_t[paddingLength + 64]; memcpy (m_SessionRequestBuffer, x, 32); @@ -145,7 +152,7 @@ namespace transport (void) bytes_transferred; delete[] m_SessionCreatedBuffer; m_SessionCreatedBuffer = nullptr; if (ecode) - LogPrint (eLogInfo, "NTCP: Phase 2 read error: ", ecode.message ()); + LogPrint (eLogInfo, "NTCP2: SessionCreated read error: ", ecode.message ()); Terminate (); // TODO: continue } @@ -205,7 +212,7 @@ namespace transport void NTCP2Server::Connect(const boost::asio::ip::address & address, uint16_t port, std::shared_ptr conn) { - LogPrint (eLogDebug, "NTCP: Connecting to ", address ,":", port); + LogPrint (eLogDebug, "NTCP2: Connecting to ", address ,":", port); m_Service.post([this, address, port, conn]() { conn->GetSocket ().async_connect (boost::asio::ip::tcp::endpoint (address, port), std::bind (&NTCP2Server::HandleConnect, this, std::placeholders::_1, conn)); diff --git a/libi2pd/NTCP2.h b/libi2pd/NTCP2.h index a4f30920..ca36d37b 100644 --- a/libi2pd/NTCP2.h +++ b/libi2pd/NTCP2.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "RouterInfo.h" #include "TransportSession.h" @@ -16,13 +17,15 @@ namespace transport { public: - NTCP2Session (NTCP2Server& server, std::shared_ptr in_RemoteRouter = nullptr); // TODO + NTCP2Session (NTCP2Server& server, std::shared_ptr in_RemoteRouter = nullptr); ~NTCP2Session (); void Terminate (); + void Done (); boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; }; void ClientLogin (); // Alice + void SendI2NPMessages (const std::vector >& msgs) {}; // TODO private: