mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
garlic encryption of inbound tunnel build message
This commit is contained in:
parent
d47bf1bada
commit
1e9eb30aa3
|
@ -1133,7 +1133,7 @@ namespace garlic
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> WrapECIESX25519AEADRatchetMessage (std::shared_ptr<const I2NPMessage> msg, const uint8_t * key, uint64_t tag)
|
std::shared_ptr<I2NPMessage> WrapECIESX25519Message (std::shared_ptr<const I2NPMessage> msg, const uint8_t * key, uint64_t tag)
|
||||||
{
|
{
|
||||||
auto m = NewI2NPMessage ();
|
auto m = NewI2NPMessage ();
|
||||||
m->Align (12); // in order to get buf aligned to 16 (12 + 4)
|
m->Align (12); // in order to get buf aligned to 16 (12 + 4)
|
||||||
|
@ -1167,5 +1167,12 @@ namespace garlic
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<I2NPMessage> WrapECIESX25519MessageForRouter (std::shared_ptr<const I2NPMessage> msg, const uint8_t * routerPublicKey)
|
||||||
|
{
|
||||||
|
// TODO: implement without session
|
||||||
|
auto session = std::make_shared<ECIESX25519AEADRatchetSession>(nullptr, false);
|
||||||
|
session->SetRemoteStaticKey (routerPublicKey);
|
||||||
|
return session->WrapOneTimeMessage (msg, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,8 @@ namespace garlic
|
||||||
i2p::crypto::NoiseSymmetricState m_CurrentNoiseState;
|
i2p::crypto::NoiseSymmetricState m_CurrentNoiseState;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> WrapECIESX25519AEADRatchetMessage (std::shared_ptr<const I2NPMessage> msg, const uint8_t * key, uint64_t tag);
|
std::shared_ptr<I2NPMessage> WrapECIESX25519Message (std::shared_ptr<const I2NPMessage> msg, const uint8_t * key, uint64_t tag);
|
||||||
|
std::shared_ptr<I2NPMessage> WrapECIESX25519MessageForRouter (std::shared_ptr<const I2NPMessage> msg, const uint8_t * routerPublicKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -675,7 +675,7 @@ namespace i2p
|
||||||
// send garlic to reply tunnel
|
// send garlic to reply tunnel
|
||||||
transports.SendMessage (clearText + SHORT_REQUEST_RECORD_NEXT_IDENT_OFFSET,
|
transports.SendMessage (clearText + SHORT_REQUEST_RECORD_NEXT_IDENT_OFFSET,
|
||||||
CreateTunnelGatewayMsg (bufbe32toh (clearText + SHORT_REQUEST_RECORD_NEXT_TUNNEL_OFFSET),
|
CreateTunnelGatewayMsg (bufbe32toh (clearText + SHORT_REQUEST_RECORD_NEXT_TUNNEL_OFFSET),
|
||||||
i2p::garlic::WrapECIESX25519AEADRatchetMessage (otbrm, noiseState.m_CK + 32, tag)));
|
i2p::garlic::WrapECIESX25519Message (otbrm, noiseState.m_CK + 32, tag)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -988,7 +988,7 @@ namespace data
|
||||||
{
|
{
|
||||||
uint64_t tag;
|
uint64_t tag;
|
||||||
memcpy (&tag, excluded + 33, 8);
|
memcpy (&tag, excluded + 33, 8);
|
||||||
replyMsg = i2p::garlic::WrapECIESX25519AEADRatchetMessage (replyMsg, sessionKey, tag);
|
replyMsg = i2p::garlic::WrapECIESX25519Message (replyMsg, sessionKey, tag);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "Tunnel.h"
|
#include "Tunnel.h"
|
||||||
#include "TunnelPool.h"
|
#include "TunnelPool.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "ECIESX25519AEADRatchetSession.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -91,7 +92,12 @@ namespace tunnel
|
||||||
|
|
||||||
// send message
|
// send message
|
||||||
if (outboundTunnel)
|
if (outboundTunnel)
|
||||||
|
{
|
||||||
|
auto ident = m_Config->GetFirstHop () ? m_Config->GetFirstHop ()->ident : nullptr;
|
||||||
|
if (ident && ident->GetCryptoKeyType () == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)
|
||||||
|
msg = i2p::garlic::WrapECIESX25519MessageForRouter (msg, ident->GetEncryptionPublicKey ());
|
||||||
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
|
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
i2p::transport::transports.SendMessage (GetNextIdentHash (), msg);
|
i2p::transport::transports.SendMessage (GetNextIdentHash (), msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue