mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-30 20:24:15 +00:00
LS2 signature verification and store type
This commit is contained in:
parent
12af68bdb5
commit
6193b06708
@ -264,7 +264,7 @@ namespace i2p
|
||||
auto m = NewI2NPShortMessage ();
|
||||
uint8_t * payload = m->GetPayload ();
|
||||
memcpy (payload + DATABASE_STORE_KEY_OFFSET, leaseSet->GetIdentHash (), 32);
|
||||
payload[DATABASE_STORE_TYPE_OFFSET] = 1; // LeaseSet
|
||||
payload[DATABASE_STORE_TYPE_OFFSET] = leaseSet->GetStoreType (); // 1 for LeaseSet
|
||||
htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, 0);
|
||||
size_t size = DATABASE_STORE_HEADER_SIZE;
|
||||
memcpy (payload + size, leaseSet->GetBuffer (), leaseSet->GetBufferLen ());
|
||||
|
@ -228,21 +228,51 @@ namespace data
|
||||
memcpy (m_Buffer, buf, len);
|
||||
}
|
||||
|
||||
LeaseSet2::LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len)
|
||||
{
|
||||
LeaseSet2::LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len):
|
||||
m_StoreType (storeType)
|
||||
{
|
||||
SetBuffer (buf, len);
|
||||
ReadFromBuffer (storeType, buf, len);
|
||||
ReadFromBuffer (buf, len);
|
||||
}
|
||||
|
||||
void LeaseSet2::ReadFromBuffer (uint8_t storeType, const uint8_t * buf, size_t len)
|
||||
void LeaseSet2::ReadFromBuffer (const uint8_t * buf, size_t len)
|
||||
{
|
||||
auto identity = std::make_shared<IdentityEx>(buf, len);
|
||||
SetIdentity (identity);
|
||||
size_t offset = identity->GetFullLen ();
|
||||
if (offset + 10 >= len) return;
|
||||
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4; // published timestamp (seconds)
|
||||
uint16_t expires = bufbe16toh (buf + offset); offset += 2; // expires (seconds)
|
||||
SetExpirationTime ((timestamp + expires)*1000LL); // in milliseconds
|
||||
SetIsValid (true); // TODO:: verify signature
|
||||
offset += 2; // flags
|
||||
// properties
|
||||
uint16_t propertiesLen = bufbe16toh (buf + offset); offset += 2;
|
||||
offset += propertiesLen; // skip for now. TODO: implement properties
|
||||
if (offset + 1 >= len) return;
|
||||
// key sections
|
||||
int numKeySections = buf[offset]; offset++;
|
||||
for (int i = 0; i < numKeySections; i++)
|
||||
{
|
||||
// skip key for now. TODO: implement encryption key
|
||||
offset += 2; // encryption key type
|
||||
if (offset + 2 >= len) return;
|
||||
uint16_t encryptionKeyLen = bufbe16toh (buf + offset); offset += 2;
|
||||
offset += encryptionKeyLen;
|
||||
if (offset >= len) return;
|
||||
}
|
||||
// leases
|
||||
int numLeases = buf[offset]; offset++;
|
||||
offset += numLeases*40; // 40 bytes each
|
||||
// verify signature
|
||||
if (offset + identity->GetSignatureLen () > len) return;
|
||||
uint8_t * buf1 = new uint8_t[offset + 1];
|
||||
buf1[0] = m_StoreType;
|
||||
memcpy (buf1 + 1, buf, offset); // TODO: implement it better
|
||||
bool verified = identity->Verify (buf1, offset + 1, buf + offset); // assume online keys
|
||||
delete[] buf1;
|
||||
if (!verified)
|
||||
LogPrint (eLogWarning, "LeaseSet2: verification failed");
|
||||
SetIsValid (verified);
|
||||
}
|
||||
|
||||
LocalLeaseSet::LocalLeaseSet (std::shared_ptr<const IdentityEx> identity, const uint8_t * encryptionPublicKey, std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels):
|
||||
|
@ -56,7 +56,7 @@ namespace data
|
||||
public:
|
||||
|
||||
LeaseSet (const uint8_t * buf, size_t len, bool storeLeases = true);
|
||||
~LeaseSet () { delete[] m_Buffer; };
|
||||
virtual ~LeaseSet () { delete[] m_Buffer; };
|
||||
void Update (const uint8_t * buf, size_t len, bool verifySignature = true);
|
||||
bool IsNewer (const uint8_t * buf, size_t len) const;
|
||||
void PopulateLeases (); // from buffer
|
||||
@ -73,7 +73,8 @@ namespace data
|
||||
bool ExpiresSoon(const uint64_t dlt=1000 * 5, const uint64_t fudge = 0) const ;
|
||||
bool operator== (const LeaseSet& other) const
|
||||
{ return m_BufferLen == other.m_BufferLen && !memcmp (m_Buffer, other.m_Buffer, m_BufferLen); };
|
||||
|
||||
virtual uint8_t GetStoreType () const { return 1; };
|
||||
|
||||
// implements RoutingDestination
|
||||
std::shared_ptr<const IdentityEx> GetIdentity () const { return m_Identity; };
|
||||
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;
|
||||
@ -115,10 +116,15 @@ namespace data
|
||||
public:
|
||||
|
||||
LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len);
|
||||
uint8_t GetStoreType () const { return m_StoreType; };
|
||||
|
||||
private:
|
||||
|
||||
void ReadFromBuffer (uint8_t storeType, const uint8_t * buf, size_t len);
|
||||
void ReadFromBuffer (const uint8_t * buf, size_t len);
|
||||
|
||||
private:
|
||||
|
||||
uint8_t m_StoreType;
|
||||
};
|
||||
|
||||
class LocalLeaseSet
|
||||
|
Loading…
x
Reference in New Issue
Block a user