mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
don't try to generate more ECIES-X25519-AEAD-Ratchet tags if decryption failed
This commit is contained in:
parent
17d0e59d02
commit
d5aca85a35
@ -541,34 +541,7 @@ namespace garlic
|
|||||||
// otherwise ECIESx25519
|
// otherwise ECIESx25519
|
||||||
auto session = std::make_shared<ECIESX25519AEADRatchetSession> (this, false); // incoming
|
auto session = std::make_shared<ECIESX25519AEADRatchetSession> (this, false); // incoming
|
||||||
if (!session->HandleNextMessage (buf, length, nullptr, 0))
|
if (!session->HandleNextMessage (buf, length, nullptr, 0))
|
||||||
{
|
LogPrint (eLogError, "Garlic: Can't handle ECIES-X25519-AEAD-Ratchet message");
|
||||||
// try to generate more tags for last tagset
|
|
||||||
if (m_LastTagset && (m_LastTagset->GetNextIndex () - m_LastTagset->GetTrimBehind () < 3*ECIESX25519_MAX_NUM_GENERATED_TAGS))
|
|
||||||
{
|
|
||||||
uint64_t missingTag; memcpy (&missingTag, buf, 8);
|
|
||||||
auto maxTags = std::max (m_NumRatchetInboundTags, ECIESX25519_MAX_NUM_GENERATED_TAGS);
|
|
||||||
LogPrint (eLogWarning, "Garlic: Trying to generate more ECIES-X25519-AEAD-Ratchet tags");
|
|
||||||
for (int i = 0; i < maxTags; i++)
|
|
||||||
{
|
|
||||||
auto nextTag = AddECIESx25519SessionNextTag (m_LastTagset);
|
|
||||||
if (!nextTag)
|
|
||||||
{
|
|
||||||
LogPrint (eLogError, "Garlic: Can't create new ECIES-X25519-AEAD-Ratchet tag for last tagset");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (nextTag == missingTag)
|
|
||||||
{
|
|
||||||
LogPrint (eLogDebug, "Garlic: Missing ECIES-X25519-AEAD-Ratchet tag was generated");
|
|
||||||
if (m_LastTagset->HandleNextMessage (buf, length, m_ECIESx25519Tags[nextTag].index))
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) m_LastTagset = nullptr;
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
LogPrint (eLogError, "Garlic: Can't handle ECIES-X25519-AEAD-Ratchet message");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "Garlic: Failed to decrypt message");
|
LogPrint (eLogError, "Garlic: Failed to decrypt message");
|
||||||
@ -583,9 +556,7 @@ namespace garlic
|
|||||||
auto it = m_ECIESx25519Tags.find (tag);
|
auto it = m_ECIESx25519Tags.find (tag);
|
||||||
if (it != m_ECIESx25519Tags.end ())
|
if (it != m_ECIESx25519Tags.end ())
|
||||||
{
|
{
|
||||||
if (it->second.tagset && it->second.tagset->HandleNextMessage (buf, len, it->second.index))
|
if (!it->second.tagset || !it->second.tagset->HandleNextMessage (buf, len, it->second.index))
|
||||||
m_LastTagset = it->second.tagset;
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Garlic: Can't handle ECIES-X25519-AEAD-Ratchet message");
|
LogPrint (eLogError, "Garlic: Can't handle ECIES-X25519-AEAD-Ratchet message");
|
||||||
m_ECIESx25519Tags.erase (it);
|
m_ECIESx25519Tags.erase (it);
|
||||||
return true;
|
return true;
|
||||||
@ -893,8 +864,6 @@ namespace garlic
|
|||||||
}
|
}
|
||||||
if (numExpiredTags > 0)
|
if (numExpiredTags > 0)
|
||||||
LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " ECIESx25519 tags expired for ", GetIdentHash().ToBase64 ());
|
LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " ECIESx25519 tags expired for ", GetIdentHash().ToBase64 ());
|
||||||
if (m_LastTagset && m_LastTagset->IsExpired (ts))
|
|
||||||
m_LastTagset = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
||||||
|
@ -288,7 +288,6 @@ namespace garlic
|
|||||||
int m_NumRatchetInboundTags;
|
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
|
||||||
ReceiveRatchetTagSetPtr m_LastTagset; // tagset last message came for
|
|
||||||
// DeliveryStatus
|
// DeliveryStatus
|
||||||
std::mutex m_DeliveryStatusSessionsMutex;
|
std::mutex m_DeliveryStatusSessionsMutex;
|
||||||
std::unordered_map<uint32_t, GarlicRoutingSessionPtr> m_DeliveryStatusSessions; // msgID -> session
|
std::unordered_map<uint32_t, GarlicRoutingSessionPtr> m_DeliveryStatusSessions; // msgID -> session
|
||||||
|
Loading…
Reference in New Issue
Block a user