Browse Source

use ECDSA P256 for client I2P tunnels

pull/102/head
orignal 10 years ago
parent
commit
ecb1fd720d
  1. 16
      Destination.cpp
  2. 6
      Destination.h
  3. 3
      I2PTunnel.cpp

16
Destination.cpp

@ -11,11 +11,11 @@ namespace i2p
{ {
namespace stream namespace stream
{ {
StreamingDestination::StreamingDestination (bool isPublic): StreamingDestination::StreamingDestination (bool isPublic, i2p::data::SigningKeyType sigType):
m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr), m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr),
m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic) m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic)
{ {
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (/*i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256*/); // uncomment for ECDSA m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType);
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
@ -42,7 +42,7 @@ namespace stream
else else
{ {
LogPrint ("Can't open file ", fullPath, " Creating new one"); LogPrint ("Can't open file ", fullPath, " Creating new one");
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (/*i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256*/); m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (i2p::data::SIGNING_KEY_TYPE_DSA_SHA1);
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out); std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
size_t len = m_Keys.GetFullLen (); size_t len = m_Keys.GetFullLen ();
uint8_t * buf = new uint8_t[len]; uint8_t * buf = new uint8_t[len];
@ -359,7 +359,7 @@ namespace stream
{ {
if (!m_SharedLocalDestination) if (!m_SharedLocalDestination)
{ {
m_SharedLocalDestination = new StreamingDestination (false); // non-public m_SharedLocalDestination = new StreamingDestination (false, i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // non-public, DSA
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination; m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
m_SharedLocalDestination->Start (); m_SharedLocalDestination->Start ();
} }
@ -409,9 +409,9 @@ namespace stream
return localDestination; return localDestination;
} }
StreamingDestination * StreamingDestinations::CreateNewLocalDestination (bool isPublic) StreamingDestination * StreamingDestinations::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
{ {
auto localDestination = new StreamingDestination (isPublic); auto localDestination = new StreamingDestination (isPublic, sigType);
std::unique_lock<std::mutex> l(m_DestinationsMutex); std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[localDestination->GetIdentHash ()] = localDestination; m_Destinations[localDestination->GetIdentHash ()] = localDestination;
localDestination->Start (); localDestination->Start ();
@ -499,9 +499,9 @@ namespace stream
return destinations.GetSharedLocalDestination (); return destinations.GetSharedLocalDestination ();
} }
StreamingDestination * CreateNewLocalDestination (bool isPublic) StreamingDestination * CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
{ {
return destinations.CreateNewLocalDestination (isPublic); return destinations.CreateNewLocalDestination (isPublic, sigType);
} }
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic) StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)

6
Destination.h

@ -18,7 +18,7 @@ namespace stream
{ {
public: public:
StreamingDestination (bool isPublic); StreamingDestination (bool isPublic, i2p::data::SigningKeyType sigType);
StreamingDestination (const std::string& fullPath, bool isPublic); StreamingDestination (const std::string& fullPath, bool isPublic);
StreamingDestination (const i2p::data::PrivateKeys& keys, bool isPublic); StreamingDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
~StreamingDestination (); ~StreamingDestination ();
@ -103,7 +103,7 @@ namespace stream
Stream * CreateClientStream (const i2p::data::LeaseSet& remote); Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
void DeleteStream (Stream * stream); void DeleteStream (Stream * stream);
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; }; StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
StreamingDestination * CreateNewLocalDestination (bool isPublic); StreamingDestination * CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType);
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic); StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
void DeleteLocalDestination (StreamingDestination * destination); void DeleteLocalDestination (StreamingDestination * destination);
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const; StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
@ -130,7 +130,7 @@ namespace stream
void StartStreaming (); void StartStreaming ();
void StopStreaming (); void StopStreaming ();
StreamingDestination * GetSharedLocalDestination (); StreamingDestination * GetSharedLocalDestination ();
StreamingDestination * CreateNewLocalDestination (bool isPublic = true); StreamingDestination * CreateNewLocalDestination (bool isPublic = true, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // transient
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true); StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
void DeleteLocalDestination (StreamingDestination * destination); void DeleteLocalDestination (StreamingDestination * destination);
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination); StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);

3
I2PTunnel.cpp

@ -145,7 +145,8 @@ namespace stream
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination,
int port, StreamingDestination * localDestination): int port, StreamingDestination * localDestination):
I2PTunnel (service, localDestination ? localDestination : GetSharedLocalDestination ()), I2PTunnel (service, localDestination ? localDestination :
CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256)),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)), m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Timer (service), m_Destination (destination), m_DestinationIdentHash (nullptr), m_Timer (service), m_Destination (destination), m_DestinationIdentHash (nullptr),
m_RemoteLeaseSet (nullptr) m_RemoteLeaseSet (nullptr)

Loading…
Cancel
Save