mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-22 00:59:08 +01:00
handle Ack request
This commit is contained in:
parent
744e893dce
commit
869d0156ce
2 changed files with 28 additions and 3 deletions
|
@ -38,6 +38,7 @@ namespace garlic
|
||||||
{
|
{
|
||||||
i2p::crypto::HKDF (m_KeyData.GetSessTagCK (), m_SessTagConstant, 32, "SessionTagKeyGen", m_KeyData.buf); // [sessTag_ck, tag] = HKDF(sessTag_chainkey, SESSTAG_CONSTANT, "SessionTagKeyGen", 64)
|
i2p::crypto::HKDF (m_KeyData.GetSessTagCK (), m_SessTagConstant, 32, "SessionTagKeyGen", m_KeyData.buf); // [sessTag_ck, tag] = HKDF(sessTag_chainkey, SESSTAG_CONSTANT, "SessionTagKeyGen", 64)
|
||||||
m_NextIndex++;
|
m_NextIndex++;
|
||||||
|
if (m_NextIndex >= 65535) m_NextIndex = 0; // TODO: dirty hack, should create new tagset
|
||||||
return m_KeyData.GetTag ();
|
return m_KeyData.GetTag ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ namespace garlic
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ECIESX25519AEADRatchetSession::HandlePayload (const uint8_t * buf, size_t len)
|
void ECIESX25519AEADRatchetSession::HandlePayload (const uint8_t * buf, size_t len, int index)
|
||||||
{
|
{
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
while (offset < len)
|
while (offset < len)
|
||||||
|
@ -207,6 +208,12 @@ namespace garlic
|
||||||
case eECIESx25519BlkPadding:
|
case eECIESx25519BlkPadding:
|
||||||
LogPrint (eLogDebug, "Garlic: padding");
|
LogPrint (eLogDebug, "Garlic: padding");
|
||||||
break;
|
break;
|
||||||
|
case eECIESx25519BlkAckRequest:
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "Garlic: ack request");
|
||||||
|
m_AckRequests.push_back ( {bufbe16toh (buf + offset), index});
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LogPrint (eLogWarning, "Garlic: Unknown block type ", (int)blk);
|
LogPrint (eLogWarning, "Garlic: Unknown block type ", (int)blk);
|
||||||
}
|
}
|
||||||
|
@ -401,7 +408,7 @@ namespace garlic
|
||||||
LogPrint (eLogWarning, "Garlic: Payload section AEAD decryption failed");
|
LogPrint (eLogWarning, "Garlic: Payload section AEAD decryption failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HandlePayload (payload.data (), len - 16);
|
HandlePayload (payload.data (), len - 16, index);
|
||||||
if (m_ReceiveTagset.GetNextIndex () - index <= GetOwner ()->GetNumTags ()*2/3)
|
if (m_ReceiveTagset.GetNextIndex () - index <= GetOwner ()->GetNumTags ()*2/3)
|
||||||
GenerateMoreReceiveTags (GetOwner ()->GetNumTags ());
|
GenerateMoreReceiveTags (GetOwner ()->GetNumTags ());
|
||||||
return true;
|
return true;
|
||||||
|
@ -478,6 +485,8 @@ namespace garlic
|
||||||
SetLeaseSetSubmissionTime (ts);
|
SetLeaseSetSubmissionTime (ts);
|
||||||
GetOwner ()->DeliveryStatusSent (shared_from_this (), leaseSet->GetMsgID ());
|
GetOwner ()->DeliveryStatusSent (shared_from_this (), leaseSet->GetMsgID ());
|
||||||
}
|
}
|
||||||
|
if (m_AckRequests.size () > 0)
|
||||||
|
payloadLen += m_AckRequests.size ()*4 + 3;
|
||||||
uint8_t paddingSize;
|
uint8_t paddingSize;
|
||||||
RAND_bytes (&paddingSize, 1);
|
RAND_bytes (&paddingSize, 1);
|
||||||
paddingSize &= 0x0F; paddingSize++; // 1 - 16
|
paddingSize &= 0x0F; paddingSize++; // 1 - 16
|
||||||
|
@ -497,6 +506,18 @@ namespace garlic
|
||||||
// msg
|
// msg
|
||||||
if (msg && m_Destination)
|
if (msg && m_Destination)
|
||||||
offset += CreateGarlicClove (msg, v.data () + offset, payloadLen - offset, true);
|
offset += CreateGarlicClove (msg, v.data () + offset, payloadLen - offset, true);
|
||||||
|
// ack
|
||||||
|
if (m_AckRequests.size () > 0)
|
||||||
|
{
|
||||||
|
v[offset] = eECIESx25519BlkAck; offset++;
|
||||||
|
htobe16buf (v.data () + offset, m_AckRequests.size ()*4); offset += 2;
|
||||||
|
for (auto& it: m_AckRequests)
|
||||||
|
{
|
||||||
|
htobe16buf (v.data () + offset, it.first); offset += 2;
|
||||||
|
htobe16buf (v.data () + offset, it.second); offset += 2;
|
||||||
|
}
|
||||||
|
m_AckRequests.clear ();
|
||||||
|
}
|
||||||
// padding
|
// padding
|
||||||
v[offset] = eECIESx25519BlkPadding; offset++;
|
v[offset] = eECIESx25519BlkPadding; offset++;
|
||||||
htobe16buf (v.data () + offset, paddingSize); offset += 2;
|
htobe16buf (v.data () + offset, paddingSize); offset += 2;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "Garlic.h"
|
#include "Garlic.h"
|
||||||
|
@ -51,6 +52,8 @@ namespace garlic
|
||||||
eECIESx25519BlkTermination = 4,
|
eECIESx25519BlkTermination = 4,
|
||||||
eECIESx25519BlkOptions = 5,
|
eECIESx25519BlkOptions = 5,
|
||||||
eECIESx25519BlkNextSessionKey = 7,
|
eECIESx25519BlkNextSessionKey = 7,
|
||||||
|
eECIESx25519BlkAck = 8,
|
||||||
|
eECIESx25519BlkAckRequest = 9,
|
||||||
eECIESx25519BlkGalicClove = 11,
|
eECIESx25519BlkGalicClove = 11,
|
||||||
eECIESx25519BlkPadding = 254
|
eECIESx25519BlkPadding = 254
|
||||||
};
|
};
|
||||||
|
@ -99,7 +102,7 @@ namespace garlic
|
||||||
bool HandleNewIncomingSession (const uint8_t * buf, size_t len);
|
bool HandleNewIncomingSession (const uint8_t * buf, size_t len);
|
||||||
bool HandleNewOutgoingSessionReply (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);
|
bool HandleExistingSessionMessage (const uint8_t * buf, size_t len, int index);
|
||||||
void HandlePayload (const uint8_t * buf, size_t len);
|
void HandlePayload (const uint8_t * buf, size_t len, int index = 0);
|
||||||
|
|
||||||
bool NewOutgoingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
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 NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
||||||
|
@ -120,6 +123,7 @@ namespace garlic
|
||||||
uint64_t m_LastActivityTimestamp = 0; // incoming
|
uint64_t m_LastActivityTimestamp = 0; // incoming
|
||||||
RatchetTagSet m_SendTagset, m_ReceiveTagset;
|
RatchetTagSet m_SendTagset, m_ReceiveTagset;
|
||||||
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; // (key_id, indeX)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue