|
|
@ -487,16 +487,18 @@ namespace garlic |
|
|
|
buf += 4; // length
|
|
|
|
buf += 4; // length
|
|
|
|
|
|
|
|
|
|
|
|
bool found = false; |
|
|
|
bool found = false; |
|
|
|
|
|
|
|
uint64_t tag; |
|
|
|
if (SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)) |
|
|
|
if (SupportsEncryptionType (i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// try ECIESx25519 tag
|
|
|
|
// try ECIESx25519 tag
|
|
|
|
uint64_t tag; |
|
|
|
|
|
|
|
memcpy (&tag, buf, 8); |
|
|
|
memcpy (&tag, buf, 8); |
|
|
|
auto it1 = m_ECIESx25519Tags.find (tag); |
|
|
|
auto it1 = m_ECIESx25519Tags.find (tag); |
|
|
|
if (it1 != m_ECIESx25519Tags.end ()) |
|
|
|
if (it1 != m_ECIESx25519Tags.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
found = true; |
|
|
|
found = true; |
|
|
|
if (!it1->second.tagset->HandleNextMessage (buf, length, it1->second.index)) |
|
|
|
if (it1->second.tagset->HandleNextMessage (buf, length, it1->second.index)) |
|
|
|
|
|
|
|
m_LastTagset = it1->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 (it1); |
|
|
|
m_ECIESx25519Tags.erase (it1); |
|
|
|
} |
|
|
|
} |
|
|
@ -542,8 +544,26 @@ 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)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// try to gererate more tags for last tagset
|
|
|
|
|
|
|
|
if (m_LastTagset) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < ECIESX25519_MAX_NUM_GENERATED_TAGS; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "Garlic: Missing ECIES-X25519-AEAD-Ratchet tag was generated"); |
|
|
|
|
|
|
|
if (AddECIESx25519SessionNextTag (m_LastTagset) == tag) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_LastTagset->HandleNextMessage (buf, length, m_ECIESx25519Tags[tag].index)) |
|
|
|
|
|
|
|
found = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!found) m_LastTagset = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!found) |
|
|
|
LogPrint (eLogError, "Garlic: can't handle ECIES-X25519-AEAD-Ratchet message"); |
|
|
|
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"); |
|
|
|
} |
|
|
|
} |
|
|
@ -845,6 +865,8 @@ 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) |
|
|
@ -1030,11 +1052,12 @@ namespace garlic |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GarlicDestination::AddECIESx25519SessionNextTag (RatchetTagSetPtr tagset) |
|
|
|
uint64_t GarlicDestination::AddECIESx25519SessionNextTag (RatchetTagSetPtr tagset) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto index = tagset->GetNextIndex (); |
|
|
|
auto index = tagset->GetNextIndex (); |
|
|
|
uint64_t tag = tagset->GetNextSessionTag (); |
|
|
|
uint64_t tag = tagset->GetNextSessionTag (); |
|
|
|
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexTagset{index, tagset}); |
|
|
|
m_ECIESx25519Tags.emplace (tag, ECIESX25519AEADRatchetIndexTagset{index, tagset}); |
|
|
|
|
|
|
|
return tag; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GarlicDestination::AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session) |
|
|
|
void GarlicDestination::AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session) |
|
|
|