From a776441ce1ab5871e8a4e1d5d7a98c7ef50b61a4 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 15 Jun 2026 17:08:05 -0400 Subject: [PATCH] detect and check imcompatible crypto between local destination and LeaseSet --- daemon/HTTPServer.cpp | 9 ++++++--- libi2pd/Destination.cpp | 10 +++++++--- libi2pd/LeaseSet.cpp | 10 +++++++--- libi2pd/LeaseSet.h | 4 +++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 4bc762c2..e9db1c95 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -529,9 +529,12 @@ namespace http { << "" << it.first.ToBase32 () << "" << "" - << "" << (int)it.second->GetStoreType () << "" - << "" << (int)it.second->GetEncryptionType () <<"" - << "\r\n"; + << "" << (int)it.second->GetStoreType () << ""; + if (!it.second->IsIncompatibleCrypto ()) + s << "" << (int)it.second->GetEncryptionType () <<""; + else + s << "n/a"; + s << "\r\n"; } s << "\r\n\r\n"; s << "\r\n\r\n
\r\n"; diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 635c70d0..5766f931 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -445,7 +445,11 @@ namespace client { // add or replace if (buf[DATABASE_STORE_TYPE_OFFSET] == i2p::data::NETDB_STORE_TYPE_LEASESET) + { leaseSet = std::make_shared (buf + offset, len - offset); // LeaseSet + if (!SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ELGAMAL)) + leaseSet->SetIsIncompatibleCrypto (true); + } else { leaseSet = std::make_shared (buf[DATABASE_STORE_TYPE_OFFSET], @@ -1216,7 +1220,7 @@ namespace client auto leaseSet = FindLeaseSet (dest); if (leaseSet) { - auto stream = CreateStream (leaseSet, port); + auto stream = (!leaseSet->IsIncompatibleCrypto ()) ? CreateStream (leaseSet, port) : nullptr; boost::asio::post (GetService (), [streamRequestComplete, stream]() { streamRequestComplete(stream); @@ -1228,7 +1232,7 @@ namespace client RequestDestination (dest, [s, streamRequestComplete, port](std::shared_ptr ls) { - if (ls) + if (ls && !ls->IsIncompatibleCrypto ()) streamRequestComplete(s->CreateStream (ls, port)); else streamRequestComplete (nullptr); @@ -1247,7 +1251,7 @@ namespace client RequestDestinationWithEncryptedLeaseSet (dest, [s, streamRequestComplete, port](std::shared_ptr ls) { - if (ls) + if (ls && !ls->IsIncompatibleCrypto ()) streamRequestComplete(s->CreateStream (ls, port)); else streamRequestComplete (nullptr); diff --git a/libi2pd/LeaseSet.cpp b/libi2pd/LeaseSet.cpp index f2b4f561..81db5679 100644 --- a/libi2pd/LeaseSet.cpp +++ b/libi2pd/LeaseSet.cpp @@ -22,13 +22,14 @@ namespace i2p namespace data { LeaseSet::LeaseSet (bool storeLeases): - m_IsValid (false), m_StoreLeases (storeLeases), m_ExpirationTime (0), m_EncryptionKey (nullptr), - m_Buffer (nullptr), m_BufferLen (0) + m_IsValid (false), m_IsIncompatibleCrypto (false), m_StoreLeases (storeLeases), + m_ExpirationTime (0), m_EncryptionKey (nullptr), m_Buffer (nullptr), m_BufferLen (0) { } LeaseSet::LeaseSet (const uint8_t * buf, size_t len, bool storeLeases): - m_IsValid (true), m_StoreLeases (storeLeases), m_ExpirationTime (0), m_EncryptionKey (nullptr) + m_IsValid (true), m_IsIncompatibleCrypto (false), m_StoreLeases (storeLeases), + m_ExpirationTime (0), m_EncryptionKey (nullptr) { m_Buffer = new uint8_t[len]; memcpy (m_Buffer, buf, len); @@ -410,6 +411,7 @@ namespace data // key sections CryptoKeyType preferredKeyType = m_EncryptionType; m_EncryptionType = 0; + m_Encryptor = nullptr; // TODO: atomic bool preferredKeyFound = false; if (offset + 1 > len) return 0; int numKeySections = buf[offset]; offset++; @@ -441,6 +443,8 @@ namespace data } offset += encryptionKeyLen; } + SetIsIncompatibleCrypto (!m_Encryptor); + // leases if (offset + 1 > len) return 0; int numLeases = buf[offset]; offset++; diff --git a/libi2pd/LeaseSet.h b/libi2pd/LeaseSet.h index 6ab546d3..ea4dbd0e 100644 --- a/libi2pd/LeaseSet.h +++ b/libi2pd/LeaseSet.h @@ -81,6 +81,8 @@ namespace data const uint8_t * GetBuffer () const { return m_Buffer; }; size_t GetBufferLen () const { return m_BufferLen; }; bool IsValid () const { return m_IsValid; }; + bool IsIncompatibleCrypto () const { return m_IsIncompatibleCrypto; }; + void SetIsIncompatibleCrypto (bool isIncompatibleCrypto) { m_IsIncompatibleCrypto = isIncompatibleCrypto; }; const std::vector > GetNonExpiredLeases (bool withThreshold = true) const; const std::vector > GetNonExpiredLeasesExcluding (LeaseInspectFunc exclude, bool withThreshold = true) const; bool HasExpiredLeases () const; @@ -125,7 +127,7 @@ namespace data private: - bool m_IsValid, m_StoreLeases; // we don't need to store leases for floodfill + bool m_IsValid, m_IsIncompatibleCrypto, m_StoreLeases; // we don't need to store leases for floodfill std::set, LeaseCmp> m_Leases; uint64_t m_ExpirationTime; // in milliseconds std::shared_ptr m_Identity;