From 5c9af1c6130ed486fff2d528032361d0669d4f3e Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 18 Mar 2022 15:32:32 -0400 Subject: [PATCH] MixHash with encrypted payload after decryption --- libi2pd/SSU2.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index 65dc12f7..966bd267 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -124,15 +124,17 @@ namespace transport i2p::context.GetSSU2StaticKeys ().Agree (headerX + 16, sharedSecret); m_NoiseState->MixKey (sharedSecret); // decrypt - uint8_t * payload = buf + 64; - m_NoiseState->MixHash (payload, 24); // h = SHA256(h || 24 byte encrypted payload from Session Request) for SessionCreated - if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len - 80, m_NoiseState->m_H, 32, m_NoiseState->m_CK + 32, nonce, payload, len - 80, false)) + uint8_t * payload = buf + 64; + std::vector decryptedPayload(len - 80); + if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len - 80, m_NoiseState->m_H, 32, + m_NoiseState->m_CK + 32, nonce, decryptedPayload.data (), decryptedPayload.size (), false)) { LogPrint (eLogWarning, "SSU2: SessionRequest AEAD verification failed "); return; } + m_NoiseState->MixHash (payload, 24); // h = SHA256(h || 24 byte encrypted payload from Session Request) for SessionCreated // payload - HandlePayload (payload, len - 80); + HandlePayload (decryptedPayload.data (), decryptedPayload.size ()); m_Server.AddSession (m_SourceConnID, shared_from_this ()); SendSessionCreated (headerX + 16); @@ -497,7 +499,10 @@ namespace transport boost::asio::buffer (payload, payloadLen) }; boost::system::error_code ec; - m_Socket.send_to (bufs, to, 0, ec); + if (to.address ().is_v6 ()) + m_SocketV6.send_to (bufs, to, 0, ec); + else + m_Socket.send_to (bufs, to, 0, ec); } bool SSU2Server::CreateSession (std::shared_ptr router,