store and check remote Identity

pull/92/head
orignal 10 years ago
parent c9c311c41e
commit f811b19cf1

@ -16,20 +16,27 @@ namespace data
{
// copy public and signing keys together
memcpy (publicKey, keys.publicKey, sizeof (publicKey) + sizeof (signingKey));
memset (certificate, 0, sizeof (certificate));
memset (&certificate, 0, sizeof (certificate));
return *this;
}
bool Identity::FromBase64 (const std::string& s)
{
size_t count = Base64ToByteStream (s.c_str(), s.length(), publicKey, sizeof (Identity));
return count == sizeof(Identity);
size_t count = Base64ToByteStream (s.c_str(), s.length(), publicKey, DEFAULT_IDENTITY_SIZE);
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 hash;
CryptoPP::SHA256().CalculateDigest(hash, publicKey, sizeof (Identity));
CryptoPP::SHA256().CalculateDigest(hash, publicKey, DEFAULT_IDENTITY_SIZE);
return hash;
}

@ -71,14 +71,28 @@ namespace data
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
{
uint8_t publicKey[256];
uint8_t signingKey[128];
uint8_t certificate[3];
struct
{
uint8_t type;
uint16_t length;
} certificate;
Identity& operator=(const Keys& keys);
bool FromBase64(const std::string& );
size_t FromBuffer (const uint8_t * buf, size_t len);
IdentHash Hash() const;
};

@ -118,14 +118,17 @@ namespace stream
if (flags & PACKET_FLAG_FROM_INCLUDED)
{
LogPrint ("From identity");
if (!m_RemoteLeaseSet)
optionData += m_RemoteIdentity.FromBuffer (optionData, packet->GetOptionSize ());
if (m_RemoteLeaseSet)
{
i2p::data::Identity * identity = (i2p::data::Identity *)optionData;
LogPrint ("Incoming stream from ", identity->Hash ().ToBase64 ());
m_RemoteLeaseSet = i2p::data::netdb.FindLeaseSet (identity->Hash ());
if (!m_RemoteLeaseSet)
LogPrint ("LeaseSet ", identity->Hash ().ToBase64 (), " not found");
if (m_RemoteIdentity.Hash () != m_RemoteLeaseSet->GetIdentHash ()) // check recieved identity
{
LogPrint ("Unexpected identity ", m_RemoteIdentity.Hash ().ToBase64 (), " ", m_RemoteLeaseSet->GetIdentHash ().ToBase64 (), " expected");
m_RemoteLeaseSet = nullptr;
}
}
else
LogPrint ("Incoming stream from ", m_RemoteIdentity.Hash ().ToBase64 ());
optionData += sizeof (i2p::data::Identity);
}
@ -303,11 +306,15 @@ namespace stream
}
bool Stream::SendPacket (const uint8_t * buf, size_t len)
{
{
if (!m_RemoteLeaseSet)
{
LogPrint ("Can't send packet. Missing remote LeaseSet");
return false;
UpdateCurrentRemoteLease ();
if (!m_RemoteLeaseSet)
{
LogPrint ("Can't send packet. Missing remote LeaseSet");
return false;
}
}
I2NPMessage * leaseSet = nullptr;
@ -347,6 +354,12 @@ namespace stream
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)
{
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();

@ -112,6 +112,7 @@ namespace stream
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber, m_LastReceivedSequenceNumber;
bool m_IsOpen, m_IsOutgoing, m_LeaseSetUpdated;
StreamingDestination * m_LocalDestination;
i2p::data::Identity m_RemoteIdentity;
const i2p::data::LeaseSet * m_RemoteLeaseSet;
i2p::data::Lease m_CurrentRemoteLease;
std::queue<Packet *> m_ReceiveQueue;

Loading…
Cancel
Save