mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
crypto.ratchet.inboundTags
This commit is contained in:
parent
5e0a8ed232
commit
61897ae16c
|
@ -56,6 +56,9 @@ namespace client
|
||||||
if (it != params->end ())
|
if (it != params->end ())
|
||||||
numTags = std::stoi(it->second);
|
numTags = std::stoi(it->second);
|
||||||
LogPrint (eLogInfo, "Destination: parameters for tunnel set to: ", inQty, " inbound (", inLen, " hops), ", outQty, " outbound (", outLen, " hops), ", numTags, " tags");
|
LogPrint (eLogInfo, "Destination: parameters for tunnel set to: ", inQty, " inbound (", inLen, " hops), ", outQty, " outbound (", outLen, " hops), ", numTags, " tags");
|
||||||
|
it = params->find (I2CP_PARAM_RATCHET_INBOUND_TAGS);
|
||||||
|
if (it != params->end ())
|
||||||
|
SetNumRatchetInboundTags (std::stoi(it->second));
|
||||||
it = params->find (I2CP_PARAM_EXPLICIT_PEERS);
|
it = params->find (I2CP_PARAM_EXPLICIT_PEERS);
|
||||||
if (it != params->end ())
|
if (it != params->end ())
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,8 @@ namespace client
|
||||||
const int STREAM_REQUEST_TIMEOUT = 60; //in seconds
|
const int STREAM_REQUEST_TIMEOUT = 60; //in seconds
|
||||||
const char I2CP_PARAM_TAGS_TO_SEND[] = "crypto.tagsToSend";
|
const char I2CP_PARAM_TAGS_TO_SEND[] = "crypto.tagsToSend";
|
||||||
const int DEFAULT_TAGS_TO_SEND = 40;
|
const int DEFAULT_TAGS_TO_SEND = 40;
|
||||||
|
const char I2CP_PARAM_RATCHET_INBOUND_TAGS[] = "crypto.ratchet.inboundTags";
|
||||||
|
const char I2CP_PARAM_RATCHET_OUTBOUND_TAGS[] = "crypto.ratchet.outboundTags"; // not used yet
|
||||||
const char I2CP_PARAM_INBOUND_NICKNAME[] = "inbound.nickname";
|
const char I2CP_PARAM_INBOUND_NICKNAME[] = "inbound.nickname";
|
||||||
const char I2CP_PARAM_OUTBOUND_NICKNAME[] = "outbound.nickname";
|
const char I2CP_PARAM_OUTBOUND_NICKNAME[] = "outbound.nickname";
|
||||||
const char I2CP_PARAM_LEASESET_TYPE[] = "i2cp.leaseSetType";
|
const char I2CP_PARAM_LEASESET_TYPE[] = "i2cp.leaseSetType";
|
||||||
|
|
|
@ -341,7 +341,8 @@ namespace garlic
|
||||||
newTagset->SetTagSetID (tagsetID);
|
newTagset->SetTagSetID (tagsetID);
|
||||||
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey);
|
newTagset->DHInitialize (receiveTagset->GetNextRootKey (), tagsetKey);
|
||||||
newTagset->NextSessionTagRatchet ();
|
newTagset->NextSessionTagRatchet ();
|
||||||
GenerateMoreReceiveTags (newTagset, ECIESX25519_MAX_NUM_GENERATED_TAGS);
|
GenerateMoreReceiveTags (newTagset, (GetOwner () && GetOwner ()->GetNumRatchetInboundTags () > 0) ?
|
||||||
|
GetOwner ()->GetNumRatchetInboundTags () : ECIESX25519_MAX_NUM_GENERATED_TAGS);
|
||||||
receiveTagset->Expire ();
|
receiveTagset->Expire ();
|
||||||
LogPrint (eLogDebug, "Garlic: next receive tagset ", tagsetID, " created");
|
LogPrint (eLogDebug, "Garlic: next receive tagset ", tagsetID, " created");
|
||||||
}
|
}
|
||||||
|
@ -459,7 +460,8 @@ namespace garlic
|
||||||
m_SendTagset = std::make_shared<RatchetTagSet>(shared_from_this ());
|
m_SendTagset = std::make_shared<RatchetTagSet>(shared_from_this ());
|
||||||
m_SendTagset->DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
|
m_SendTagset->DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
|
||||||
m_SendTagset->NextSessionTagRatchet ();
|
m_SendTagset->NextSessionTagRatchet ();
|
||||||
GenerateMoreReceiveTags (receiveTagset, ECIESX25519_MIN_NUM_GENERATED_TAGS);
|
GenerateMoreReceiveTags (receiveTagset, (GetOwner () && GetOwner ()->GetNumRatchetInboundTags () > 0) ?
|
||||||
|
GetOwner ()->GetNumRatchetInboundTags () : ECIESX25519_MIN_NUM_GENERATED_TAGS);
|
||||||
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", m_NSRKey, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
|
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", m_NSRKey, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
|
||||||
// encrypt payload
|
// encrypt payload
|
||||||
if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len, m_H, 32, m_NSRKey, nonce, out + offset, len + 16, true)) // encrypt
|
if (!i2p::crypto::AEADChaCha20Poly1305 (payload, len, m_H, 32, m_NSRKey, nonce, out + offset, len + 16, true)) // encrypt
|
||||||
|
@ -548,7 +550,8 @@ namespace garlic
|
||||||
auto receiveTagset = std::make_shared<RatchetTagSet>(shared_from_this ());
|
auto receiveTagset = std::make_shared<RatchetTagSet>(shared_from_this ());
|
||||||
receiveTagset->DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
|
receiveTagset->DHInitialize (m_CK, keydata + 32); // tagset_ba = DH_INITIALIZE(chainKey, k_ba)
|
||||||
receiveTagset->NextSessionTagRatchet ();
|
receiveTagset->NextSessionTagRatchet ();
|
||||||
GenerateMoreReceiveTags (receiveTagset, ECIESX25519_MIN_NUM_GENERATED_TAGS);
|
GenerateMoreReceiveTags (receiveTagset, (GetOwner () && GetOwner ()->GetNumRatchetInboundTags () > 0) ?
|
||||||
|
GetOwner ()->GetNumRatchetInboundTags () : ECIESX25519_MIN_NUM_GENERATED_TAGS);
|
||||||
}
|
}
|
||||||
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", keydata, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
|
i2p::crypto::HKDF (keydata + 32, nullptr, 0, "AttachPayloadKDF", keydata, 32); // k = HKDF(k_ba, ZEROLEN, "AttachPayloadKDF", 32)
|
||||||
// decrypt payload
|
// decrypt payload
|
||||||
|
@ -610,11 +613,23 @@ namespace garlic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HandlePayload (payload, len - 16, receiveTagset, index);
|
HandlePayload (payload, len - 16, receiveTagset, index);
|
||||||
int moreTags = ECIESX25519_MIN_NUM_GENERATED_TAGS + (index >> 2); // N/4
|
if (GetOwner ())
|
||||||
if (moreTags > ECIESX25519_MAX_NUM_GENERATED_TAGS) moreTags = ECIESX25519_MAX_NUM_GENERATED_TAGS;
|
{
|
||||||
moreTags -= (receiveTagset->GetNextIndex () - index);
|
int moreTags = 0;
|
||||||
if (moreTags > 0 && GetOwner ())
|
if (GetOwner ()->GetNumRatchetInboundTags () > 0) // override in settings?
|
||||||
GenerateMoreReceiveTags (receiveTagset, moreTags);
|
{
|
||||||
|
if (receiveTagset->GetNextIndex () - index < GetOwner ()->GetNumRatchetInboundTags ()/2)
|
||||||
|
moreTags = GetOwner ()->GetNumRatchetInboundTags ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moreTags = ECIESX25519_MIN_NUM_GENERATED_TAGS + (index >> 2); // N/4
|
||||||
|
if (moreTags > ECIESX25519_MAX_NUM_GENERATED_TAGS) moreTags = ECIESX25519_MAX_NUM_GENERATED_TAGS;
|
||||||
|
moreTags -= (receiveTagset->GetNextIndex () - index);
|
||||||
|
}
|
||||||
|
if (moreTags > 0)
|
||||||
|
GenerateMoreReceiveTags (receiveTagset, moreTags);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,8 @@ namespace garlic
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
GarlicDestination::GarlicDestination (): m_NumTags (32) // 32 tags by default
|
GarlicDestination::GarlicDestination (): m_NumTags (32), // 32 tags by default
|
||||||
|
m_NumRatchetInboundTags (0) // 0 means standard
|
||||||
{
|
{
|
||||||
m_Ctx = BN_CTX_new ();
|
m_Ctx = BN_CTX_new ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,6 +232,8 @@ namespace garlic
|
||||||
void CleanUp ();
|
void CleanUp ();
|
||||||
void SetNumTags (int numTags) { m_NumTags = numTags; };
|
void SetNumTags (int numTags) { m_NumTags = numTags; };
|
||||||
int GetNumTags () const { return m_NumTags; };
|
int GetNumTags () const { return m_NumTags; };
|
||||||
|
void SetNumRatchetInboundTags (int numTags) { m_NumRatchetInboundTags = numTags; };
|
||||||
|
int GetNumRatchetInboundTags () const { return m_NumRatchetInboundTags; };
|
||||||
std::shared_ptr<GarlicRoutingSession> GetRoutingSession (std::shared_ptr<const i2p::data::RoutingDestination> destination, bool attachLeaseSet);
|
std::shared_ptr<GarlicRoutingSession> GetRoutingSession (std::shared_ptr<const i2p::data::RoutingDestination> destination, bool attachLeaseSet);
|
||||||
void CleanupExpiredTags ();
|
void CleanupExpiredTags ();
|
||||||
void RemoveDeliveryStatusSession (uint32_t msgID);
|
void RemoveDeliveryStatusSession (uint32_t msgID);
|
||||||
|
@ -278,6 +280,7 @@ namespace garlic
|
||||||
std::unordered_map<i2p::data::IdentHash, ElGamalAESSessionPtr> m_Sessions;
|
std::unordered_map<i2p::data::IdentHash, ElGamalAESSessionPtr> m_Sessions;
|
||||||
std::unordered_map<i2p::data::Tag<32>, ECIESX25519AEADRatchetSessionPtr> m_ECIESx25519Sessions; // static key -> session
|
std::unordered_map<i2p::data::Tag<32>, ECIESX25519AEADRatchetSessionPtr> m_ECIESx25519Sessions; // static key -> session
|
||||||
// incoming
|
// incoming
|
||||||
|
int m_NumRatchetInboundTags;
|
||||||
std::unordered_map<SessionTag, std::shared_ptr<AESDecryption>, std::hash<i2p::data::Tag<32> > > m_Tags;
|
std::unordered_map<SessionTag, std::shared_ptr<AESDecryption>, std::hash<i2p::data::Tag<32> > > m_Tags;
|
||||||
std::unordered_map<uint64_t, ECIESX25519AEADRatchetIndexTagset> m_ECIESx25519Tags; // session tag -> session
|
std::unordered_map<uint64_t, ECIESX25519AEADRatchetIndexTagset> m_ECIESx25519Tags; // session tag -> session
|
||||||
// DeliveryStatus
|
// DeliveryStatus
|
||||||
|
|
|
@ -461,6 +461,8 @@ namespace client
|
||||||
}
|
}
|
||||||
std::string explicitPeers = GetI2CPStringOption(section, I2CP_PARAM_EXPLICIT_PEERS, "");
|
std::string explicitPeers = GetI2CPStringOption(section, I2CP_PARAM_EXPLICIT_PEERS, "");
|
||||||
if (explicitPeers.length () > 0) options[I2CP_PARAM_EXPLICIT_PEERS] = explicitPeers;
|
if (explicitPeers.length () > 0) options[I2CP_PARAM_EXPLICIT_PEERS] = explicitPeers;
|
||||||
|
std::string ratchetInboundTags = GetI2CPStringOption(section, I2CP_PARAM_RATCHET_INBOUND_TAGS, "");
|
||||||
|
if (ratchetInboundTags.length () > 0) options[I2CP_PARAM_RATCHET_INBOUND_TAGS] = ratchetInboundTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientContext::ReadI2CPOptionsFromConfig (const std::string& prefix, std::map<std::string, std::string>& options) const
|
void ClientContext::ReadI2CPOptionsFromConfig (const std::string& prefix, std::map<std::string, std::string>& options) const
|
||||||
|
|
Loading…
Reference in a new issue