|
|
|
@ -265,5 +265,39 @@ namespace data
@@ -265,5 +265,39 @@ namespace data
|
|
|
|
|
auto ts = i2p::util::GetMillisecondsSinceEpoch (); |
|
|
|
|
return ts > m_ExpirationTime; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool LeaseSetBufferValidate(const uint8_t * ptr, size_t sz, uint64_t & expires) |
|
|
|
|
{ |
|
|
|
|
IdentityEx ident(ptr, sz); |
|
|
|
|
size_t size = ident.GetFullLen (); |
|
|
|
|
if (size > sz) |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "LeaseSet: identity length ", size, " exceeds buffer size ", sz); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
// encryption key
|
|
|
|
|
size += 256; |
|
|
|
|
// signing key (unused)
|
|
|
|
|
size += ident.GetSigningPublicKeyLen (); |
|
|
|
|
uint8_t numLeases = ptr[size]; |
|
|
|
|
++size; |
|
|
|
|
if (!numLeases || numLeases > MAX_NUM_LEASES) |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "LeaseSet: incorrect number of leases", (int)numLeases); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
const uint8_t * leases = ptr + size; |
|
|
|
|
expires = 0; |
|
|
|
|
/** find lease with the max expiration timestamp */ |
|
|
|
|
for (int i = 0; i < numLeases; i++) |
|
|
|
|
{ |
|
|
|
|
leases += 36; // gateway + tunnel ID
|
|
|
|
|
uint64_t endDate = bufbe64toh (leases); |
|
|
|
|
leases += 8; // end date
|
|
|
|
|
if(endDate > expires) |
|
|
|
|
expires = endDate; |
|
|
|
|
} |
|
|
|
|
return ident.Verify(ptr, leases - ptr, leases); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|