mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
handle tunnel delivery instructioin for ECIESx25519
This commit is contained in:
parent
376bf6ba72
commit
bcfe44db54
|
@ -359,11 +359,11 @@ namespace client
|
||||||
|
|
||||||
void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t len)
|
void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
uint8_t typeID = buf[I2NP_HEADER_TYPEID_OFFSET];
|
I2NPMessageType typeID = (I2NPMessageType)(buf[I2NP_HEADER_TYPEID_OFFSET]);
|
||||||
LeaseSetDestination::HandleCloveI2NPMessage (typeID, buf + I2NP_HEADER_SIZE, GetI2NPMessageLength(buf, len) - I2NP_HEADER_SIZE);
|
LeaseSetDestination::HandleCloveI2NPMessage (typeID, buf + I2NP_HEADER_SIZE, GetI2NPMessageLength(buf, len) - I2NP_HEADER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LeaseSetDestination::HandleCloveI2NPMessage (uint8_t typeID, const uint8_t * payload, size_t len)
|
bool LeaseSetDestination::HandleCloveI2NPMessage (I2NPMessageType typeID, const uint8_t * payload, size_t len)
|
||||||
{
|
{
|
||||||
switch (typeID)
|
switch (typeID)
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,7 +132,7 @@ namespace client
|
||||||
|
|
||||||
// implements GarlicDestination
|
// implements GarlicDestination
|
||||||
void HandleI2NPMessage (const uint8_t * buf, size_t len);
|
void HandleI2NPMessage (const uint8_t * buf, size_t len);
|
||||||
bool HandleCloveI2NPMessage (uint8_t typeID, const uint8_t * payload, size_t len);
|
bool HandleCloveI2NPMessage (I2NPMessageType typeID, const uint8_t * payload, size_t len);
|
||||||
|
|
||||||
void SetLeaseSet (std::shared_ptr<const i2p::data::LocalLeaseSet> newLeaseSet);
|
void SetLeaseSet (std::shared_ptr<const i2p::data::LocalLeaseSet> newLeaseSet);
|
||||||
int GetLeaseSetType () const { return m_LeaseSetType; };
|
int GetLeaseSetType () const { return m_LeaseSetType; };
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "Elligator.h"
|
#include "Elligator.h"
|
||||||
#include "Tag.h"
|
#include "Tag.h"
|
||||||
#include "I2PEndian.h"
|
#include "I2PEndian.h"
|
||||||
#include "Garlic.h"
|
|
||||||
#include "ECIESX25519AEADRatchetSession.h"
|
#include "ECIESX25519AEADRatchetSession.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -36,7 +35,7 @@ namespace garlic
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ECIESX25519AEADRatchetSession::NewIncomingSession (const i2p::data::LocalDestination& dest,
|
bool ECIESX25519AEADRatchetSession::NewIncomingSession (const i2p::data::LocalDestination& dest,
|
||||||
const uint8_t * buf, size_t len, CloveI2NPMsgHandler handleCloveI2NPMsg)
|
const uint8_t * buf, size_t len, CloveHandler handleClove)
|
||||||
{
|
{
|
||||||
// we are Bob
|
// we are Bob
|
||||||
// KDF1
|
// KDF1
|
||||||
|
@ -87,12 +86,12 @@ namespace garlic
|
||||||
}
|
}
|
||||||
if (isStatic) MixHash (buf, len); // h = SHA256(h || ciphertext)
|
if (isStatic) MixHash (buf, len); // h = SHA256(h || ciphertext)
|
||||||
|
|
||||||
HandlePayload (payload.data (), len - 16, handleCloveI2NPMsg);
|
HandlePayload (payload.data (), len - 16, handleClove);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ECIESX25519AEADRatchetSession::HandlePayload (const uint8_t * buf, size_t len, CloveI2NPMsgHandler& handleCloveI2NPMsg)
|
void ECIESX25519AEADRatchetSession::HandlePayload (const uint8_t * buf, size_t len, CloveHandler& handleClove)
|
||||||
{
|
{
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
while (offset < len)
|
while (offset < len)
|
||||||
|
@ -110,7 +109,7 @@ namespace garlic
|
||||||
switch (blk)
|
switch (blk)
|
||||||
{
|
{
|
||||||
case eECIESx25519BlkGalicClove:
|
case eECIESx25519BlkGalicClove:
|
||||||
HandleClove (buf + offset, size, handleCloveI2NPMsg);
|
handleClove (buf + offset, size);
|
||||||
break;
|
break;
|
||||||
case eECIESx25519BlkDateTime:
|
case eECIESx25519BlkDateTime:
|
||||||
LogPrint (eLogDebug, "Garlic: datetime");
|
LogPrint (eLogDebug, "Garlic: datetime");
|
||||||
|
@ -119,7 +118,7 @@ namespace garlic
|
||||||
LogPrint (eLogDebug, "Garlic: options");
|
LogPrint (eLogDebug, "Garlic: options");
|
||||||
break;
|
break;
|
||||||
case eECIESx25519BlkPadding:
|
case eECIESx25519BlkPadding:
|
||||||
LogPrint (eLogDebug, "NTCP2: padding");
|
LogPrint (eLogDebug, "Garlic: padding");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogPrint (eLogWarning, "Garlic: Unknown block type ", (int)blk);
|
LogPrint (eLogWarning, "Garlic: Unknown block type ", (int)blk);
|
||||||
|
@ -127,33 +126,6 @@ namespace garlic
|
||||||
offset += size;
|
offset += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ECIESX25519AEADRatchetSession::HandleClove (const uint8_t * buf, size_t len, CloveI2NPMsgHandler& handleCloveI2NPMsg)
|
|
||||||
{
|
|
||||||
const uint8_t * buf1 = buf;
|
|
||||||
uint8_t flag = buf[0]; buf++; // flag
|
|
||||||
GarlicDeliveryType deliveryType = (GarlicDeliveryType)((flag >> 5) & 0x03);
|
|
||||||
switch (deliveryType)
|
|
||||||
{
|
|
||||||
case eGarlicDeliveryTypeDestination:
|
|
||||||
buf += 32; // TODO: check destination
|
|
||||||
// no break here
|
|
||||||
case eGarlicDeliveryTypeLocal:
|
|
||||||
{
|
|
||||||
uint8_t typeID = buf[0]; buf++; // typeid
|
|
||||||
buf += (4 + 4); // msgID + expiration
|
|
||||||
ptrdiff_t offset = buf - buf1;
|
|
||||||
if (offset <= (int)len)
|
|
||||||
handleCloveI2NPMsg (typeID, buf, len - offset);
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Garlic: clove is too long");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// TODO: tunnel
|
|
||||||
default:
|
|
||||||
LogPrint (eLogWarning, "Garlic: unexpected delivery type ", (int)deliveryType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,20 +24,19 @@ namespace garlic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::function<void (uint8_t typeID, const uint8_t * payload, size_t len)> CloveI2NPMsgHandler;
|
typedef std::function<void (const uint8_t * buf, size_t len)> CloveHandler;
|
||||||
|
|
||||||
ECIESX25519AEADRatchetSession ();
|
ECIESX25519AEADRatchetSession ();
|
||||||
~ECIESX25519AEADRatchetSession ();
|
~ECIESX25519AEADRatchetSession ();
|
||||||
|
|
||||||
bool NewIncomingSession (const i2p::data::LocalDestination& dest, const uint8_t * buf, size_t len,
|
bool NewIncomingSession (const i2p::data::LocalDestination& dest, const uint8_t * buf, size_t len,
|
||||||
CloveI2NPMsgHandler handleCloveI2NPMsg);
|
CloveHandler handleClove);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void MixHash (const uint8_t * buf, size_t len);
|
void MixHash (const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
void HandlePayload (const uint8_t * buf, size_t len, CloveI2NPMsgHandler& handleCloveI2NPMsg);
|
void HandlePayload (const uint8_t * buf, size_t len, CloveHandler& handleClove);
|
||||||
void HandleClove (const uint8_t * buf, size_t len, CloveI2NPMsgHandler& handleCloveI2NPMsg);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -833,11 +833,64 @@ namespace garlic
|
||||||
void GarlicDestination::HandleECIESx25519 (const uint8_t * buf, size_t len)
|
void GarlicDestination::HandleECIESx25519 (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
ECIESX25519AEADRatchetSession session;
|
ECIESX25519AEADRatchetSession session;
|
||||||
session.NewIncomingSession (*this, buf, len,
|
session.NewIncomingSession (*this, buf, len, std::bind (&GarlicDestination::HandleECIESx25519GarlicClove,
|
||||||
[this](uint8_t typeID, const uint8_t * payload, size_t len)
|
this, std::placeholders::_1, std::placeholders::_2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GarlicDestination::HandleECIESx25519GarlicClove (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
HandleCloveI2NPMessage (typeID, payload,len);
|
const uint8_t * buf1 = buf;
|
||||||
});
|
uint8_t flag = buf[0]; buf++; // flag
|
||||||
|
GarlicDeliveryType deliveryType = (GarlicDeliveryType)((flag >> 5) & 0x03);
|
||||||
|
switch (deliveryType)
|
||||||
|
{
|
||||||
|
case eGarlicDeliveryTypeDestination:
|
||||||
|
LogPrint (eLogDebug, "Garlic: type destination");
|
||||||
|
buf += 32; // TODO: check destination
|
||||||
|
// no break here
|
||||||
|
case eGarlicDeliveryTypeLocal:
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "Garlic: type local");
|
||||||
|
I2NPMessageType typeID = (I2NPMessageType)(buf[0]); buf++; // typeid
|
||||||
|
buf += (4 + 4); // msgID + expiration
|
||||||
|
ptrdiff_t offset = buf - buf1;
|
||||||
|
if (offset <= (int)len)
|
||||||
|
HandleCloveI2NPMessage (typeID, buf, len - offset);
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Garlic: clove is too long");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case eGarlicDeliveryTypeTunnel:
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "Garlic: type tunnel");
|
||||||
|
// gwHash and gwTunnel sequence is reverted
|
||||||
|
const uint8_t * gwHash = buf;
|
||||||
|
buf += 32;
|
||||||
|
ptrdiff_t offset = buf - buf1;
|
||||||
|
if (offset + 13 > (int)len)
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "Garlic: message is too short");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
uint32_t gwTunnel = bufbe32toh (buf); buf += 4;
|
||||||
|
I2NPMessageType typeID = (I2NPMessageType)(buf[0]); buf++; // typeid
|
||||||
|
buf += (4 + 4); // msgID + expiration
|
||||||
|
offset += 13;
|
||||||
|
if (GetTunnelPool ())
|
||||||
|
{
|
||||||
|
auto tunnel = GetTunnelPool ()->GetNextOutboundTunnel ();
|
||||||
|
if (tunnel)
|
||||||
|
tunnel->SendTunnelDataMsg (gwHash, gwTunnel, CreateI2NPMessage (typeID, buf, len - offset));
|
||||||
|
else
|
||||||
|
LogPrint (eLogWarning, "Garlic: No outbound tunnels available for garlic clove");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Garlic: Tunnel pool is not set for inbound tunnel");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
LogPrint (eLogWarning, "Garlic: unexpected delivery type ", (int)deliveryType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ namespace garlic
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void HandleI2NPMessage (const uint8_t * buf, size_t len) = 0; // called from clove only
|
virtual void HandleI2NPMessage (const uint8_t * buf, size_t len) = 0; // called from clove only
|
||||||
virtual bool HandleCloveI2NPMessage (uint8_t typeID, const uint8_t * payload, size_t len) = 0;
|
virtual bool HandleCloveI2NPMessage (I2NPMessageType typeID, const uint8_t * payload, size_t len) = 0;
|
||||||
void HandleGarlicMessage (std::shared_ptr<I2NPMessage> msg);
|
void HandleGarlicMessage (std::shared_ptr<I2NPMessage> msg);
|
||||||
void HandleDeliveryStatusMessage (uint32_t msgID);
|
void HandleDeliveryStatusMessage (uint32_t msgID);
|
||||||
|
|
||||||
|
@ -209,6 +209,7 @@ namespace garlic
|
||||||
|
|
||||||
// ECIES-X25519-AEAD-Ratchet
|
// ECIES-X25519-AEAD-Ratchet
|
||||||
void HandleECIESx25519 (const uint8_t * buf, size_t len);
|
void HandleECIESx25519 (const uint8_t * buf, size_t len);
|
||||||
|
void HandleECIESx25519GarlicClove (const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ namespace i2p
|
||||||
|
|
||||||
// implements GarlicDestination
|
// implements GarlicDestination
|
||||||
void HandleI2NPMessage (const uint8_t * buf, size_t len);
|
void HandleI2NPMessage (const uint8_t * buf, size_t len);
|
||||||
bool HandleCloveI2NPMessage (uint8_t typeID, const uint8_t * payload, size_t len) { return false; }; // not implemented
|
bool HandleCloveI2NPMessage (I2NPMessageType typeID, const uint8_t * payload, size_t len) { return false; }; // not implemented
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue