mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
handle next key forward
This commit is contained in:
parent
ec29597dbd
commit
30067fc7d7
3 changed files with 96 additions and 35 deletions
|
@ -27,10 +27,13 @@ namespace garlic
|
|||
void DHInitialize (const uint8_t * rootKey, const uint8_t * k);
|
||||
void NextSessionTagRatchet ();
|
||||
uint64_t GetNextSessionTag ();
|
||||
const uint8_t * GetNextRootKey () const { return m_NextRootKey; };
|
||||
int GetNextIndex () const { return m_NextIndex; };
|
||||
void GetSymmKey (int index, uint8_t * key);
|
||||
|
||||
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session.lock (); };
|
||||
int GetTagSetID () const { return m_TagSetID; };
|
||||
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
|
||||
|
||||
private:
|
||||
|
||||
|
@ -44,10 +47,11 @@ namespace garlic
|
|||
uint64_t GetTag () const { return ll[4]; }; // tag = keydata[32:39]
|
||||
|
||||
} m_KeyData;
|
||||
uint8_t m_SessTagConstant[32], m_SymmKeyCK[32], m_CurrentSymmKeyCK[64];
|
||||
uint8_t m_SessTagConstant[32], m_SymmKeyCK[32], m_CurrentSymmKeyCK[64], m_NextRootKey[32];
|
||||
int m_NextIndex, m_NextSymmKeyIndex;
|
||||
std::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
|
||||
std::weak_ptr<ECIESX25519AEADRatchetSession> m_Session;
|
||||
int m_TagSetID = 0;
|
||||
};
|
||||
|
||||
enum ECIESx25519BlockType
|
||||
|
@ -56,14 +60,17 @@ namespace garlic
|
|||
eECIESx25519BlkSessionID = 1,
|
||||
eECIESx25519BlkTermination = 4,
|
||||
eECIESx25519BlkOptions = 5,
|
||||
eECIESx25519BlkNextSessionKey = 7,
|
||||
eECIESx25519BlkNextKey = 7,
|
||||
eECIESx25519BlkAck = 8,
|
||||
eECIESx25519BlkAckRequest = 9,
|
||||
eECIESx25519BlkGalicClove = 11,
|
||||
eECIESx25519BlkPadding = 254
|
||||
};
|
||||
|
||||
|
||||
const uint8_t ECIESX25519_NEXT_KEY_KEY_PRESENT_FLAG = 0x01;
|
||||
const uint8_t ECIESX25519_NEXT_KEY_REVERSE_KEY_FLAG = 0x02;
|
||||
const uint8_t ECIESX25519_NEXT_KEY_REQUEST_REVERSE_KEY_FLAG = 0x04;
|
||||
|
||||
const int ECIESX25519_RESTART_TIMEOUT = 120; // number of second of inactivity we should restart after
|
||||
const int ECIESX25519_EXPIRATION_TIMEOUT = 600; // in seconds
|
||||
|
||||
|
@ -83,7 +90,7 @@ namespace garlic
|
|||
ECIESX25519AEADRatchetSession (GarlicDestination * owner, bool attachLeaseSet);
|
||||
~ECIESX25519AEADRatchetSession ();
|
||||
|
||||
bool HandleNextMessage (const uint8_t * buf, size_t len, int index = 0);
|
||||
bool HandleNextMessage (const uint8_t * buf, size_t len, std::shared_ptr<RatchetTagSet> receiveTagset, int index = 0);
|
||||
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg);
|
||||
|
||||
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
||||
|
@ -107,9 +114,10 @@ namespace garlic
|
|||
|
||||
bool HandleNewIncomingSession (const uint8_t * buf, size_t len);
|
||||
bool HandleNewOutgoingSessionReply (const uint8_t * buf, size_t len);
|
||||
bool HandleExistingSessionMessage (const uint8_t * buf, size_t len, int index);
|
||||
void HandlePayload (const uint8_t * buf, size_t len, int index = 0);
|
||||
|
||||
bool HandleExistingSessionMessage (const uint8_t * buf, size_t len, std::shared_ptr<RatchetTagSet> receiveTagset, int index);
|
||||
void HandlePayload (const uint8_t * buf, size_t len, const std::shared_ptr<RatchetTagSet>& receiveTagset, int index);
|
||||
void HandleNextKey (const uint8_t * buf, size_t len, const std::shared_ptr<RatchetTagSet>& receiveTagset);
|
||||
|
||||
bool NewOutgoingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
||||
bool NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
||||
bool NextNewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
||||
|
@ -119,7 +127,7 @@ namespace garlic
|
|||
size_t CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len, bool isDestination = false);
|
||||
size_t CreateDeliveryStatusClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len);
|
||||
|
||||
void GenerateMoreReceiveTags (int numTags);
|
||||
void GenerateMoreReceiveTags (std::shared_ptr<RatchetTagSet> receiveTagset, int numTags);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -129,10 +137,12 @@ namespace garlic
|
|||
i2p::crypto::X25519Keys m_EphemeralKeys;
|
||||
SessionState m_State = eSessionStateNew;
|
||||
uint64_t m_LastActivityTimestamp = 0; // incoming
|
||||
std::shared_ptr<RatchetTagSet> m_SendTagset, m_ReceiveTagset;
|
||||
std::shared_ptr<RatchetTagSet> m_SendTagset;
|
||||
int m_SendKeyID = 0, m_ReceiveKeyID = 0;
|
||||
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
||||
std::list<std::pair<uint16_t, int> > m_AckRequests; // (tagsetid, index)
|
||||
};
|
||||
std::list<std::pair<uint16_t, i2p::data::Tag<32> > > m_ReverseKeys; // (keyid, public key)
|
||||
};
|
||||
|
||||
std::shared_ptr<I2NPMessage> WrapECIESX25519AEADRatchetMessage (std::shared_ptr<const I2NPMessage> msg, const uint8_t * key, uint64_t tag);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue