mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
extended identity for local destination
This commit is contained in:
parent
9b8460cffa
commit
2bc1ba1a9c
28
Identity.cpp
28
Identity.cpp
@ -77,6 +77,20 @@ namespace data
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IdentityEx& IdentityEx::operator=(const Identity& standard)
|
||||||
|
{
|
||||||
|
m_StandardIdentity = standard;
|
||||||
|
m_IdentHash = m_StandardIdentity.Hash ();
|
||||||
|
|
||||||
|
delete m_Verifier;
|
||||||
|
m_Verifier = nullptr;
|
||||||
|
delete[] m_ExtendedBuffer;
|
||||||
|
m_ExtendedBuffer = nullptr;
|
||||||
|
m_ExtendedLen = 0;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
size_t IdentityEx::FromBuffer (const uint8_t * buf, size_t len)
|
size_t IdentityEx::FromBuffer (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
delete m_Verifier;
|
delete m_Verifier;
|
||||||
@ -99,7 +113,15 @@ namespace data
|
|||||||
return GetFullLen ();
|
return GetFullLen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IdentityEx::GetSigningPublicKeyLen ()
|
size_t IdentityEx::ToBuffer (uint8_t * buf, size_t len) const
|
||||||
|
{
|
||||||
|
memcpy (buf, &m_StandardIdentity, DEFAULT_IDENTITY_SIZE);
|
||||||
|
if (m_ExtendedLen > 0 && m_ExtendedBuffer)
|
||||||
|
memcpy (buf + DEFAULT_IDENTITY_SIZE, m_ExtendedBuffer, m_ExtendedLen);
|
||||||
|
return GetFullLen ();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t IdentityEx::GetSigningPublicKeyLen () const
|
||||||
{
|
{
|
||||||
if (!m_Verifier)
|
if (!m_Verifier)
|
||||||
CreateVerifier ();
|
CreateVerifier ();
|
||||||
@ -108,7 +130,7 @@ namespace data
|
|||||||
return 128;
|
return 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IdentityEx::GetSignatureLen ()
|
size_t IdentityEx::GetSignatureLen () const
|
||||||
{
|
{
|
||||||
if (!m_Verifier)
|
if (!m_Verifier)
|
||||||
CreateVerifier ();
|
CreateVerifier ();
|
||||||
@ -125,7 +147,7 @@ namespace data
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdentityEx::CreateVerifier ()
|
void IdentityEx::CreateVerifier () const
|
||||||
{
|
{
|
||||||
switch (m_StandardIdentity.certificate.type)
|
switch (m_StandardIdentity.certificate.type)
|
||||||
{
|
{
|
||||||
|
15
Identity.h
15
Identity.h
@ -109,24 +109,26 @@ namespace data
|
|||||||
IdentityEx (const IdentityEx& other);
|
IdentityEx (const IdentityEx& other);
|
||||||
~IdentityEx ();
|
~IdentityEx ();
|
||||||
IdentityEx& operator=(const IdentityEx& other);
|
IdentityEx& operator=(const IdentityEx& other);
|
||||||
|
IdentityEx& operator=(const Identity& standard);
|
||||||
|
|
||||||
size_t FromBuffer (const uint8_t * buf, size_t len);
|
size_t FromBuffer (const uint8_t * buf, size_t len);
|
||||||
|
size_t ToBuffer (uint8_t * buf, size_t len) const;
|
||||||
const Identity& GetStandardIdentity () const { return m_StandardIdentity; };
|
const Identity& GetStandardIdentity () const { return m_StandardIdentity; };
|
||||||
const IdentHash& GetIdentHash () const { return m_IdentHash; };
|
const IdentHash& GetIdentHash () const { return m_IdentHash; };
|
||||||
size_t GetFullLen () const { return m_ExtendedLen + DEFAULT_IDENTITY_SIZE; };
|
size_t GetFullLen () const { return m_ExtendedLen + DEFAULT_IDENTITY_SIZE; };
|
||||||
size_t GetSigningPublicKeyLen ();
|
size_t GetSigningPublicKeyLen () const;
|
||||||
size_t GetSignatureLen ();
|
size_t GetSignatureLen () const;
|
||||||
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature);
|
bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void CreateVerifier ();
|
void CreateVerifier () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Identity m_StandardIdentity;
|
Identity m_StandardIdentity;
|
||||||
IdentHash m_IdentHash;
|
IdentHash m_IdentHash;
|
||||||
i2p::crypto::Verifier * m_Verifier;
|
mutable i2p::crypto::Verifier * m_Verifier;
|
||||||
size_t m_ExtendedLen;
|
size_t m_ExtendedLen;
|
||||||
uint8_t * m_ExtendedBuffer;
|
uint8_t * m_ExtendedBuffer;
|
||||||
};
|
};
|
||||||
@ -201,8 +203,7 @@ namespace data
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~LocalDestination() {};
|
virtual ~LocalDestination() {};
|
||||||
virtual const IdentHash& GetIdentHash () const = 0;
|
virtual const IdentityEx& GetIdentity () const = 0;
|
||||||
virtual const Identity& GetIdentity () const = 0;
|
|
||||||
virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
|
virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
|
||||||
virtual const uint8_t * GetEncryptionPublicKey () const = 0;
|
virtual const uint8_t * GetEncryptionPublicKey () const = 0;
|
||||||
virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0;
|
virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0;
|
||||||
|
20
LeaseSet.cpp
20
LeaseSet.cpp
@ -22,17 +22,18 @@ namespace data
|
|||||||
|
|
||||||
LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool):
|
LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool):
|
||||||
m_IsUnsolicited (false)
|
m_IsUnsolicited (false)
|
||||||
{
|
{
|
||||||
m_BufferLen = 0;
|
|
||||||
// header
|
// header
|
||||||
const i2p::data::LocalDestination& localDestination = pool.GetLocalDestination ();
|
const i2p::data::LocalDestination& localDestination = pool.GetLocalDestination ();
|
||||||
LeaseSetHeader * header = (LeaseSetHeader *)m_Buffer;
|
m_BufferLen = localDestination.GetIdentity ().ToBuffer (m_Buffer, MAX_LS_BUFFER_SIZE);
|
||||||
header->destination = localDestination.GetIdentity ();
|
memcpy (m_Buffer + m_BufferLen, localDestination.GetEncryptionPublicKey (), 256);
|
||||||
memcpy (header->encryptionKey, localDestination.GetEncryptionPublicKey (), 256);
|
m_BufferLen += 256;
|
||||||
memset (header->signingKey, 0, 128);
|
auto signingKeyLen = localDestination.GetIdentity ().GetSigningPublicKeyLen ();
|
||||||
|
memset (m_Buffer + m_BufferLen, 0, signingKeyLen);
|
||||||
|
m_BufferLen += signingKeyLen;
|
||||||
auto tunnels = pool.GetInboundTunnels (5); // 5 tunnels maximum
|
auto tunnels = pool.GetInboundTunnels (5); // 5 tunnels maximum
|
||||||
header->num = tunnels.size (); // num leases
|
m_Buffer[m_BufferLen] = tunnels.size (); // num leases
|
||||||
m_BufferLen += sizeof (LeaseSetHeader);
|
m_BufferLen++;
|
||||||
// leases
|
// leases
|
||||||
for (auto it: tunnels)
|
for (auto it: tunnels)
|
||||||
{
|
{
|
||||||
@ -45,8 +46,9 @@ namespace data
|
|||||||
m_BufferLen += sizeof (Lease);
|
m_BufferLen += sizeof (Lease);
|
||||||
}
|
}
|
||||||
// signature
|
// signature
|
||||||
|
// TODO: signer
|
||||||
localDestination.Sign (m_Buffer, m_BufferLen, m_Buffer + m_BufferLen);
|
localDestination.Sign (m_Buffer, m_BufferLen, m_Buffer + m_BufferLen);
|
||||||
m_BufferLen += 40;
|
m_BufferLen += 40; // TODO:
|
||||||
LogPrint ("Local LeaseSet of ", tunnels.size (), " leases created");
|
LogPrint ("Local LeaseSet of ", tunnels.size (), " leases created");
|
||||||
|
|
||||||
ReadFromBuffer ();
|
ReadFromBuffer ();
|
||||||
|
@ -34,14 +34,6 @@ namespace data
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LeaseSetHeader
|
|
||||||
{
|
|
||||||
Identity destination;
|
|
||||||
uint8_t encryptionKey[256];
|
|
||||||
uint8_t signingKey[128];
|
|
||||||
uint8_t num;
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
const int MAX_LS_BUFFER_SIZE = 2048;
|
const int MAX_LS_BUFFER_SIZE = 2048;
|
||||||
|
@ -44,6 +44,7 @@ namespace i2p
|
|||||||
routerInfo.CreateBuffer ();
|
routerInfo.CreateBuffer ();
|
||||||
|
|
||||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||||
|
m_Identity = m_RouterInfo.GetRouterIdentity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
||||||
@ -84,7 +85,8 @@ namespace i2p
|
|||||||
|
|
||||||
i2p::data::RouterInfo routerInfo(i2p::util::filesystem::GetFullPath (ROUTER_INFO)); // TODO
|
i2p::data::RouterInfo routerInfo(i2p::util::filesystem::GetFullPath (ROUTER_INFO)); // TODO
|
||||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||||
|
m_Identity = m_RouterInfo.GetRouterIdentity ();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,14 +22,14 @@ namespace i2p
|
|||||||
const uint8_t * GetPrivateKey () const { return m_Keys.privateKey; };
|
const uint8_t * GetPrivateKey () const { return m_Keys.privateKey; };
|
||||||
const uint8_t * GetSigningPrivateKey () const { return m_Keys.signingPrivateKey; };
|
const uint8_t * GetSigningPrivateKey () const { return m_Keys.signingPrivateKey; };
|
||||||
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
|
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
|
||||||
|
const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
||||||
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
|
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
|
||||||
|
|
||||||
void OverrideNTCPAddress (const char * host, int port); // temporary
|
void OverrideNTCPAddress (const char * host, int port); // temporary
|
||||||
void UpdateAddress (const char * host); // called from SSU
|
void UpdateAddress (const char * host); // called from SSU
|
||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
const i2p::data::IdentityEx& GetIdentity () const { return m_Identity; };
|
||||||
const i2p::data::Identity& GetIdentity () const { return GetRouterIdentity (); };
|
|
||||||
const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); };
|
const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); };
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; };
|
const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; };
|
||||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||||
@ -45,6 +45,7 @@ namespace i2p
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
i2p::data::RouterInfo m_RouterInfo;
|
i2p::data::RouterInfo m_RouterInfo;
|
||||||
|
i2p::data::IdentityEx m_Identity; // TODO: move to RI
|
||||||
i2p::data::Keys m_Keys;
|
i2p::data::Keys m_Keys;
|
||||||
CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
|
CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
|
||||||
CryptoPP::AutoSeededRandomPool m_Rnd;
|
CryptoPP::AutoSeededRandomPool m_Rnd;
|
||||||
|
@ -507,7 +507,7 @@ namespace stream
|
|||||||
{
|
{
|
||||||
m_Keys = i2p::data::CreateRandomKeys ();
|
m_Keys = i2p::data::CreateRandomKeys ();
|
||||||
|
|
||||||
m_IdentHash = m_Keys.pub.Hash ();
|
m_Identity = m_Keys.pub;
|
||||||
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
||||||
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
||||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||||
@ -524,7 +524,7 @@ namespace stream
|
|||||||
else
|
else
|
||||||
LogPrint ("Can't open file ", fullPath);
|
LogPrint ("Can't open file ", fullPath);
|
||||||
|
|
||||||
m_IdentHash = m_Keys.pub.Hash ();
|
m_Identity = m_Keys.pub;
|
||||||
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
|
||||||
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
|
||||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||||
@ -627,7 +627,7 @@ namespace stream
|
|||||||
if (!m_SharedLocalDestination)
|
if (!m_SharedLocalDestination)
|
||||||
{
|
{
|
||||||
m_SharedLocalDestination = new StreamingDestination (m_Service);
|
m_SharedLocalDestination = new StreamingDestination (m_Service);
|
||||||
m_Destinations[m_SharedLocalDestination->GetIdentHash ()] = m_SharedLocalDestination;
|
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
||||||
}
|
}
|
||||||
LoadLocalDestinations ();
|
LoadLocalDestinations ();
|
||||||
|
|
||||||
@ -673,7 +673,7 @@ namespace stream
|
|||||||
it->path();
|
it->path();
|
||||||
#endif
|
#endif
|
||||||
auto localDestination = new StreamingDestination (m_Service, fullPath);
|
auto localDestination = new StreamingDestination (m_Service, fullPath);
|
||||||
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
m_Destinations[localDestination->GetIdentity ().GetIdentHash ()] = localDestination;
|
||||||
numDestinations++;
|
numDestinations++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,7 @@ namespace stream
|
|||||||
void HandleNextPacket (Packet * packet);
|
void HandleNextPacket (Packet * packet);
|
||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; };
|
const i2p::data::IdentityEx& GetIdentity () const { return m_Identity; };
|
||||||
const i2p::data::Identity& GetIdentity () const { return m_Keys.pub; };
|
|
||||||
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
|
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
|
||||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||||
@ -170,7 +169,7 @@ namespace stream
|
|||||||
boost::asio::io_service& m_Service;
|
boost::asio::io_service& m_Service;
|
||||||
std::map<uint32_t, Stream *> m_Streams;
|
std::map<uint32_t, Stream *> m_Streams;
|
||||||
i2p::data::PrivateKeys m_Keys;
|
i2p::data::PrivateKeys m_Keys;
|
||||||
i2p::data::IdentHash m_IdentHash;
|
i2p::data::IdentityEx m_Identity;
|
||||||
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
||||||
|
|
||||||
i2p::tunnel::TunnelPool * m_Pool;
|
i2p::tunnel::TunnelPool * m_Pool;
|
||||||
|
@ -195,7 +195,7 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
// last hop
|
// last hop
|
||||||
auto hop = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
auto hop = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
||||||
if (hop->GetIdentHash () != i2p::context.GetIdentHash ()) // outbound shouldn't be zero-hop tunnel
|
if (hop->GetIdentHash () != i2p::context.GetRouterIdentHash ()) // outbound shouldn't be zero-hop tunnel
|
||||||
{
|
{
|
||||||
prevHop = hop;
|
prevHop = hop;
|
||||||
hops.push_back (prevHop);
|
hops.push_back (prevHop);
|
||||||
|
@ -30,7 +30,7 @@ namespace tunnel
|
|||||||
const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); };
|
const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); };
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); };
|
const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); };
|
||||||
const i2p::data::LocalDestination& GetLocalDestination () const { return m_LocalDestination; };
|
const i2p::data::LocalDestination& GetLocalDestination () const { return m_LocalDestination; };
|
||||||
bool IsExploratory () const { return m_LocalDestination.GetIdentHash () == i2p::context.GetIdentHash (); };
|
bool IsExploratory () const { return GetIdentHash () == i2p::context.GetRouterIdentHash (); };
|
||||||
|
|
||||||
void CreateTunnels ();
|
void CreateTunnels ();
|
||||||
void TunnelCreated (InboundTunnel * createdTunnel);
|
void TunnelCreated (InboundTunnel * createdTunnel);
|
||||||
@ -40,7 +40,7 @@ namespace tunnel
|
|||||||
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
||||||
OutboundTunnel * GetNextOutboundTunnel (OutboundTunnel * suggested = nullptr);
|
OutboundTunnel * GetNextOutboundTunnel (OutboundTunnel * suggested = nullptr);
|
||||||
InboundTunnel * GetNextInboundTunnel (InboundTunnel * suggested = nullptr);
|
InboundTunnel * GetNextInboundTunnel (InboundTunnel * suggested = nullptr);
|
||||||
const i2p::data::IdentHash& GetIdentHash () { return m_LocalDestination.GetIdentHash (); };
|
const i2p::data::IdentHash& GetIdentHash () const { return m_LocalDestination.GetIdentity ().GetIdentHash (); };
|
||||||
|
|
||||||
void TestTunnels ();
|
void TestTunnels ();
|
||||||
void ProcessDeliveryStatus (I2NPMessage * msg);
|
void ProcessDeliveryStatus (I2NPMessage * msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user