Browse Source

create LeaseSet encryption key per tunnel pool

pull/46/head
orignal 11 years ago
parent
commit
d7084e379f
  1. 4
      RouterContext.cpp
  2. 3
      RouterContext.h
  3. 2
      Streaming.cpp
  4. 20
      TunnelPool.cpp
  5. 8
      TunnelPool.h

4
RouterContext.cpp

@ -14,10 +14,6 @@ namespace i2p
if (!Load ()) if (!Load ())
CreateNewRouter (); CreateNewRouter ();
Save (); Save ();
// we generate LeaseSet at every start-up
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(m_Rnd, m_LeaseSetPrivateKey, m_LeaseSetPublicKey);
} }
void RouterContext::CreateNewRouter () void RouterContext::CreateNewRouter ()

3
RouterContext.h

@ -20,8 +20,6 @@ namespace i2p
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; }; i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
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 uint8_t * GetLeaseSetPrivateKey () const { return m_LeaseSetPrivateKey; };
const uint8_t * GetLeaseSetPublicKey () const { return m_LeaseSetPublicKey; };
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); }; const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
@ -42,7 +40,6 @@ namespace i2p
i2p::data::RouterInfo m_RouterInfo; i2p::data::RouterInfo m_RouterInfo;
i2p::data::Keys m_Keys; i2p::data::Keys m_Keys;
CryptoPP::DSA::PrivateKey m_SigningPrivateKey; CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
uint8_t m_LeaseSetPublicKey[256], m_LeaseSetPrivateKey[256];
CryptoPP::AutoSeededRandomPool m_Rnd; CryptoPP::AutoSeededRandomPool m_Rnd;
}; };

2
Streaming.cpp

@ -377,7 +377,7 @@ namespace stream
size_t size = 0; size_t size = 0;
memcpy (buf + size, &m_Identity, sizeof (m_Identity)); memcpy (buf + size, &m_Identity, sizeof (m_Identity));
size += sizeof (m_Identity); // destination size += sizeof (m_Identity); // destination
memcpy (buf + size, i2p::context.GetLeaseSetPublicKey (), 256); memcpy (buf + size, m_Pool->GetEncryptionPublicKey (), 256);
size += 256; // encryption key size += 256; // encryption key
memset (buf + size, 0, 128); memset (buf + size, 0, 128);
size += 128; // signing key size += 128; // signing key

20
TunnelPool.cpp

@ -1,15 +1,21 @@
#include <cryptopp/dh.h>
#include "CryptoConst.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "NetDb.h" #include "NetDb.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "RouterContext.h"
#include "TunnelPool.h" #include "TunnelPool.h"
namespace i2p namespace i2p
{ {
namespace tunnel namespace tunnel
{ {
TunnelPool::TunnelPool (i2p::data::LocalDestination * owner, int numTunnels): TunnelPool::TunnelPool (i2p::data::LocalDestination * localDestination, int numTunnels):
m_Owner (owner), m_NumTunnels (numTunnels) m_LocalDestination (localDestination), m_NumTunnels (numTunnels)
{ {
CryptoPP::AutoSeededRandomPool rnd;
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
} }
TunnelPool::~TunnelPool () TunnelPool::~TunnelPool ()
@ -21,15 +27,15 @@ namespace tunnel
void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel) void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel)
{ {
m_InboundTunnels.insert (createdTunnel); m_InboundTunnels.insert (createdTunnel);
if (m_Owner) if (m_LocalDestination)
m_Owner->UpdateLeaseSet (); m_LocalDestination->UpdateLeaseSet ();
} }
void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel) void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel)
{ {
m_InboundTunnels.erase (expiredTunnel); m_InboundTunnels.erase (expiredTunnel);
if (m_Owner) if (m_LocalDestination)
m_Owner->UpdateLeaseSet (); m_LocalDestination->UpdateLeaseSet ();
} }
std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
@ -63,7 +69,7 @@ namespace tunnel
{ {
firstHop, firstHop,
secondHop secondHop
// TODO: swithc to 3-hops later // TODO: switch to 3-hops later
/*i2p::data::netdb.GetRandomRouter (secondHop) */ /*i2p::data::netdb.GetRandomRouter (secondHop) */
}), }),
outboundTunnel); outboundTunnel);

8
TunnelPool.h

@ -20,9 +20,12 @@ namespace tunnel
{ {
public: public:
TunnelPool (i2p::data::LocalDestination * owner, int numTunnels = 5); TunnelPool (i2p::data::LocalDestination * localDestination, int numTunnels = 5);
~TunnelPool (); ~TunnelPool ();
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
void CreateTunnels (); void CreateTunnels ();
void TunnelCreated (InboundTunnel * createdTunnel); void TunnelCreated (InboundTunnel * createdTunnel);
void TunnelExpired (InboundTunnel * expiredTunnel); void TunnelExpired (InboundTunnel * expiredTunnel);
@ -34,7 +37,8 @@ namespace tunnel
private: private:
i2p::data::LocalDestination * m_Owner; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
i2p::data::LocalDestination * m_LocalDestination;
int m_NumTunnels; int m_NumTunnels;
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first

Loading…
Cancel
Save