mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-30 20:24:15 +00:00
create transit tunnel and reply for short tunnel build
This commit is contained in:
parent
5fb426b336
commit
8571830485
@ -424,7 +424,7 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
uint8_t nonce[12];
|
uint8_t nonce[12];
|
||||||
memset (nonce, 0, 12);
|
memset (nonce, 0, 12);
|
||||||
auto noiseState = std::move (i2p::context.GetCurrentNoiseState ());
|
auto& noiseState = i2p::context.GetCurrentNoiseState ();
|
||||||
if (!noiseState || !i2p::crypto::AEADChaCha20Poly1305 (reply, TUNNEL_BUILD_RECORD_SIZE - 16,
|
if (!noiseState || !i2p::crypto::AEADChaCha20Poly1305 (reply, TUNNEL_BUILD_RECORD_SIZE - 16,
|
||||||
noiseState->m_H, 32, noiseState->m_CK, nonce, reply, TUNNEL_BUILD_RECORD_SIZE, true)) // encrypt
|
noiseState->m_H, 32, noiseState->m_CK, nonce, reply, TUNNEL_BUILD_RECORD_SIZE, true)) // encrypt
|
||||||
{
|
{
|
||||||
@ -609,9 +609,19 @@ namespace i2p
|
|||||||
LogPrint (eLogWarning, "I2NP: Can't decrypt short request record ", i);
|
LogPrint (eLogWarning, "I2NP: Can't decrypt short request record ", i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto& noiseState = i2p::context.GetCurrentNoiseState ();
|
||||||
|
uint8_t layerKeys[64]; // (layer key, iv key)
|
||||||
|
i2p::crypto::HKDF (noiseState->m_CK + 32, nullptr, 0, "LayerAndIVKeys", layerKeys); // TODO: correct domain
|
||||||
|
auto transitTunnel = i2p::tunnel::CreateTransitTunnel (
|
||||||
|
bufbe32toh (clearText + SHORT_REQUEST_RECORD_RECEIVE_TUNNEL_OFFSET),
|
||||||
|
clearText + SHORT_REQUEST_RECORD_NEXT_IDENT_OFFSET,
|
||||||
|
bufbe32toh (clearText + SHORT_REQUEST_RECORD_NEXT_TUNNEL_OFFSET),
|
||||||
|
layerKeys, layerKeys + 32,
|
||||||
|
clearText[SHORT_REQUEST_RECORD_FLAG_OFFSET] & 0x80,
|
||||||
|
clearText[SHORT_REQUEST_RECORD_FLAG_OFFSET] & 0x40);
|
||||||
|
i2p::tunnel::tunnels.AddTransitTunnel (transitTunnel);
|
||||||
// TODO: fill reply
|
// TODO: fill reply
|
||||||
// encrypt reply
|
// encrypt reply
|
||||||
auto noiseState = std::move (i2p::context.GetCurrentNoiseState ());
|
|
||||||
if (!noiseState)
|
if (!noiseState)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "I2NP: Invalid Noise state for short reply encryption");
|
LogPrint (eLogWarning, "I2NP: Invalid Noise state for short reply encryption");
|
||||||
@ -622,6 +632,7 @@ namespace i2p
|
|||||||
uint8_t * reply = buf + 1;
|
uint8_t * reply = buf + 1;
|
||||||
for (int j = 0; j < num; j++)
|
for (int j = 0; j < num; j++)
|
||||||
{
|
{
|
||||||
|
nonce[4] = j; // nonce is record #
|
||||||
if (j == i)
|
if (j == i)
|
||||||
{
|
{
|
||||||
if (!i2p::crypto::AEADChaCha20Poly1305 (reply, SHORT_TUNNEL_BUILD_RECORD_SIZE - 16,
|
if (!i2p::crypto::AEADChaCha20Poly1305 (reply, SHORT_TUNNEL_BUILD_RECORD_SIZE - 16,
|
||||||
@ -635,7 +646,10 @@ namespace i2p
|
|||||||
i2p::crypto::ChaCha20 (reply, SHORT_TUNNEL_BUILD_RECORD_SIZE, noiseState->m_CK, nonce, reply);
|
i2p::crypto::ChaCha20 (reply, SHORT_TUNNEL_BUILD_RECORD_SIZE, noiseState->m_CK, nonce, reply);
|
||||||
reply += SHORT_TUNNEL_BUILD_RECORD_SIZE;
|
reply += SHORT_TUNNEL_BUILD_RECORD_SIZE;
|
||||||
}
|
}
|
||||||
// TODO: send
|
// TODO: send reply
|
||||||
|
transports.SendMessage (clearText + SHORT_REQUEST_RECORD_NEXT_TUNNEL_OFFSET,
|
||||||
|
CreateI2NPMessage (eI2NPShortTunnelBuild, buf, len,
|
||||||
|
bufbe32toh (clearText + SHORT_REQUEST_RECORD_SEND_MSG_ID_OFFSET)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
record += SHORT_TUNNEL_BUILD_RECORD_SIZE;
|
record += SHORT_TUNNEL_BUILD_RECORD_SIZE;
|
||||||
|
@ -104,6 +104,15 @@ namespace i2p
|
|||||||
|
|
||||||
// ShortRequestRecordClearText
|
// ShortRequestRecordClearText
|
||||||
const size_t SHORT_REQUEST_RECORD_ENCRYPTED_OFFSET = 16;
|
const size_t SHORT_REQUEST_RECORD_ENCRYPTED_OFFSET = 16;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_RECEIVE_TUNNEL_OFFSET = 0;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_NEXT_TUNNEL_OFFSET = SHORT_REQUEST_RECORD_RECEIVE_TUNNEL_OFFSET + 4;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_NEXT_IDENT_OFFSET = SHORT_REQUEST_RECORD_NEXT_TUNNEL_OFFSET + 4;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_FLAG_OFFSET = SHORT_REQUEST_RECORD_NEXT_IDENT_OFFSET + 32;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_MORE_FLAGS_OFFSET = SHORT_REQUEST_RECORD_FLAG_OFFSET + 1;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_LAYER_ENCRYPTION_TYPE = SHORT_REQUEST_RECORD_MORE_FLAGS_OFFSET + 2;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_REQUEST_TIME_OFFSET = SHORT_REQUEST_RECORD_LAYER_ENCRYPTION_TYPE + 1;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_REQUEST_EXPIRATION_OFFSET = SHORT_REQUEST_RECORD_REQUEST_TIME_OFFSET + 4;
|
||||||
|
const size_t SHORT_REQUEST_RECORD_SEND_MSG_ID_OFFSET = SHORT_REQUEST_RECORD_REQUEST_EXPIRATION_OFFSET + 4;
|
||||||
const size_t SHORT_REQUEST_RECORD_CLEAR_TEXT_SIZE = 172;
|
const size_t SHORT_REQUEST_RECORD_CLEAR_TEXT_SIZE = 172;
|
||||||
|
|
||||||
enum I2NPMessageType
|
enum I2NPMessageType
|
||||||
|
Loading…
x
Reference in New Issue
Block a user