mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-09 20:51:04 +00:00
don't rely on order in tunnel build message. assign index to hop instead
This commit is contained in:
parent
b95caaf219
commit
59439ebf26
36
Tunnel.cpp
36
Tunnel.cpp
@ -48,22 +48,27 @@ namespace tunnel
|
|||||||
hop->next ? rnd.GenerateWord32 () : replyMsgID, // we set replyMsgID for last hop only
|
hop->next ? rnd.GenerateWord32 () : replyMsgID, // we set replyMsgID for last hop only
|
||||||
hop->isGateway, hop->isEndpoint),
|
hop->isGateway, hop->isEndpoint),
|
||||||
records[i]);
|
records[i]);
|
||||||
|
hop->recordIndex = i; //TODO:
|
||||||
i++;
|
i++;
|
||||||
hop = hop->next;
|
hop = hop->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::crypto::CBCDecryption decryption;
|
i2p::crypto::CBCDecryption decryption;
|
||||||
hop = m_Config->GetLastHop ()->prev;
|
hop = m_Config->GetLastHop ()->prev;
|
||||||
size_t ind = numRecords - 1;
|
|
||||||
while (hop)
|
while (hop)
|
||||||
{
|
{
|
||||||
decryption.SetKey (hop->replyKey);
|
decryption.SetKey (hop->replyKey);
|
||||||
decryption.SetIV (hop->replyIV);
|
decryption.SetIV (hop->replyIV);
|
||||||
for (size_t i = ind; i < numRecords; i++)
|
// decrypt records after current hop
|
||||||
decryption.Decrypt((uint8_t *)&records[i],
|
TunnelHopConfig * hop1 = hop->next;
|
||||||
sizeof (I2NPBuildRequestRecordElGamalEncrypted), (uint8_t *)&records[i]);
|
while (hop1)
|
||||||
|
{
|
||||||
|
decryption.Decrypt((uint8_t *)&records[hop1->recordIndex],
|
||||||
|
sizeof (I2NPBuildRequestRecordElGamalEncrypted),
|
||||||
|
(uint8_t *)&records[hop1->recordIndex]);
|
||||||
|
hop1 = hop1->next;
|
||||||
|
}
|
||||||
hop = hop->prev;
|
hop = hop->prev;
|
||||||
ind--;
|
|
||||||
}
|
}
|
||||||
FillI2NPMessageHeader (msg, eI2NPVariableTunnelBuild);
|
FillI2NPMessageHeader (msg, eI2NPVariableTunnelBuild);
|
||||||
|
|
||||||
@ -76,21 +81,28 @@ 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 ();
|
||||||
int num = msg[0];
|
|
||||||
while (hop)
|
while (hop)
|
||||||
{
|
{
|
||||||
decryption.SetKey (hop->replyKey);
|
decryption.SetKey (hop->replyKey);
|
||||||
decryption.SetIV (hop->replyIV);
|
decryption.SetIV (hop->replyIV);
|
||||||
for (int i = 0; i < num; i++)
|
// decrypt records before and including current hop
|
||||||
{
|
TunnelHopConfig * hop1 = hop;
|
||||||
uint8_t * record = msg + 1 + i*sizeof (I2NPBuildResponseRecord);
|
while (hop1)
|
||||||
|
{
|
||||||
|
uint8_t * record = msg + 1 + hop1->recordIndex*sizeof (I2NPBuildResponseRecord);
|
||||||
decryption.Decrypt(record, sizeof (I2NPBuildResponseRecord), record);
|
decryption.Decrypt(record, sizeof (I2NPBuildResponseRecord), record);
|
||||||
}
|
hop1 = hop1->prev;
|
||||||
|
}
|
||||||
hop = hop->prev;
|
hop = hop->prev;
|
||||||
num--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_IsEstablished = true;
|
m_IsEstablished = true;
|
||||||
|
@ -24,6 +24,7 @@ namespace tunnel
|
|||||||
|
|
||||||
TunnelHopConfig * next, * prev;
|
TunnelHopConfig * next, * prev;
|
||||||
i2p::crypto::TunnelDecryption decryption;
|
i2p::crypto::TunnelDecryption decryption;
|
||||||
|
int recordIndex; // record # in tunnel build message
|
||||||
|
|
||||||
TunnelHopConfig (const i2p::data::RouterInfo * r)
|
TunnelHopConfig (const i2p::data::RouterInfo * r)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user