Browse Source

validate leaseset for zero leases

pull/178/head
orignal 10 years ago
parent
commit
d5e1d5db9c
  1. 21
      Destination.cpp
  2. 15
      LeaseSet.cpp
  3. 2
      LeaseSet.h
  4. 18
      NetDb.cpp

21
Destination.cpp

@ -223,13 +223,28 @@ namespace client
{ {
leaseSet = it->second; leaseSet = it->second;
leaseSet->Update (buf + offset, len - offset); leaseSet->Update (buf + offset, len - offset);
LogPrint (eLogDebug, "Remote LeaseSet updated"); if (leaseSet->IsValid ())
LogPrint (eLogDebug, "Remote LeaseSet updated");
else
{
LogPrint (eLogDebug, "Remote LeaseSet update failed");
m_RemoteLeaseSets.erase (it);
leaseSet = nullptr;
}
} }
else else
{ {
LogPrint (eLogDebug, "New remote LeaseSet added");
leaseSet = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset); leaseSet = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset);
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = leaseSet; if (leaseSet->IsValid ())
{
LogPrint (eLogDebug, "New remote LeaseSet added");
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = leaseSet;
}
else
{
LogPrint (eLogError, "New remote LeaseSet verification failed");
leaseSet = nullptr;
}
} }
} }
else else

15
LeaseSet.cpp

@ -14,7 +14,8 @@ namespace i2p
namespace data namespace data
{ {
LeaseSet::LeaseSet (const uint8_t * buf, size_t len) LeaseSet::LeaseSet (const uint8_t * buf, size_t len):
m_IsValid (true)
{ {
m_Buffer = new uint8_t[len]; m_Buffer = new uint8_t[len];
memcpy (m_Buffer, buf, len); memcpy (m_Buffer, buf, len);
@ -22,7 +23,8 @@ namespace data
ReadFromBuffer (); ReadFromBuffer ();
} }
LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool) LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool):
m_IsValid (true)
{ {
// header // header
const i2p::data::LocalDestination * localDestination = pool.GetLocalDestination (); const i2p::data::LocalDestination * localDestination = pool.GetLocalDestination ();
@ -30,6 +32,7 @@ namespace data
{ {
m_Buffer = nullptr; m_Buffer = nullptr;
m_BufferLen = 0; m_BufferLen = 0;
m_IsValid = false;
LogPrint (eLogError, "Destination for local LeaseSet doesn't exist"); LogPrint (eLogError, "Destination for local LeaseSet doesn't exist");
return; return;
} }
@ -88,6 +91,7 @@ namespace data
uint8_t num = m_Buffer[size]; uint8_t num = m_Buffer[size];
size++; // num size++; // num
LogPrint ("LeaseSet num=", (int)num); LogPrint ("LeaseSet num=", (int)num);
if (!num) m_IsValid = false;
// process leases // process leases
const uint8_t * leases = m_Buffer + size; const uint8_t * leases = m_Buffer + size;
@ -106,14 +110,17 @@ namespace data
if (!netdb.FindRouter (lease.tunnelGateway)) if (!netdb.FindRouter (lease.tunnelGateway))
{ {
// if not found request it // if not found request it
LogPrint ("Lease's tunnel gateway not found. Requested"); LogPrint (eLogInfo, "Lease's tunnel gateway not found. Requested");
netdb.RequestDestination (lease.tunnelGateway); netdb.RequestDestination (lease.tunnelGateway);
} }
} }
// verify // verify
if (!m_Identity.Verify (m_Buffer, leases - m_Buffer, leases)) if (!m_Identity.Verify (m_Buffer, leases - m_Buffer, leases))
LogPrint ("LeaseSet verification failed"); {
LogPrint (eLogWarning, "LeaseSet verification failed");
m_IsValid = false;
}
} }
const std::vector<Lease> LeaseSet::GetNonExpiredLeases (bool withThreshold) const const std::vector<Lease> LeaseSet::GetNonExpiredLeases (bool withThreshold) const

2
LeaseSet.h

@ -44,6 +44,7 @@ namespace data
const uint8_t * GetBuffer () const { return m_Buffer; }; const uint8_t * GetBuffer () const { return m_Buffer; };
size_t GetBufferLen () const { return m_BufferLen; }; size_t GetBufferLen () const { return m_BufferLen; };
bool IsValid () const { return m_IsValid; };
// implements RoutingDestination // implements RoutingDestination
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); }; const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
@ -60,6 +61,7 @@ namespace data
private: private:
bool m_IsValid;
std::vector<Lease> m_Leases; std::vector<Lease> m_Leases;
IdentityEx m_Identity; IdentityEx m_Identity;
uint8_t m_EncryptionKey[256]; uint8_t m_EncryptionKey[256];

18
NetDb.cpp

@ -252,12 +252,24 @@ namespace data
if (it != m_LeaseSets.end ()) if (it != m_LeaseSets.end ())
{ {
it->second->Update (buf, len); it->second->Update (buf, len);
LogPrint ("LeaseSet updated"); if (it->second->IsValid ())
LogPrint (eLogInfo, "LeaseSet updated");
else
{
LogPrint (eLogInfo, "LeaseSet update failed");
m_LeaseSets.erase (it);
}
} }
else else
{ {
LogPrint ("New LeaseSet added"); auto leaseSet = std::make_shared<LeaseSet> (buf, len);
m_LeaseSets[ident] = std::make_shared<LeaseSet> (buf, len); if (leaseSet->IsValid ())
{
LogPrint (eLogInfo, "New LeaseSet added");
m_LeaseSets[ident] = leaseSet;
}
else
LogPrint (eLogError, "New LeaseSet validation failed");
} }
} }
} }

Loading…
Cancel
Save