diff --git a/Identity.h b/Identity.h index b9763209..2aca019b 100644 --- a/Identity.h +++ b/Identity.h @@ -119,6 +119,8 @@ namespace data public: virtual const IdentHash& GetIdentHash () const = 0; + virtual const uint8_t * GetEncryptionPrivateKey () const = 0; + virtual const uint8_t * GetEncryptionPublicKey () const = 0; virtual void UpdateLeaseSet () = 0; // LeaseSet must be updated }; } diff --git a/RouterContext.h b/RouterContext.h index cb30db38..bd5acd4e 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -32,7 +32,9 @@ namespace i2p // implements LocalDestination void UpdateLeaseSet () {}; const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); }; - + const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); }; + const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; }; + private: void CreateNewRouter (); diff --git a/Streaming.cpp b/Streaming.cpp index 34a24f69..9291235a 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "Log.h" #include "RouterInfo.h" @@ -347,6 +348,8 @@ namespace stream m_IdentHash = i2p::data::CalculateIdentHash (m_Keys.pub); m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); + CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); + dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this); } @@ -357,6 +360,8 @@ namespace stream s.read ((char *)&m_Keys, sizeof (m_Keys)); else LogPrint ("Can't open file ", fullPath); + CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); + dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this); } diff --git a/Streaming.h b/Streaming.h index cd118f17..b1706e4a 100644 --- a/Streaming.h +++ b/Streaming.h @@ -139,6 +139,8 @@ namespace stream // implements LocalDestination void UpdateLeaseSet (); const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; }; + const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; + const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; private: @@ -149,7 +151,8 @@ namespace stream std::map m_Streams; i2p::data::PrivateKeys m_Keys; i2p::data::IdentHash m_IdentHash; - + uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; + i2p::tunnel::TunnelPool * m_Pool; I2NPMessage * m_LeaseSet; diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 0b09d352..b7c22e2b 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -1,4 +1,3 @@ -#include #include "I2PEndian.h" #include "CryptoConst.h" #include "Tunnel.h" @@ -15,9 +14,6 @@ namespace tunnel TunnelPool::TunnelPool (i2p::data::LocalDestination& localDestination, int numTunnels): m_LocalDestination (localDestination), m_NumTunnels (numTunnels), m_LastOutboundTunnel (nullptr) { - CryptoPP::AutoSeededRandomPool rnd; - CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); - dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); } TunnelPool::~TunnelPool () diff --git a/TunnelPool.h b/TunnelPool.h index 3a3b67b5..c780d9b7 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -25,8 +25,8 @@ namespace tunnel 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; }; + const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); }; + const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); }; void CreateTunnels (); void TunnelCreated (InboundTunnel * createdTunnel); @@ -47,7 +47,6 @@ namespace tunnel private: - uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; i2p::data::LocalDestination& m_LocalDestination; int m_NumTunnels; std::set m_InboundTunnels; // recent tunnel appears first