From ea1f2d4e260f3502bf37ced83484986038e03107 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 6 Feb 2022 10:17:35 -0500 Subject: [PATCH] use i for intro key for SSU --- libi2pd/RouterInfo.cpp | 8 ++++---- libi2pd/RouterInfo.h | 3 +-- libi2pd/SSUSession.cpp | 14 +++++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index 706186d4..8d6c7120 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -260,7 +260,7 @@ namespace data else if (!strcmp (key, "key")) { if (address->ssu) - isIntroKey = (Base64ToByteStream (value, strlen (value), address->ssu->key, 32) == 32); + isIntroKey = (Base64ToByteStream (value, strlen (value), address->i, 32) == 32); else LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP"); } @@ -592,9 +592,9 @@ namespace data addr->ssu.reset (new SSUExt ()); addr->ssu->mtu = mtu; if (key) - memcpy (addr->ssu->key, key, 32); + memcpy (addr->i, key, 32); else - RAND_bytes (addr->ssu->key, 32); + RAND_bytes (addr->i, 32); for (const auto& it: *m_Addresses) // don't insert same address twice if (*it == *addr) return; m_SupportedTransports |= addr->host.is_v6 () ? eSSUV6 : eSSUV4; @@ -1175,7 +1175,7 @@ namespace data WriteString ("key", properties); properties << '='; char value[64]; - size_t l = ByteStreamToBase64 (address.ssu->key, 32, value, 64); + size_t l = ByteStreamToBase64 (address.i, 32, value, 64); value[l] = 0; WriteString (value, properties); properties << ';'; diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index 3bb7f614..e7f2fd3d 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -109,7 +109,6 @@ namespace data struct SSUExt { int mtu; - IntroKey key; // intro key for SSU std::vector introducers; }; @@ -117,7 +116,7 @@ namespace data { TransportStyle transportStyle; boost::asio::ip::address host; - Tag<32> s, i; // keys, i is first 16 bytes for NTCP2 + Tag<32> s, i; // keys, i is first 16 bytes for NTCP2 and 32 bytes intro key for SSU int port; uint64_t date; uint8_t caps; diff --git a/libi2pd/SSUSession.cpp b/libi2pd/SSUSession.cpp index 9fce9e85..dc9a7ae8 100644 --- a/libi2pd/SSUSession.cpp +++ b/libi2pd/SSUSession.cpp @@ -31,7 +31,7 @@ namespace transport { // we are client auto address = IsV6 () ? router->GetSSUV6Address () : router->GetSSUAddress (true); - if (address) m_IntroKey = address->ssu->key; + if (address) m_IntroKey = address->i; m_Data.AdjustPacketSize (router); // mtu } else @@ -39,7 +39,7 @@ namespace transport // we are server auto address = IsV6 () ? i2p::context.GetRouterInfo ().GetSSUV6Address () : i2p::context.GetRouterInfo ().GetSSUAddress (true); - if (address) m_IntroKey = address->ssu->key; + if (address) m_IntroKey = address->i; } m_CreationTime = i2p::util::GetSecondsSinceEpoch (); } @@ -127,8 +127,8 @@ namespace transport LogPrint (eLogInfo, "SSU: SSU is not supported"); return; } - if (Validate (buf, len, address->ssu->key)) - Decrypt (buf, len, address->ssu->key); + if (Validate (buf, len, address->i)) + Decrypt (buf, len, address->i); else { LogPrint (eLogWarning, "SSU: MAC verification failed ", len, " bytes from ", senderEndpoint); @@ -436,7 +436,7 @@ namespace transport payload += 2; *payload = 0; // challenge payload++; - memcpy (payload, (const uint8_t *)address->ssu->key, 32); + memcpy (payload, (const uint8_t *)address->i, 32); payload += 32; htobe32buf (payload, nonce); // nonce @@ -1183,7 +1183,7 @@ namespace transport auto addr = address.is_v4 () ? i2p::context.GetRouterInfo ().GetSSUAddress (true) : // ipv4 i2p::context.GetRouterInfo ().GetSSUV6Address (); if (addr) - memcpy (payload, addr->ssu->key, 32); // intro key + memcpy (payload, addr->i, 32); // intro key else LogPrint (eLogInfo, "SSU: SSU is not supported. Can't send peer test"); } @@ -1222,7 +1222,7 @@ namespace transport if (!nonce) nonce = 1; m_IsPeerTest = false; m_Server.NewPeerTest (nonce, ePeerTestParticipantAlice1, shared_from_this ()); - SendPeerTest (nonce, boost::asio::ip::address(), 0, address->ssu->key, false, false); // address and port always zero for Alice + SendPeerTest (nonce, boost::asio::ip::address(), 0, address->i, false, false); // address and port always zero for Alice } void SSUSession::SendKeepAlive ()