mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-28 00:44:42 +00:00
detect and check imcompatible crypto between local destination and LeaseSet
This commit is contained in:
@@ -529,9 +529,12 @@ namespace http {
|
||||
<< "<td>" << it.first.ToBase32 () << "</td>"
|
||||
<< "<td><a class=\"button\" href=\"" << webroot << "?cmd=" << HTTP_COMMAND_EXPIRELEASE<< "&b32=" << dest->GetIdentHash ().ToBase32 ()
|
||||
<< "&lease=" << it.first.ToBase32 () << "&token=" << token << "\" title=\"" << tr("Expire LeaseSet") << "\"> ✘ </a></td>"
|
||||
<< "<td>" << (int)it.second->GetStoreType () << "</td>"
|
||||
<< "<td>" << (int)it.second->GetEncryptionType () <<"</td>"
|
||||
<< "</tr>\r\n";
|
||||
<< "<td>" << (int)it.second->GetStoreType () << "</td>";
|
||||
if (!it.second->IsIncompatibleCrypto ())
|
||||
s << "<td>" << (int)it.second->GetEncryptionType () <<"</td>";
|
||||
else
|
||||
s << "<td>n/a</td>";
|
||||
s << "</tr>\r\n";
|
||||
}
|
||||
s << "</tbody>\r\n</table>\r\n";
|
||||
s << "</div>\r\n</div>\r\n<br>\r\n";
|
||||
|
||||
@@ -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<i2p::data::LeaseSet> (buf + offset, len - offset); // LeaseSet
|
||||
if (!SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ELGAMAL))
|
||||
leaseSet->SetIsIncompatibleCrypto (true);
|
||||
}
|
||||
else
|
||||
{
|
||||
leaseSet = std::make_shared<i2p::data::LeaseSet2> (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<const i2p::data::LeaseSet> 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<i2p::data::LeaseSet> ls)
|
||||
{
|
||||
if (ls)
|
||||
if (ls && !ls->IsIncompatibleCrypto ())
|
||||
streamRequestComplete(s->CreateStream (ls, port));
|
||||
else
|
||||
streamRequestComplete (nullptr);
|
||||
|
||||
@@ -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++;
|
||||
|
||||
+3
-1
@@ -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<std::shared_ptr<const Lease> > GetNonExpiredLeases (bool withThreshold = true) const;
|
||||
const std::vector<std::shared_ptr<const Lease> > 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<std::shared_ptr<Lease>, LeaseCmp> m_Leases;
|
||||
uint64_t m_ExpirationTime; // in milliseconds
|
||||
std::shared_ptr<const IdentityEx> m_Identity;
|
||||
|
||||
Reference in New Issue
Block a user