mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
destination delivery instructions
This commit is contained in:
parent
8c800dc178
commit
239c8b5172
|
@ -370,8 +370,8 @@ namespace garlic
|
||||||
std::vector<uint8_t> ECIESX25519AEADRatchetSession::CreatePayload (std::shared_ptr<const I2NPMessage> msg)
|
std::vector<uint8_t> ECIESX25519AEADRatchetSession::CreatePayload (std::shared_ptr<const I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
size_t payloadLen = 7; // datatime
|
size_t payloadLen = 7; // datatime
|
||||||
if (msg)
|
if (msg && m_Destination)
|
||||||
payloadLen += msg->GetPayloadLength () + 13;
|
payloadLen += msg->GetPayloadLength () + 13 + 32;
|
||||||
auto leaseSet = CreateDatabaseStoreMsg (GetOwner ()->GetLeaseSet ());
|
auto leaseSet = CreateDatabaseStoreMsg (GetOwner ()->GetLeaseSet ());
|
||||||
if (leaseSet)
|
if (leaseSet)
|
||||||
payloadLen += leaseSet->GetPayloadLength () + 13;
|
payloadLen += leaseSet->GetPayloadLength () + 13;
|
||||||
|
@ -389,8 +389,8 @@ namespace garlic
|
||||||
if (leaseSet)
|
if (leaseSet)
|
||||||
offset += CreateGarlicClove (leaseSet, v.data () + offset, payloadLen - offset);
|
offset += CreateGarlicClove (leaseSet, v.data () + offset, payloadLen - offset);
|
||||||
// msg
|
// msg
|
||||||
if (msg)
|
if (msg && m_Destination)
|
||||||
offset += CreateGarlicClove (msg, v.data () + offset, payloadLen - offset);
|
offset += CreateGarlicClove (msg, v.data () + offset, payloadLen - offset, true);
|
||||||
// padding
|
// padding
|
||||||
v[offset] = eECIESx25519BlkPadding; offset++;
|
v[offset] = eECIESx25519BlkPadding; offset++;
|
||||||
htobe16buf (v.data () + offset, paddingSize); offset += 2;
|
htobe16buf (v.data () + offset, paddingSize); offset += 2;
|
||||||
|
@ -398,18 +398,27 @@ namespace garlic
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ECIESX25519AEADRatchetSession::CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len)
|
size_t ECIESX25519AEADRatchetSession::CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len, bool isDestination)
|
||||||
{
|
{
|
||||||
if (!msg) return 0;
|
if (!msg) return 0;
|
||||||
uint16_t cloveSize = msg->GetPayloadLength () + 9 + 1;
|
uint16_t cloveSize = msg->GetPayloadLength () + 9 + 1;
|
||||||
|
if (isDestination) cloveSize += 32;
|
||||||
if ((int)len < cloveSize + 3) return 0;
|
if ((int)len < cloveSize + 3) return 0;
|
||||||
buf[0] = eECIESx25519BlkGalicClove; // clove type
|
buf[0] = eECIESx25519BlkGalicClove; // clove type
|
||||||
htobe16buf (buf + 1, cloveSize); // size
|
htobe16buf (buf + 1, cloveSize); // size
|
||||||
buf[3] = 0; // flag and delivery instructions
|
buf += 3;
|
||||||
buf[4] = msg->GetTypeID (); // I2NP msg type
|
if (isDestination)
|
||||||
htobe32buf (buf + 5, msg->GetMsgID ()); // msgID
|
{
|
||||||
htobe32buf (buf + 9, msg->GetExpiration ()/1000); // expiration in seconds
|
*buf = (eGarlicDeliveryTypeDestination << 5);
|
||||||
memcpy (buf + 13, msg->GetPayload (), msg->GetPayloadLength ());
|
memcpy (buf + 1, *m_Destination, 32); buf += 32;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*buf = 0;
|
||||||
|
buf++; // flag and delivery instructions
|
||||||
|
*buf = msg->GetTypeID (); // I2NP msg type
|
||||||
|
htobe32buf (buf + 1, msg->GetMsgID ()); // msgID
|
||||||
|
htobe32buf (buf + 5, msg->GetExpiration ()/1000); // expiration in seconds
|
||||||
|
memcpy (buf + 9, msg->GetPayload (), msg->GetPayloadLength ());
|
||||||
return cloveSize + 3;
|
return cloveSize + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,11 @@ namespace garlic
|
||||||
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
||||||
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
|
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
|
||||||
|
|
||||||
|
void SetDestination (const i2p::data::IdentHash& dest) // TODO:
|
||||||
|
{
|
||||||
|
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ResetKeys ();
|
void ResetKeys ();
|
||||||
|
@ -84,7 +89,7 @@ namespace garlic
|
||||||
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);
|
||||||
std::vector<uint8_t> CreatePayload (std::shared_ptr<const I2NPMessage> msg);
|
std::vector<uint8_t> CreatePayload (std::shared_ptr<const I2NPMessage> msg);
|
||||||
size_t CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len);
|
size_t CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len, bool isDestination = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -93,6 +98,7 @@ namespace garlic
|
||||||
i2p::crypto::X25519Keys m_EphemeralKeys;
|
i2p::crypto::X25519Keys m_EphemeralKeys;
|
||||||
SessionState m_State = eSessionStateNew;
|
SessionState m_State = eSessionStateNew;
|
||||||
RatchetTagSet m_TagsetAB, m_TagsetBA;
|
RatchetTagSet m_TagsetAB, m_TagsetBA;
|
||||||
|
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,6 +669,7 @@ namespace garlic
|
||||||
session = std::make_shared<ECIESX25519AEADRatchetSession> (this);
|
session = std::make_shared<ECIESX25519AEADRatchetSession> (this);
|
||||||
session->SetRemoteStaticKey (staticKey);
|
session->SetRemoteStaticKey (staticKey);
|
||||||
}
|
}
|
||||||
|
session->SetDestination (destination->GetIdentHash ()); // TODO: remove
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -860,8 +861,6 @@ namespace garlic
|
||||||
|
|
||||||
void GarlicDestination::HandleECIESx25519 (const uint8_t * buf, size_t len)
|
void GarlicDestination::HandleECIESx25519 (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
auto handleClove = std::bind (&GarlicDestination::HandleECIESx25519GarlicClove,
|
|
||||||
this, std::placeholders::_1, std::placeholders::_2);
|
|
||||||
uint64_t tag;
|
uint64_t tag;
|
||||||
memcpy (&tag, buf, 8);
|
memcpy (&tag, buf, 8);
|
||||||
ECIESX25519AEADRatchetSessionPtr session;
|
ECIESX25519AEADRatchetSessionPtr session;
|
||||||
|
@ -874,7 +873,8 @@ namespace garlic
|
||||||
else
|
else
|
||||||
session = std::make_shared<ECIESX25519AEADRatchetSession> (this); // incoming
|
session = std::make_shared<ECIESX25519AEADRatchetSession> (this); // incoming
|
||||||
|
|
||||||
if (!session->HandleNextMessage (buf, len, handleClove))
|
if (!session->HandleNextMessage (buf, len, std::bind (&GarlicDestination::HandleECIESx25519GarlicClove,
|
||||||
|
this, std::placeholders::_1, std::placeholders::_2)))
|
||||||
LogPrint (eLogError, "Garlic: can't handle ECIES-X25519-AEAD-Ratchet message");
|
LogPrint (eLogError, "Garlic: can't handle ECIES-X25519-AEAD-Ratchet message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue