session tag for ECIESx25519 sessions

This commit is contained in:
orignal 2020-01-21 14:40:23 -05:00
parent ccec3376ba
commit 6142e93252
4 changed files with 79 additions and 28 deletions

View file

@ -861,14 +861,32 @@ namespace garlic
void GarlicDestination::HandleECIESx25519 (const uint8_t * buf, size_t len)
{
auto session = std::make_shared<ECIESX25519AEADRatchetSession> (this);
if (session->NewIncomingSession (buf, len, std::bind (&GarlicDestination::HandleECIESx25519GarlicClove,
this, std::placeholders::_1, std::placeholders::_2)))
auto handleClove = std::bind (&GarlicDestination::HandleECIESx25519GarlicClove,
this, std::placeholders::_1, std::placeholders::_2);
uint64_t tag;
memcpy (&tag, buf, 8);
auto it = m_ECIESx25519Tags.find (tag);
if (it != m_ECIESx25519Tags.end ())
{
m_ECIESx25519Sessions.emplace (session->GetRemoteStaticKey (), session);
// TODO
auto session = it->second;
if (!session->NewOutgoingSessionReply (buf, len, handleClove))
{
LogPrint (eLogError, "Garlic: can't decrypt ECIES-X25519-AEAD-Ratchet new session reply");
m_ECIESx25519Tags.erase (tag);
m_ECIESx25519Sessions.erase (session->GetRemoteStaticKey ());
}
}
else
LogPrint (eLogError, "Garlic: can't decrypt ECIES-X25519-AEAD-Ratchet new session");
{
auto session = std::make_shared<ECIESX25519AEADRatchetSession> (this);
if (session->NewIncomingSession (buf, len, handleClove))
{
m_ECIESx25519Sessions.emplace (session->GetRemoteStaticKey (), session);
}
else
LogPrint (eLogError, "Garlic: can't decrypt ECIES-X25519-AEAD-Ratchet new session");
}
}
void GarlicDestination::HandleECIESx25519GarlicClove (const uint8_t * buf, size_t len)
@ -926,5 +944,10 @@ namespace garlic
LogPrint (eLogWarning, "Garlic: unexpected delivery type ", (int)deliveryType);
}
}
void GarlicDestination::AddECIESx25519SessionTag (uint64_t tag, ECIESX25519AEADRatchetSessionPtr session)
{
m_ECIESx25519Tags.emplace (tag, session);
}
}
}