verify path response

This commit is contained in:
orignal 2022-09-14 19:08:14 -04:00
parent 09e6e2940f
commit 857a2bc399
2 changed files with 20 additions and 1 deletions

View File

@ -207,6 +207,8 @@ namespace transport
if (m_RelayTag)
m_Server.RemoveRelay (m_RelayTag);
m_SentHandshakePacket.reset (nullptr);
m_SessionConfirmedFragment.reset (nullptr);
m_PathChallenge.reset (nullptr);
m_SendQueue.clear ();
m_SentPackets.clear ();
m_IncompleteMessages.clear ();
@ -1455,8 +1457,17 @@ namespace transport
SendPathResponse (buf + offset, size);
break;
case eSSU2BlkPathResponse:
{
LogPrint (eLogDebug, "SSU2: Path response");
if (m_PathChallenge)
{
i2p::data::IdentHash hash;
SHA256 (buf + offset, size, hash);
if (hash == *m_PathChallenge)
m_PathChallenge.reset (nullptr);
}
break;
}
case eSSU2BlkFirstPacketNumber:
break;
case eSSU2BlkPadding:
@ -2639,7 +2650,12 @@ namespace transport
size_t len = rand () % (m_MaxPayloadSize - 3);
htobe16buf (payload + 1, len);
if (len > 0)
{
RAND_bytes (payload + 3, len);
i2p::data::IdentHash * hash = new i2p::data::IdentHash ();
SHA256 (payload + 3, len, *hash);
m_PathChallenge.reset (hash);
}
len += 3;
if (len < m_MaxPayloadSize)
len += CreatePaddingBlock (payload + len, m_MaxPayloadSize - len);
@ -2702,6 +2718,8 @@ namespace transport
else
++it;
}
if (m_PathChallenge)
RequestTermination (eSSU2TerminationReasonNormalClose);
}
void SSU2Session::FlushData ()

View File

@ -349,6 +349,7 @@ namespace transport
boost::asio::deadline_timer m_ConnectTimer;
SSU2TerminationReason m_TerminationReason;
size_t m_MaxPayloadSize;
std::unique_ptr<i2p::data::IdentHash> m_PathChallenge;
};
inline uint64_t CreateHeaderMask (const uint8_t * kh, const uint8_t * nonce)