Browse Source

pass correct nonce to chacha20

pull/1194/head
orignal 7 years ago
parent
commit
7cdb021a1f
  1. 13
      libi2pd/NTCP2.cpp
  2. 5
      libi2pd/NTCP2.h

13
libi2pd/NTCP2.cpp

@ -47,6 +47,11 @@ namespace transport @@ -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 @@ -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 @@ -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 @@ -205,7 +212,7 @@ namespace transport
void NTCP2Server::Connect(const boost::asio::ip::address & address, uint16_t port, std::shared_ptr<NTCP2Session> 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));

5
libi2pd/NTCP2.h

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include <inttypes.h>
#include <memory>
#include <thread>
#include <boost/asio.hpp>
#include "RouterInfo.h"
#include "TransportSession.h"
@ -16,13 +17,15 @@ namespace transport @@ -16,13 +17,15 @@ namespace transport
{
public:
NTCP2Session (NTCP2Server& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr); // TODO
NTCP2Session (NTCP2Server& server, std::shared_ptr<const i2p::data::RouterInfo> 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<std::shared_ptr<I2NPMessage> >& msgs) {}; // TODO
private:

Loading…
Cancel
Save