From 6cfef968638de1b887216ae2c0e5396aad322e2a Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 10 Jun 2026 20:17:21 -0400 Subject: [PATCH] always submit ECIES key/tag --- libi2pd/Destination.cpp | 11 +++-------- libi2pd/Garlic.cpp | 9 +++------ libi2pd/I2NPProtocol.cpp | 19 +++++-------------- libi2pd/I2NPProtocol.h | 2 +- libi2pd/TunnelPool.cpp | 24 +++++------------------- 5 files changed, 17 insertions(+), 48 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 7678465c..6bd8acfe 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -863,18 +863,13 @@ namespace client request->excluded.insert (nextFloodfill->GetIdentHash ()); request->requestTimeoutTimer.cancel (); - bool isECIES = GetRatchetsHighestCryptoType () > 0 && - nextFloodfill->GetVersion () >= MAKE_VERSION_NUMBER(0, 9, 46); // >= 0.9.46; uint8_t replyKey[32], replyTag[32]; RAND_bytes (replyKey, 32); // random session key - RAND_bytes (replyTag, isECIES ? 8 : 32); // random session tag - if (isECIES) - AddECIESx25519Key (replyKey, replyTag); - else - AddSessionKey (replyKey, replyTag); + RAND_bytes (replyTag, 8); // random session tag + AddECIESx25519Key (replyKey, replyTag); auto msg = WrapMessageForRouter (nextFloodfill, - CreateLeaseSetDatabaseLookupMsg (dest, request->excluded, request->replyTunnel, replyKey, replyTag, isECIES)); + CreateLeaseSetDatabaseLookupMsg (dest, request->excluded, request->replyTunnel, replyKey, replyTag)); auto s = shared_from_this (); msg->onDrop = [s, dest, request]() { diff --git a/libi2pd/Garlic.cpp b/libi2pd/Garlic.cpp index 087aced7..07084fba 100644 --- a/libi2pd/Garlic.cpp +++ b/libi2pd/Garlic.cpp @@ -507,11 +507,8 @@ namespace garlic auto mod = length & 0x0f; // %16 buf += 4; // length - bool found = false; - bool supportsRatchets = SupportsRatchets (); - if (supportsRatchets) - // try ECIESx25519 tag - found = HandleECIESx25519TagMessage (buf, length); + // try ECIESx25519 tag, might be used even is ratchets not supported + bool found = HandleECIESx25519TagMessage (buf, length); if (!found) { auto it = !mod ? m_Tags.find (SessionTag(buf)) : m_Tags.end (); // AES block is multiple of 16 @@ -546,7 +543,7 @@ namespace garlic decryption->Decrypt(buf + 514, length - 514, iv, buf + 514); HandleAESBlock (buf + 514, length - 514, decryption, msg->from); } - else if (supportsRatchets) + else if (SupportsRatchets ()) { // otherwise ECIESx25519 auto ts = i2p::util::GetMillisecondsSinceEpoch (); diff --git a/libi2pd/I2NPProtocol.cpp b/libi2pd/I2NPProtocol.cpp index f13cb2a9..8e2df3bb 100644 --- a/libi2pd/I2NPProtocol.cpp +++ b/libi2pd/I2NPProtocol.cpp @@ -189,7 +189,7 @@ namespace i2p std::shared_ptr CreateLeaseSetDatabaseLookupMsg (const i2p::data::IdentHash& dest, const std::unordered_set& excludedFloodfills, std::shared_ptr replyTunnel, const uint8_t * replyKey, - const uint8_t * replyTag, bool replyECIES) + const uint8_t * replyTag) { int cnt = excludedFloodfills.size (); auto m = cnt > 7 ? NewI2NPMessage () : NewI2NPShortMessage (); @@ -198,9 +198,8 @@ namespace i2p buf += 32; memcpy (buf, replyTunnel->GetNextIdentHash (), 32); // reply tunnel GW buf += 32; - *buf = DATABASE_LOOKUP_DELIVERY_FLAG | DATABASE_LOOKUP_TYPE_LEASESET_LOOKUP; // flags - *buf |= (replyECIES ? DATABASE_LOOKUP_ECIES_FLAG : DATABASE_LOOKUP_ENCRYPTION_FLAG); - buf ++; + *buf = DATABASE_LOOKUP_DELIVERY_FLAG | DATABASE_LOOKUP_TYPE_LEASESET_LOOKUP | DATABASE_LOOKUP_ECIES_FLAG; // flags + buf++; htobe32buf (buf, replyTunnel->GetNextTunnelID ()); // reply tunnel ID buf += 4; @@ -223,16 +222,8 @@ namespace i2p // encryption memcpy (buf, replyKey, 32); buf[32] = 1; // 1 tag - if (replyECIES) - { - memcpy (buf + 33, replyTag, 8); // 8 bytes tag - buf += 41; - } - else - { - memcpy (buf + 33, replyTag, 32); // 32 bytes tag - buf += 65; - } + memcpy (buf + 33, replyTag, 8); // 8 bytes tag + buf += 41; m->len += (buf - m->GetPayload ()); m->FillI2NPMessageHeader (eI2NPDatabaseLookup); diff --git a/libi2pd/I2NPProtocol.h b/libi2pd/I2NPProtocol.h index f28fa70c..222bfcca 100644 --- a/libi2pd/I2NPProtocol.h +++ b/libi2pd/I2NPProtocol.h @@ -278,7 +278,7 @@ namespace tunnel std::shared_ptr CreateLeaseSetDatabaseLookupMsg (const i2p::data::IdentHash& dest, const std::unordered_set& excludedFloodfills, std::shared_ptr replyTunnel, - const uint8_t * replyKey, const uint8_t * replyTag, bool replyECIES = false); + const uint8_t * replyKey, const uint8_t * replyTag); std::shared_ptr CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, std::vector routers); std::shared_ptr CreateDatabaseStoreMsg (std::shared_ptr router = nullptr, uint32_t replyToken = 0, std::shared_ptr replyTunnel = nullptr); diff --git a/libi2pd/TunnelPool.cpp b/libi2pd/TunnelPool.cpp index 9d987c86..d86fe604 100644 --- a/libi2pd/TunnelPool.cpp +++ b/libi2pd/TunnelPool.cpp @@ -431,7 +431,6 @@ namespace tunnel newTests.push_back(std::make_pair (*it1, *it2)); ++it1; ++it2; } - bool isECIES = m_LocalDestination->GetRatchetsHighestCryptoType () > 0; for (auto& it: newTests) { uint32_t msgID; @@ -457,21 +456,11 @@ namespace tunnel } }; // encrypt - if (isECIES) - { - uint8_t key[32]; RAND_bytes (key, 32); - uint64_t tag; RAND_bytes ((uint8_t *)&tag, 8); - m_LocalDestination->SubmitECIESx25519Key (key, tag); - msg = i2p::garlic::WrapECIESX25519Message (msg, key, tag); - } - else - { - uint8_t key[32], tag[32]; - RAND_bytes (key, 32); RAND_bytes (tag, 32); - m_LocalDestination->SubmitSessionKey (key, tag); - i2p::garlic::ElGamalAESSession garlic (key, tag); - msg = garlic.WrapSingleMessage (msg); - } + uint8_t key[32]; RAND_bytes (key, 32); + uint64_t tag; RAND_bytes ((uint8_t *)&tag, 8); + m_LocalDestination->SubmitECIESx25519Key (key, tag); + msg = i2p::garlic::WrapECIESX25519Message (msg, key, tag); + // send outbound->SendTunnelDataMsgTo (it.second->GetNextIdentHash (), it.second->GetNextTunnelID (), msg); } } @@ -819,9 +808,6 @@ namespace tunnel return; } - if (m_LocalDestination && !m_LocalDestination->GetRatchetsHighestCryptoType ()) - path.isShort = false; // because can't handle ECIES encrypted reply - std::shared_ptr config; if (m_NumOutboundHops > 0) config = std::make_shared(path.peers, inboundTunnel->GetNextTunnelID (),