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 @@ -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 ()

3
RouterContext.h

@ -20,8 +20,6 @@ namespace i2p @@ -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 @@ -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;
};

2
Streaming.cpp

@ -377,7 +377,7 @@ namespace stream @@ -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

20
TunnelPool.cpp

@ -1,15 +1,21 @@ @@ -1,15 +1,21 @@
#include <cryptopp/dh.h>
#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 @@ -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<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
@ -63,7 +69,7 @@ namespace tunnel @@ -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);

8
TunnelPool.h

@ -20,9 +20,12 @@ namespace tunnel @@ -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 @@ -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<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first

Loading…
Cancel
Save