mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 00:34:20 +00:00
delete expired ECIESX25519AEADRatchet sessions and tags
This commit is contained in:
parent
50450923df
commit
9c9b723cf5
@ -401,6 +401,7 @@ namespace garlic
|
|||||||
|
|
||||||
bool ECIESX25519AEADRatchetSession::HandleNextMessage (const uint8_t * buf, size_t len, int index)
|
bool ECIESX25519AEADRatchetSession::HandleNextMessage (const uint8_t * buf, size_t len, int index)
|
||||||
{
|
{
|
||||||
|
m_LastActivityTimestamp = i2p::util::GetSecondsSinceEpoch ();
|
||||||
switch (m_State)
|
switch (m_State)
|
||||||
{
|
{
|
||||||
case eSessionStateEstablished:
|
case eSessionStateEstablished:
|
||||||
|
@ -55,6 +55,10 @@ namespace garlic
|
|||||||
eECIESx25519BlkPadding = 254
|
eECIESx25519BlkPadding = 254
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const int ECIESX25519_RESTART_TIMEOUT = 120; // number of second of inactivity we should restart after
|
||||||
|
const int ECIESX25519_EXPIRATION_TIMEOUT = 600; // in seconds
|
||||||
|
|
||||||
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession, public std::enable_shared_from_this<ECIESX25519AEADRatchetSession>
|
class ECIESX25519AEADRatchetSession: public GarlicRoutingSession, public std::enable_shared_from_this<ECIESX25519AEADRatchetSession>
|
||||||
{
|
{
|
||||||
enum SessionState
|
enum SessionState
|
||||||
@ -81,6 +85,9 @@ namespace garlic
|
|||||||
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
|
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsExpired (uint64_t ts) const { return ts > m_LastActivityTimestamp + ECIESX25519_EXPIRATION_TIMEOUT; }
|
||||||
|
bool CanBeRestarted (uint64_t ts) const { return ts > m_LastActivityTimestamp + ECIESX25519_RESTART_TIMEOUT; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ResetKeys ();
|
void ResetKeys ();
|
||||||
@ -109,6 +116,7 @@ namespace garlic
|
|||||||
uint8_t m_Aepk[32]; // Alice's ephemeral keys TODO: for incoming only
|
uint8_t m_Aepk[32]; // Alice's ephemeral keys TODO: for incoming only
|
||||||
i2p::crypto::X25519Keys m_EphemeralKeys;
|
i2p::crypto::X25519Keys m_EphemeralKeys;
|
||||||
SessionState m_State = eSessionStateNew;
|
SessionState m_State = eSessionStateNew;
|
||||||
|
uint64_t m_LastActivityTimestamp = 0; // incoming
|
||||||
RatchetTagSet m_SendTagset, m_ReceiveTagset;
|
RatchetTagSet m_SendTagset, m_ReceiveTagset;
|
||||||
int m_NumReceiveTags = 0;
|
int m_NumReceiveTags = 0;
|
||||||
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
||||||
|
@ -739,7 +739,25 @@ namespace garlic
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: cleanup ECIESx25519
|
// ECIESx25519
|
||||||
|
for (auto it = m_ECIESx25519Tags.begin (); it != m_ECIESx25519Tags.end ();)
|
||||||
|
{
|
||||||
|
if (ts > it->second.creationTime + INCOMING_TAGS_EXPIRATION_TIMEOUT)
|
||||||
|
it = m_ECIESx25519Tags.erase (it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = m_ECIESx25519Sessions.begin (); it != m_ECIESx25519Sessions.end ();)
|
||||||
|
{
|
||||||
|
if (it->second->IsExpired (ts))
|
||||||
|
{
|
||||||
|
it->second->SetOwner (nullptr);
|
||||||
|
it = m_ECIESx25519Sessions.erase (it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
||||||
@ -940,12 +958,24 @@ namespace garlic
|
|||||||
|
|
||||||
void GarlicDestination::AddECIESx25519SessionTag (int index, uint64_t tag, ECIESX25519AEADRatchetSessionPtr session)
|
void GarlicDestination::AddECIESx25519SessionTag (int index, uint64_t tag, ECIESX25519AEADRatchetSessionPtr session)
|
||||||
{
|
{
|
||||||
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexSession{index, session});
|
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexSession{index, session, i2p::util::GetSecondsSinceEpoch ()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarlicDestination::AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session)
|
void GarlicDestination::AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session)
|
||||||
{
|
{
|
||||||
m_ECIESx25519Sessions.emplace (staticKey, session);
|
i2p::data::Tag<32> staticKeyTag (staticKey);
|
||||||
|
auto it = m_ECIESx25519Sessions.find (staticKeyTag);
|
||||||
|
if (it != m_ECIESx25519Sessions.end ())
|
||||||
|
{
|
||||||
|
if (it->second->CanBeRestarted (i2p::util::GetSecondsSinceEpoch ()))
|
||||||
|
m_ECIESx25519Sessions.erase (it);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogInfo, "Garlic: ECIESx25519 session with static key ", staticKeyTag.ToBase64 (), " already exists");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_ECIESx25519Sessions.emplace (staticKeyTag, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,7 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
ECIESX25519AEADRatchetSessionPtr session;
|
ECIESX25519AEADRatchetSessionPtr session;
|
||||||
|
uint64_t creationTime; // seconds since epoch
|
||||||
};
|
};
|
||||||
|
|
||||||
class GarlicDestination: public i2p::data::LocalDestination
|
class GarlicDestination: public i2p::data::LocalDestination
|
||||||
|
Loading…
x
Reference in New Issue
Block a user