mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
correct timestamp check for LeaseSet2
This commit is contained in:
parent
16b992d705
commit
627d8cfe69
@ -149,20 +149,13 @@ namespace data
|
||||
auto ret = m_Leases.insert (std::make_shared<Lease>(lease));
|
||||
if (!ret.second) (*ret.first)->endDate = lease.endDate; // update existing
|
||||
(*ret.first)->isUpdated = true;
|
||||
// check if lease's gateway is in our netDb
|
||||
if (!netdb.FindRouter (lease.tunnelGateway))
|
||||
{
|
||||
// if not found request it
|
||||
LogPrint (eLogInfo, "LeaseSet: Lease's tunnel gateway not found, requesting");
|
||||
netdb.RequestDestination (lease.tunnelGateway);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "LeaseSet: Lease is expired already");
|
||||
}
|
||||
|
||||
uint64_t LeaseSet::ExtractTimestamp (const uint8_t * buf, size_t len) const
|
||||
uint64_t LeaseSet::ExtractExpirationTimestamp (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
if (!m_Identity) return 0;
|
||||
size_t size = m_Identity->GetFullLen ();
|
||||
@ -187,7 +180,7 @@ namespace data
|
||||
|
||||
bool LeaseSet::IsNewer (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
return ExtractTimestamp (buf, len) > ExtractTimestamp (m_Buffer, m_BufferLen);
|
||||
return ExtractExpirationTimestamp (buf, len) > (m_ExpirationTime ? m_ExpirationTime : ExtractExpirationTimestamp (m_Buffer, m_BufferLen));
|
||||
}
|
||||
|
||||
bool LeaseSet::ExpiresSoon(const uint64_t dlt, const uint64_t fudge) const
|
||||
@ -282,6 +275,12 @@ namespace data
|
||||
ReadFromBuffer (buf, len, false, verifySignature);
|
||||
// TODO: implement encrypted
|
||||
}
|
||||
|
||||
bool LeaseSet2::IsNewer (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
uint64_t expiration;
|
||||
return ExtractPublishedTimestamp (buf, len, expiration) > m_PublishedTimestamp;
|
||||
}
|
||||
|
||||
void LeaseSet2::ReadFromBuffer (const uint8_t * buf, size_t len, bool readIdentity, bool verifySignature)
|
||||
{
|
||||
@ -640,7 +639,14 @@ namespace data
|
||||
encryptor->Encrypt (data, encrypted, ctx, true);
|
||||
}
|
||||
|
||||
uint64_t LeaseSet2::ExtractTimestamp (const uint8_t * buf, size_t len) const
|
||||
uint64_t LeaseSet2::ExtractExpirationTimestamp (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
uint64_t expiration = 0;
|
||||
ExtractPublishedTimestamp (buf, len, expiration);
|
||||
return expiration;
|
||||
}
|
||||
|
||||
uint64_t LeaseSet2::ExtractPublishedTimestamp (const uint8_t * buf, size_t len, uint64_t& expiration) const
|
||||
{
|
||||
if (len < 8) return 0;
|
||||
if (m_StoreType == NETDB_STORE_TYPE_ENCRYPTED_LEASESET2)
|
||||
@ -655,7 +661,8 @@ namespace data
|
||||
offset += blindedKeyLen;
|
||||
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4;
|
||||
uint16_t expires = bufbe16toh (buf + offset); offset += 2;
|
||||
return (timestamp + expires)* 1000LL;
|
||||
expiration = (timestamp + expires)* 1000LL;
|
||||
return timestamp;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -665,10 +672,11 @@ namespace data
|
||||
if (offset + 6 >= len) return 0;
|
||||
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4;
|
||||
uint16_t expires = bufbe16toh (buf + offset); offset += 2;
|
||||
return (timestamp + expires)* 1000LL;
|
||||
expiration = (timestamp + expires)* 1000LL;
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LocalLeaseSet::LocalLeaseSet (std::shared_ptr<const IdentityEx> identity, const uint8_t * encryptionPublicKey, std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels):
|
||||
m_ExpirationTime (0), m_Identity (identity)
|
||||
{
|
||||
|
@ -63,14 +63,14 @@ namespace data
|
||||
LeaseSet (const uint8_t * buf, size_t len, bool storeLeases = true);
|
||||
virtual ~LeaseSet () { delete[] m_EncryptionKey; delete[] m_Buffer; };
|
||||
virtual void Update (const uint8_t * buf, size_t len, bool verifySignature = true);
|
||||
bool IsNewer (const uint8_t * buf, size_t len) const;
|
||||
virtual bool IsNewer (const uint8_t * buf, size_t len) const;
|
||||
void PopulateLeases (); // from buffer
|
||||
|
||||
const uint8_t * GetBuffer () const { return m_Buffer; };
|
||||
size_t GetBufferLen () const { return m_BufferLen; };
|
||||
bool IsValid () const { return m_IsValid; };
|
||||
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;
|
||||
const std::vector<std::shared_ptr<const Lease> > GetNonExpiredLeasesExcluding (LeaseInspectFunc exclude, bool withThreshold = true) const;
|
||||
bool HasExpiredLeases () const;
|
||||
bool IsExpired () const;
|
||||
bool IsEmpty () const { return m_Leases.empty (); };
|
||||
@ -106,7 +106,7 @@ namespace data
|
||||
private:
|
||||
|
||||
void ReadFromBuffer (bool readIdentity = true, bool verifySignature = true);
|
||||
virtual uint64_t ExtractTimestamp (const uint8_t * buf, size_t len) const; // returns max expiration time
|
||||
virtual uint64_t ExtractExpirationTimestamp (const uint8_t * buf, size_t len) const; // returns max expiration time
|
||||
|
||||
private:
|
||||
|
||||
@ -145,6 +145,7 @@ namespace data
|
||||
bool IsPublishedEncrypted () const { return m_IsPublishedEncrypted; };
|
||||
std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return m_TransientVerifier; };
|
||||
void Update (const uint8_t * buf, size_t len, bool verifySignature);
|
||||
bool IsNewer (const uint8_t * buf, size_t len) const;
|
||||
|
||||
// implements RoutingDestination
|
||||
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;
|
||||
@ -160,7 +161,8 @@ namespace data
|
||||
template<typename Verifier>
|
||||
bool VerifySignature (Verifier& verifier, const uint8_t * buf, size_t len, size_t signatureOffset);
|
||||
|
||||
uint64_t ExtractTimestamp (const uint8_t * buf, size_t len) const;
|
||||
uint64_t ExtractExpirationTimestamp (const uint8_t * buf, size_t len) const;
|
||||
uint64_t ExtractPublishedTimestamp (const uint8_t * buf, size_t len, uint64_t& expiration) const;
|
||||
size_t ExtractClientAuthData (const uint8_t * buf, size_t len, const uint8_t * secret, const uint8_t * subcredential, uint8_t * authCookie) const; // subcredential is subcredential + timestamp, return length of autData without flag
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user