From d7084e379ff3b10f4a9168ce0cc61d099e708a98 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 15 Mar 2014 22:02:33 -0400 Subject: [PATCH] create LeaseSet encryption key per tunnel pool --- RouterContext.cpp | 4 ---- RouterContext.h | 3 --- Streaming.cpp | 2 +- TunnelPool.cpp | 20 +++++++++++++------- TunnelPool.h | 8 ++++++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/RouterContext.cpp b/RouterContext.cpp index cb8eb355..bde075ad 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -14,10 +14,6 @@ namespace i2p if (!Load ()) CreateNewRouter (); 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 () diff --git a/RouterContext.h b/RouterContext.h index 092c50b5..abbc3775 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -20,8 +20,6 @@ namespace i2p i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; }; const uint8_t * GetPrivateKey () const { return m_Keys.privateKey; }; 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 (); }; CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; @@ -42,7 +40,6 @@ namespace i2p i2p::data::RouterInfo m_RouterInfo; i2p::data::Keys m_Keys; CryptoPP::DSA::PrivateKey m_SigningPrivateKey; - uint8_t m_LeaseSetPublicKey[256], m_LeaseSetPrivateKey[256]; CryptoPP::AutoSeededRandomPool m_Rnd; }; diff --git a/Streaming.cpp b/Streaming.cpp index b7282145..6f623f4a 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -377,7 +377,7 @@ namespace stream size_t size = 0; memcpy (buf + size, &m_Identity, sizeof (m_Identity)); size += sizeof (m_Identity); // destination - memcpy (buf + size, i2p::context.GetLeaseSetPublicKey (), 256); + memcpy (buf + size, m_Pool->GetEncryptionPublicKey (), 256); size += 256; // encryption key memset (buf + size, 0, 128); size += 128; // signing key diff --git a/TunnelPool.cpp b/TunnelPool.cpp index d9d38354..37854db2 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -1,15 +1,21 @@ +#include +#include "CryptoConst.h" #include "Tunnel.h" #include "NetDb.h" #include "Timestamp.h" +#include "RouterContext.h" #include "TunnelPool.h" namespace i2p { namespace tunnel { - TunnelPool::TunnelPool (i2p::data::LocalDestination * owner, int numTunnels): - m_Owner (owner), m_NumTunnels (numTunnels) + TunnelPool::TunnelPool (i2p::data::LocalDestination * localDestination, int 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 () @@ -21,15 +27,15 @@ namespace tunnel void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel) { m_InboundTunnels.insert (createdTunnel); - if (m_Owner) - m_Owner->UpdateLeaseSet (); + if (m_LocalDestination) + m_LocalDestination->UpdateLeaseSet (); } void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel) { m_InboundTunnels.erase (expiredTunnel); - if (m_Owner) - m_Owner->UpdateLeaseSet (); + if (m_LocalDestination) + m_LocalDestination->UpdateLeaseSet (); } std::vector TunnelPool::GetInboundTunnels (int num) const @@ -63,7 +69,7 @@ namespace tunnel { firstHop, secondHop - // TODO: swithc to 3-hops later + // TODO: switch to 3-hops later /*i2p::data::netdb.GetRandomRouter (secondHop) */ }), outboundTunnel); diff --git a/TunnelPool.h b/TunnelPool.h index 988e83c0..8dad4051 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -20,9 +20,12 @@ namespace tunnel { public: - TunnelPool (i2p::data::LocalDestination * owner, int numTunnels = 5); + TunnelPool (i2p::data::LocalDestination * localDestination, int numTunnels = 5); ~TunnelPool (); + const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; + const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; + void CreateTunnels (); void TunnelCreated (InboundTunnel * createdTunnel); void TunnelExpired (InboundTunnel * expiredTunnel); @@ -34,7 +37,8 @@ namespace tunnel private: - i2p::data::LocalDestination * m_Owner; + uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; + i2p::data::LocalDestination * m_LocalDestination; int m_NumTunnels; std::set m_InboundTunnels; // recent tunnel appears first