Skip to content

Commit

Permalink
fake tunnel build ecord
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jun 19, 2014
1 parent 59439eb commit 53be08e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace tunnel
void Tunnel::Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel)
{
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 ();
*msg->GetPayload () = numRecords;
msg->len += numRecords*sizeof (I2NPBuildRequestRecordElGamalEncrypted) + 1;
Expand All @@ -52,7 +52,13 @@ namespace tunnel
i++;
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;
hop = m_Config->GetLastHop ()->prev;
while (hop)
Expand Down Expand Up @@ -81,12 +87,6 @@ namespace tunnel
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
{
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;
TunnelHopConfig * hop = m_Config->GetLastHop ();
Expand All @@ -98,26 +98,34 @@ namespace tunnel
TunnelHopConfig * hop1 = hop;
while (hop1)
{
uint8_t * record = msg + 1 + hop1->recordIndex*sizeof (I2NPBuildResponseRecord);
decryption.Decrypt(record, sizeof (I2NPBuildResponseRecord), record);
auto idx = hop1->recordIndex;
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;
}
hop = hop->prev;
}

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);
if (record->ret)
// if any of participants declined the tunnel is not established
m_IsEstablished = false;
hop = hop->next;
}
if (m_IsEstablished)
{
// change reply keys to layer keys
TunnelHopConfig * hop = m_Config->GetFirstHop ();
hop = m_Config->GetFirstHop ();
while (hop)
{
hop->decryption.SetKeys (hop->layerKey, hop->ivKey);
Expand Down

0 comments on commit 53be08e

Please sign in to comment.