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));
|
auto ret = m_Leases.insert (std::make_shared<Lease>(lease));
|
||||||
if (!ret.second) (*ret.first)->endDate = lease.endDate; // update existing
|
if (!ret.second) (*ret.first)->endDate = lease.endDate; // update existing
|
||||||
(*ret.first)->isUpdated = true;
|
(*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
|
else
|
||||||
LogPrint (eLogWarning, "LeaseSet: Lease is expired already");
|
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;
|
if (!m_Identity) return 0;
|
||||||
size_t size = m_Identity->GetFullLen ();
|
size_t size = m_Identity->GetFullLen ();
|
||||||
@ -187,7 +180,7 @@ namespace data
|
|||||||
|
|
||||||
bool LeaseSet::IsNewer (const uint8_t * buf, size_t len) const
|
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
|
bool LeaseSet::ExpiresSoon(const uint64_t dlt, const uint64_t fudge) const
|
||||||
@ -283,6 +276,12 @@ namespace data
|
|||||||
// TODO: implement encrypted
|
// 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)
|
void LeaseSet2::ReadFromBuffer (const uint8_t * buf, size_t len, bool readIdentity, bool verifySignature)
|
||||||
{
|
{
|
||||||
// standard LS2 header
|
// standard LS2 header
|
||||||
@ -640,7 +639,14 @@ namespace data
|
|||||||
encryptor->Encrypt (data, encrypted, ctx, true);
|
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 (len < 8) return 0;
|
||||||
if (m_StoreType == NETDB_STORE_TYPE_ENCRYPTED_LEASESET2)
|
if (m_StoreType == NETDB_STORE_TYPE_ENCRYPTED_LEASESET2)
|
||||||
@ -655,7 +661,8 @@ namespace data
|
|||||||
offset += blindedKeyLen;
|
offset += blindedKeyLen;
|
||||||
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4;
|
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4;
|
||||||
uint16_t expires = bufbe16toh (buf + offset); offset += 2;
|
uint16_t expires = bufbe16toh (buf + offset); offset += 2;
|
||||||
return (timestamp + expires)* 1000LL;
|
expiration = (timestamp + expires)* 1000LL;
|
||||||
|
return timestamp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -665,7 +672,8 @@ namespace data
|
|||||||
if (offset + 6 >= len) return 0;
|
if (offset + 6 >= len) return 0;
|
||||||
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4;
|
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4;
|
||||||
uint16_t expires = bufbe16toh (buf + offset); offset += 2;
|
uint16_t expires = bufbe16toh (buf + offset); offset += 2;
|
||||||
return (timestamp + expires)* 1000LL;
|
expiration = (timestamp + expires)* 1000LL;
|
||||||
|
return timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace data
|
|||||||
LeaseSet (const uint8_t * buf, size_t len, bool storeLeases = true);
|
LeaseSet (const uint8_t * buf, size_t len, bool storeLeases = true);
|
||||||
virtual ~LeaseSet () { delete[] m_EncryptionKey; delete[] m_Buffer; };
|
virtual ~LeaseSet () { delete[] m_EncryptionKey; delete[] m_Buffer; };
|
||||||
virtual void Update (const uint8_t * buf, size_t len, bool verifySignature = true);
|
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
|
void PopulateLeases (); // from buffer
|
||||||
|
|
||||||
const uint8_t * GetBuffer () const { return m_Buffer; };
|
const uint8_t * GetBuffer () const { return m_Buffer; };
|
||||||
@ -106,7 +106,7 @@ namespace data
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void ReadFromBuffer (bool readIdentity = true, bool verifySignature = true);
|
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:
|
private:
|
||||||
|
|
||||||
@ -145,6 +145,7 @@ namespace data
|
|||||||
bool IsPublishedEncrypted () const { return m_IsPublishedEncrypted; };
|
bool IsPublishedEncrypted () const { return m_IsPublishedEncrypted; };
|
||||||
std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return m_TransientVerifier; };
|
std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return m_TransientVerifier; };
|
||||||
void Update (const uint8_t * buf, size_t len, bool verifySignature);
|
void Update (const uint8_t * buf, size_t len, bool verifySignature);
|
||||||
|
bool IsNewer (const uint8_t * buf, size_t len) const;
|
||||||
|
|
||||||
// implements RoutingDestination
|
// implements RoutingDestination
|
||||||
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;
|
||||||
@ -160,7 +161,8 @@ namespace data
|
|||||||
template<typename Verifier>
|
template<typename Verifier>
|
||||||
bool VerifySignature (Verifier& verifier, const uint8_t * buf, size_t len, size_t signatureOffset);
|
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
|
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:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user