mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
fake tunnel build ecord
This commit is contained in:
parent
59439ebf26
commit
53be08e239
34
Tunnel.cpp
34
Tunnel.cpp
|
@ -27,7 +27,7 @@ namespace tunnel
|
||||||
void Tunnel::Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel)
|
void Tunnel::Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel)
|
||||||
{
|
{
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
size_t numRecords = m_Config->GetNumHops ();
|
int numRecords = m_Config->GetNumHops () + 1; // +1 fake record. TODO:
|
||||||
I2NPMessage * msg = NewI2NPMessage ();
|
I2NPMessage * msg = NewI2NPMessage ();
|
||||||
*msg->GetPayload () = numRecords;
|
*msg->GetPayload () = numRecords;
|
||||||
msg->len += numRecords*sizeof (I2NPBuildRequestRecordElGamalEncrypted) + 1;
|
msg->len += numRecords*sizeof (I2NPBuildRequestRecordElGamalEncrypted) + 1;
|
||||||
|
@ -52,7 +52,13 @@ namespace tunnel
|
||||||
i++;
|
i++;
|
||||||
hop = hop->next;
|
hop = hop->next;
|
||||||
}
|
}
|
||||||
|
// fill up fake records with random data
|
||||||
|
while (i < numRecords)
|
||||||
|
{
|
||||||
|
rnd.GenerateBlock ((uint8_t *)(records + i), sizeof (records[i]));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
i2p::crypto::CBCDecryption decryption;
|
i2p::crypto::CBCDecryption decryption;
|
||||||
hop = m_Config->GetLastHop ()->prev;
|
hop = m_Config->GetLastHop ()->prev;
|
||||||
while (hop)
|
while (hop)
|
||||||
|
@ -81,12 +87,6 @@ namespace tunnel
|
||||||
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
|
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint ("TunnelBuildResponse ", (int)msg[0], " records.");
|
LogPrint ("TunnelBuildResponse ", (int)msg[0], " records.");
|
||||||
auto numHops = m_Config->GetNumHops ();
|
|
||||||
if (msg[0] != numHops)
|
|
||||||
{
|
|
||||||
LogPrint ("Number of records in response ", (int)msg[0], " doesn't match ", numHops);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
i2p::crypto::CBCDecryption decryption;
|
i2p::crypto::CBCDecryption decryption;
|
||||||
TunnelHopConfig * hop = m_Config->GetLastHop ();
|
TunnelHopConfig * hop = m_Config->GetLastHop ();
|
||||||
|
@ -98,26 +98,34 @@ namespace tunnel
|
||||||
TunnelHopConfig * hop1 = hop;
|
TunnelHopConfig * hop1 = hop;
|
||||||
while (hop1)
|
while (hop1)
|
||||||
{
|
{
|
||||||
uint8_t * record = msg + 1 + hop1->recordIndex*sizeof (I2NPBuildResponseRecord);
|
auto idx = hop1->recordIndex;
|
||||||
decryption.Decrypt(record, sizeof (I2NPBuildResponseRecord), record);
|
if (idx >= 0 && idx < msg[0])
|
||||||
|
{
|
||||||
|
uint8_t * record = msg + 1 + idx*sizeof (I2NPBuildResponseRecord);
|
||||||
|
decryption.Decrypt(record, sizeof (I2NPBuildResponseRecord), record);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Tunnel hop index ", idx, " is out of range");
|
||||||
hop1 = hop1->prev;
|
hop1 = hop1->prev;
|
||||||
}
|
}
|
||||||
hop = hop->prev;
|
hop = hop->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_IsEstablished = true;
|
m_IsEstablished = true;
|
||||||
for (int i = 0; i < msg[0]; i++)
|
hop = m_Config->GetFirstHop ();
|
||||||
|
while (hop)
|
||||||
{
|
{
|
||||||
I2NPBuildResponseRecord * record = (I2NPBuildResponseRecord *)(msg + 1 + i*sizeof (I2NPBuildResponseRecord));
|
I2NPBuildResponseRecord * record = (I2NPBuildResponseRecord *)(msg + 1 + hop->recordIndex*sizeof (I2NPBuildResponseRecord));
|
||||||
LogPrint ("Ret code=", (int)record->ret);
|
LogPrint ("Ret code=", (int)record->ret);
|
||||||
if (record->ret)
|
if (record->ret)
|
||||||
// if any of participants declined the tunnel is not established
|
// if any of participants declined the tunnel is not established
|
||||||
m_IsEstablished = false;
|
m_IsEstablished = false;
|
||||||
|
hop = hop->next;
|
||||||
}
|
}
|
||||||
if (m_IsEstablished)
|
if (m_IsEstablished)
|
||||||
{
|
{
|
||||||
// change reply keys to layer keys
|
// change reply keys to layer keys
|
||||||
TunnelHopConfig * hop = m_Config->GetFirstHop ();
|
hop = m_Config->GetFirstHop ();
|
||||||
while (hop)
|
while (hop)
|
||||||
{
|
{
|
||||||
hop->decryption.SetKeys (hop->layerKey, hop->ivKey);
|
hop->decryption.SetKeys (hop->layerKey, hop->ivKey);
|
||||||
|
|
Loading…
Reference in a new issue