mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-04 06:00:37 +00:00
save new session with NSR tagset
This commit is contained in:
parent
438a225487
commit
4ae41513ac
@ -150,7 +150,8 @@ namespace garlic
|
|||||||
uint8_t tagsetKey[32];
|
uint8_t tagsetKey[32];
|
||||||
i2p::crypto::HKDF (m_CK, nullptr, 0, "SessionReplyTags", tagsetKey, 32); // tagsetKey = HKDF(chainKey, ZEROLEN, "SessionReplyTags", 32)
|
i2p::crypto::HKDF (m_CK, nullptr, 0, "SessionReplyTags", tagsetKey, 32); // tagsetKey = HKDF(chainKey, ZEROLEN, "SessionReplyTags", 32)
|
||||||
// Session Tag Ratchet
|
// Session Tag Ratchet
|
||||||
auto tagsetNsr = std::make_shared<RatchetTagSet>(shared_from_this ());
|
auto tagsetNsr = (m_State == eSessionStateNewSessionReceived) ? std::make_shared<RatchetTagSet>(shared_from_this ()):
|
||||||
|
std::make_shared<NSRatchetTagSet>(shared_from_this ());
|
||||||
tagsetNsr->DHInitialize (m_CK, tagsetKey); // tagset_nsr = DH_INITIALIZE(chainKey, tagsetKey)
|
tagsetNsr->DHInitialize (m_CK, tagsetKey); // tagset_nsr = DH_INITIALIZE(chainKey, tagsetKey)
|
||||||
tagsetNsr->NextSessionTagRatchet ();
|
tagsetNsr->NextSessionTagRatchet ();
|
||||||
return tagsetNsr;
|
return tagsetNsr;
|
||||||
@ -416,8 +417,8 @@ namespace garlic
|
|||||||
bool ECIESX25519AEADRatchetSession::NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen)
|
bool ECIESX25519AEADRatchetSession::NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen)
|
||||||
{
|
{
|
||||||
// we are Bob
|
// we are Bob
|
||||||
m_NSRTagset = CreateNewSessionTagset ();
|
m_NSRSendTagset = CreateNewSessionTagset ();
|
||||||
uint64_t tag = m_NSRTagset->GetNextSessionTag ();
|
uint64_t tag = m_NSRSendTagset->GetNextSessionTag ();
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
memcpy (out + offset, &tag, 8);
|
memcpy (out + offset, &tag, 8);
|
||||||
@ -475,7 +476,7 @@ namespace garlic
|
|||||||
bool ECIESX25519AEADRatchetSession::NextNewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen)
|
bool ECIESX25519AEADRatchetSession::NextNewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen)
|
||||||
{
|
{
|
||||||
// we are Bob and sent NSR already
|
// we are Bob and sent NSR already
|
||||||
uint64_t tag = m_NSRTagset->GetNextSessionTag (); // next tag
|
uint64_t tag = m_NSRSendTagset->GetNextSessionTag (); // next tag
|
||||||
memcpy (out, &tag, 8);
|
memcpy (out, &tag, 8);
|
||||||
memcpy (out + 8, m_NSREncodedKey, 32);
|
memcpy (out + 8, m_NSREncodedKey, 32);
|
||||||
// recalculate h with new tag
|
// recalculate h with new tag
|
||||||
@ -625,7 +626,7 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
case eSessionStateNewSessionReplySent:
|
case eSessionStateNewSessionReplySent:
|
||||||
m_State = eSessionStateEstablished;
|
m_State = eSessionStateEstablished;
|
||||||
m_NSRTagset = nullptr;
|
m_NSRSendTagset = nullptr;
|
||||||
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
#endif
|
#endif
|
||||||
|
@ -79,6 +79,18 @@ namespace garlic
|
|||||||
uint64_t m_ExpirationTimestamp = 0;
|
uint64_t m_ExpirationTimestamp = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NSRatchetTagSet: public RatchetTagSet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
NSRatchetTagSet (std::shared_ptr<ECIESX25519AEADRatchetSession> session):
|
||||||
|
RatchetTagSet (session), m_DummySession (session) {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::shared_ptr<ECIESX25519AEADRatchetSession> m_DummySession; // we need a strong pointer for NS
|
||||||
|
};
|
||||||
|
|
||||||
enum ECIESx25519BlockType
|
enum ECIESx25519BlockType
|
||||||
{
|
{
|
||||||
eECIESx25519BlkDateTime = 0,
|
eECIESx25519BlkDateTime = 0,
|
||||||
@ -171,7 +183,7 @@ namespace garlic
|
|||||||
i2p::crypto::X25519Keys m_EphemeralKeys;
|
i2p::crypto::X25519Keys m_EphemeralKeys;
|
||||||
SessionState m_State = eSessionStateNew;
|
SessionState m_State = eSessionStateNew;
|
||||||
uint64_t m_SessionCreatedTimestamp = 0, m_LastActivityTimestamp = 0; // incoming
|
uint64_t m_SessionCreatedTimestamp = 0, m_LastActivityTimestamp = 0; // incoming
|
||||||
std::shared_ptr<RatchetTagSet> m_SendTagset, m_NSRTagset;
|
std::shared_ptr<RatchetTagSet> m_SendTagset, m_NSRSendTagset;
|
||||||
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
|
||||||
std::list<std::pair<uint16_t, int> > m_AckRequests; // (tagsetid, index)
|
std::list<std::pair<uint16_t, int> > m_AckRequests; // (tagsetid, index)
|
||||||
bool m_SendReverseKey = false, m_SendForwardKey = false;
|
bool m_SendReverseKey = false, m_SendForwardKey = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user