mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
pass correct nonce to chacha20
This commit is contained in:
parent
74c0b729c2
commit
7cdb021a1f
@ -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)
|
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
|
static const char protocolName[] = "Noise_XK_25519_ChaChaPoly_SHA256"; // 32 bytes
|
||||||
@ -111,7 +116,9 @@ namespace transport
|
|||||||
// 4 bytes reserved
|
// 4 bytes reserved
|
||||||
// sign and encrypt options
|
// sign and encrypt options
|
||||||
i2p::crypto::Poly1305HMAC (((uint32_t *)options) + 4, (uint32_t *)key, options, 16); // calculate MAC first
|
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
|
// create buffer
|
||||||
m_SessionRequestBuffer = new uint8_t[paddingLength + 64];
|
m_SessionRequestBuffer = new uint8_t[paddingLength + 64];
|
||||||
memcpy (m_SessionRequestBuffer, x, 32);
|
memcpy (m_SessionRequestBuffer, x, 32);
|
||||||
@ -145,7 +152,7 @@ namespace transport
|
|||||||
(void) bytes_transferred;
|
(void) bytes_transferred;
|
||||||
delete[] m_SessionCreatedBuffer; m_SessionCreatedBuffer = nullptr;
|
delete[] m_SessionCreatedBuffer; m_SessionCreatedBuffer = nullptr;
|
||||||
if (ecode)
|
if (ecode)
|
||||||
LogPrint (eLogInfo, "NTCP: Phase 2 read error: ", ecode.message ());
|
LogPrint (eLogInfo, "NTCP2: SessionCreated read error: ", ecode.message ());
|
||||||
Terminate (); // TODO: continue
|
Terminate (); // TODO: continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +212,7 @@ namespace transport
|
|||||||
|
|
||||||
void NTCP2Server::Connect(const boost::asio::ip::address & address, uint16_t port, std::shared_ptr<NTCP2Session> conn)
|
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]()
|
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));
|
conn->GetSocket ().async_connect (boost::asio::ip::tcp::endpoint (address, port), std::bind (&NTCP2Server::HandleConnect, this, std::placeholders::_1, conn));
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
#include "TransportSession.h"
|
#include "TransportSession.h"
|
||||||
@ -16,13 +17,15 @@ namespace transport
|
|||||||
{
|
{
|
||||||
public:
|
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 ();
|
~NTCP2Session ();
|
||||||
void Terminate ();
|
void Terminate ();
|
||||||
|
void Done ();
|
||||||
|
|
||||||
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
||||||
|
|
||||||
void ClientLogin (); // Alice
|
void ClientLogin (); // Alice
|
||||||
|
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) {}; // TODO
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user