MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / ProcessSessionRequest

Method ProcessSessionRequest

libi2pd/SSU2Session.cpp:830–3471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

828 }
829
830 bool SSU2Session::ProcessSessionRequest (Header& header, uint8_t * buf, size_t len)
831 {
832 // we are Bob
833 if (len < 90)
834 {
835 LogPrint (eLogWarning, "SSU2: SessionRequest message too short ", len);
836 return false;
837 }
838#if OPENSSL_PQ
839 if (header.h.flags[0] >= 2 && header.h.flags[0] <= 4) // ver
840 {
841 if (m_Server.GetVersion () > 2)
842 {
843 if (SetVersion (header.h.flags[0]))
844 {
845 if (m_Version > 2)
846 {
847 auto keyLen = i2p::crypto::GetMLKEMPublicKeyLen ((i2p::data::CryptoKeyType)(m_Version + 2));
848 if (len < keyLen + 16 + 90)
849 {
850 LogPrint (eLogWarning, "SSU2: SessionRequest version ", m_Version, " message too short ", len);
851 return false;
852 }
853 }
854 }
855 else
856 {
857 m_TerminationReason = eSSU2TerminationReasonIncompatibleVersion;
858 SendRetry ();
859 return true;
860 }
861 }
862 }
863 else
864#else
865 if (header.h.flags[0] != 2) // ver
866#endif
867 {
868 LogPrint (eLogWarning, "SSU2: SessionRequest protocol version ", (int)header.h.flags[0], " is not supported");
869 return false;
870 }
871 const uint8_t nonce[12] = {0};
872 uint8_t headerX[48];
873 m_Server.ChaCha20 (buf + 16, 48, i2p::context.GetSSU2IntroKey (), nonce, headerX);
874 memcpy (&m_DestConnID, headerX, 8);
875 uint64_t token;
876 memcpy (&token, headerX + 8, 8);
877 if (!token || token != m_Server.GetIncomingToken (m_RemoteEndpoint))
878 {
879 LogPrint (eLogDebug, "SSU2: SessionRequest token mismatch. Retry");
880 SendRetry ();
881 return true;
882 }
883 // create and init noise state
884 if (!m_NoiseState) m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState);
885#if OPENSSL_PQ
886 if (m_Version > 2)
887 {

Callers

nothing calls this directly

Calls 15

LogPrintFunction · 0.85
GetMLKEMPublicKeyLenFunction · 0.85
InitNoiseXKStateMLKEM1Function · 0.85
InitNoiseXKState1Function · 0.85
CreateMLKEMKeysFunction · 0.85
ChaCha20Method · 0.80
GetSSU2IntroKeyMethod · 0.80
GetIncomingTokenMethod · 0.80
MixHashMethod · 0.80
AgreeMethod · 0.80
MixKeyMethod · 0.80

Tested by

no test coverage detected