diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index fab1a397..3a818175 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -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"); - break; + 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 () diff --git a/libi2pd/SSU2Session.h b/libi2pd/SSU2Session.h index a7aa5557..6797e8ce 100644 --- a/libi2pd/SSU2Session.h +++ b/libi2pd/SSU2Session.h @@ -349,6 +349,7 @@ namespace transport boost::asio::deadline_timer m_ConnectTimer; SSU2TerminationReason m_TerminationReason; size_t m_MaxPayloadSize; + std::unique_ptr m_PathChallenge; }; inline uint64_t CreateHeaderMask (const uint8_t * kh, const uint8_t * nonce)