mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
store and check remote Identity
This commit is contained in:
parent
c9c311c41e
commit
f811b19cf1
15
Identity.cpp
15
Identity.cpp
@ -16,20 +16,27 @@ namespace data
|
|||||||
{
|
{
|
||||||
// copy public and signing keys together
|
// copy public and signing keys together
|
||||||
memcpy (publicKey, keys.publicKey, sizeof (publicKey) + sizeof (signingKey));
|
memcpy (publicKey, keys.publicKey, sizeof (publicKey) + sizeof (signingKey));
|
||||||
memset (certificate, 0, sizeof (certificate));
|
memset (&certificate, 0, sizeof (certificate));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Identity::FromBase64 (const std::string& s)
|
bool Identity::FromBase64 (const std::string& s)
|
||||||
{
|
{
|
||||||
size_t count = Base64ToByteStream (s.c_str(), s.length(), publicKey, sizeof (Identity));
|
size_t count = Base64ToByteStream (s.c_str(), s.length(), publicKey, DEFAULT_IDENTITY_SIZE);
|
||||||
return count == sizeof(Identity);
|
return count == DEFAULT_IDENTITY_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Identity::FromBuffer (const uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
memcpy (publicKey, buf, DEFAULT_IDENTITY_SIZE);
|
||||||
|
// TODO: process certificate
|
||||||
|
return DEFAULT_IDENTITY_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentHash Identity::Hash() const
|
IdentHash Identity::Hash() const
|
||||||
{
|
{
|
||||||
IdentHash hash;
|
IdentHash hash;
|
||||||
CryptoPP::SHA256().CalculateDigest(hash, publicKey, sizeof (Identity));
|
CryptoPP::SHA256().CalculateDigest(hash, publicKey, DEFAULT_IDENTITY_SIZE);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
Identity.h
16
Identity.h
@ -71,14 +71,28 @@ namespace data
|
|||||||
uint8_t signingKey[128];
|
uint8_t signingKey[128];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const uint8_t CERTIFICATE_TYPE_NULL = 0;
|
||||||
|
const uint8_t CERTIFICATE_TYPE_HASHCASH = 1;
|
||||||
|
const uint8_t CERTIFICATE_TYPE_HIDDEN = 2;
|
||||||
|
const uint8_t CERTIFICATE_TYPE_SIGNED = 3;
|
||||||
|
const uint8_t CERTIFICATE_TYPE_MULTIPLE = 4;
|
||||||
|
const uint8_t CERTIFICATE_TYPE_KEY = 5;
|
||||||
|
|
||||||
|
const size_t DEFAULT_IDENTITY_SIZE = 387;
|
||||||
struct Identity
|
struct Identity
|
||||||
{
|
{
|
||||||
uint8_t publicKey[256];
|
uint8_t publicKey[256];
|
||||||
uint8_t signingKey[128];
|
uint8_t signingKey[128];
|
||||||
uint8_t certificate[3];
|
struct
|
||||||
|
{
|
||||||
|
uint8_t type;
|
||||||
|
uint16_t length;
|
||||||
|
} certificate;
|
||||||
|
|
||||||
Identity& operator=(const Keys& keys);
|
Identity& operator=(const Keys& keys);
|
||||||
bool FromBase64(const std::string& );
|
bool FromBase64(const std::string& );
|
||||||
|
size_t FromBuffer (const uint8_t * buf, size_t len);
|
||||||
IdentHash Hash() const;
|
IdentHash Hash() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,14 +118,17 @@ namespace stream
|
|||||||
if (flags & PACKET_FLAG_FROM_INCLUDED)
|
if (flags & PACKET_FLAG_FROM_INCLUDED)
|
||||||
{
|
{
|
||||||
LogPrint ("From identity");
|
LogPrint ("From identity");
|
||||||
if (!m_RemoteLeaseSet)
|
optionData += m_RemoteIdentity.FromBuffer (optionData, packet->GetOptionSize ());
|
||||||
|
if (m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
i2p::data::Identity * identity = (i2p::data::Identity *)optionData;
|
if (m_RemoteIdentity.Hash () != m_RemoteLeaseSet->GetIdentHash ()) // check recieved identity
|
||||||
LogPrint ("Incoming stream from ", identity->Hash ().ToBase64 ());
|
{
|
||||||
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (identity->Hash ());
|
LogPrint ("Unexpected identity ", m_RemoteIdentity.Hash ().ToBase64 (), " ", m_RemoteLeaseSet->GetIdentHash ().ToBase64 (), " expected");
|
||||||
if (!m_RemoteLeaseSet)
|
m_RemoteLeaseSet = nullptr;
|
||||||
LogPrint ("LeaseSet ", identity->Hash ().ToBase64 (), " not found");
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Incoming stream from ", m_RemoteIdentity.Hash ().ToBase64 ());
|
||||||
optionData += sizeof (i2p::data::Identity);
|
optionData += sizeof (i2p::data::Identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,11 +306,15 @@ namespace stream
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::SendPacket (const uint8_t * buf, size_t len)
|
bool Stream::SendPacket (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
LogPrint ("Can't send packet. Missing remote LeaseSet");
|
UpdateCurrentRemoteLease ();
|
||||||
return false;
|
if (!m_RemoteLeaseSet)
|
||||||
|
{
|
||||||
|
LogPrint ("Can't send packet. Missing remote LeaseSet");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
I2NPMessage * leaseSet = nullptr;
|
I2NPMessage * leaseSet = nullptr;
|
||||||
@ -347,6 +354,12 @@ namespace stream
|
|||||||
|
|
||||||
void Stream::UpdateCurrentRemoteLease ()
|
void Stream::UpdateCurrentRemoteLease ()
|
||||||
{
|
{
|
||||||
|
if (!m_RemoteLeaseSet)
|
||||||
|
{
|
||||||
|
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (m_RemoteIdentity.Hash ());
|
||||||
|
if (!m_RemoteLeaseSet)
|
||||||
|
LogPrint ("LeaseSet ", m_RemoteIdentity.Hash ().ToBase64 (), " not found");
|
||||||
|
}
|
||||||
if (m_RemoteLeaseSet)
|
if (m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
||||||
|
@ -112,6 +112,7 @@ namespace stream
|
|||||||
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber, m_LastReceivedSequenceNumber;
|
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber, m_LastReceivedSequenceNumber;
|
||||||
bool m_IsOpen, m_IsOutgoing, m_LeaseSetUpdated;
|
bool m_IsOpen, m_IsOutgoing, m_LeaseSetUpdated;
|
||||||
StreamingDestination * m_LocalDestination;
|
StreamingDestination * m_LocalDestination;
|
||||||
|
i2p::data::Identity m_RemoteIdentity;
|
||||||
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
||||||
i2p::data::Lease m_CurrentRemoteLease;
|
i2p::data::Lease m_CurrentRemoteLease;
|
||||||
std::queue<Packet *> m_ReceiveQueue;
|
std::queue<Packet *> m_ReceiveQueue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user