From b3e389a67c7576911270ecc573d6a5af16e1aee3 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 26 Aug 2014 14:56:00 -0400 Subject: [PATCH] server tunnel parameters --- Daemon.cpp | 22 +++++++++++++++++++++- Identity.h | 11 ++++++++++- README.md | 4 +++- Streaming.cpp | 33 +++++++++++++++++++++++++++++---- Streaming.h | 4 +++- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 234f9d00..05462084 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -26,18 +26,20 @@ namespace i2p { public: Daemon_Singleton_Private() : httpServer(nullptr), httpProxy(nullptr), - socksProxy(nullptr), ircTunnel(nullptr) { }; + socksProxy(nullptr), ircTunnel(nullptr), serverTunnel (nullptr) { }; ~Daemon_Singleton_Private() { delete httpServer; delete httpProxy; delete socksProxy; delete ircTunnel; + delete serverTunnel; }; i2p::util::HTTPServer *httpServer; i2p::proxy::HTTPProxy *httpProxy; i2p::proxy::SOCKSProxy *socksProxy; i2p::stream::I2PClientTunnel * ircTunnel; + i2p::stream::I2PServerTunnel * serverTunnel; }; Daemon_Singleton::Daemon_Singleton() : running(1), d(*new Daemon_Singleton_Private()) {}; @@ -117,6 +119,16 @@ namespace i2p d.ircTunnel->Start (); LogPrint("IRC tunnel started"); } + std::string eepKeys = i2p::util::config::GetArg("-eepkeys", ""); + if (eepKeys.length () > 0) // eepkeys file is presented + { + auto localDestination = i2p::stream::LoadLocalDestination (eepKeys); + d.serverTunnel = new i2p::stream::I2PServerTunnel (d.socksProxy->GetService (), + i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80), + localDestination->GetIdentHash ()); + d.serverTunnel->Start (); + LogPrint("Server tunnel started"); + } return true; } @@ -147,6 +159,14 @@ namespace i2p d.ircTunnel = nullptr; LogPrint("IRC tunnel stoped"); } + if (d.serverTunnel) + { + d.serverTunnel->Stop (); + delete d.serverTunnel; + d.serverTunnel = nullptr; + LogPrint("Server tunnel stoped"); + } + StopLog (); delete d.socksProxy; d.socksProxy = nullptr; diff --git a/Identity.h b/Identity.h index 9ff2bcfa..f2ccdc82 100644 --- a/Identity.h +++ b/Identity.h @@ -46,6 +46,14 @@ namespace data return std::string (str); } + std::string ToBase32 () const + { + char str[sz*2]; + int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2); + str[l] = 0; + return std::string (str); + } + private: union // 8 bytes alignment @@ -155,7 +163,8 @@ namespace data const uint8_t * GetPrivateKey () const { return m_PrivateKey; }; const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; }; void Sign (const uint8_t * buf, int len, uint8_t * signature) const; - + + size_t GetFullLen () const { return m_Public.GetFullLen () + 256 + m_Public.GetSignatureLen ()/2; }; size_t FromBuffer (const uint8_t * buf, size_t len); size_t ToBuffer (uint8_t * buf, size_t len) const; diff --git a/README.md b/README.md index 65bc91e4..be42a06d 100644 --- a/README.md +++ b/README.md @@ -53,5 +53,7 @@ Options * --socksproxyport= - The port to listen on (SOCKS Proxy) * --ircport= - The local port of IRC tunnel to listen on. 6668 by default * --ircdest= - I2P destination address of IRC server. For example irc.postman.i2p - +* --eepkeys= - File name containing destination keys. For example privKeys.dat +* --eephost= - Address incoming trafic forward to. 127.0.0.1 by default +* --eepport= - Port incoming trafic forward to. 80 by default diff --git a/Streaming.cpp b/Streaming.cpp index efc64585..e5205313 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -527,9 +527,22 @@ namespace stream s.read ((char *)buf, len); m_Keys.FromBuffer (buf, len); delete[] buf; + LogPrint ("Local address ", m_Keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p loaded"); } else - LogPrint ("Can't open file ", fullPath); + { + LogPrint ("Can't open file ", fullPath, " Creating new one"); + // new eepsites use ECDSA + m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256); + std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out); + size_t len = m_Keys.GetFullLen (); + uint8_t * buf = new uint8_t[len]; + len = m_Keys.ToBuffer (buf, len); + f.write ((char *)buf, len); + delete[] buf; + + LogPrint ("New private keys file ", fullPath, " for ", m_Keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p created"); + } CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); @@ -627,7 +640,7 @@ namespace stream m_SharedLocalDestination = new StreamingDestination (m_Service); m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination; } - LoadLocalDestinations (); + // LoadLocalDestinations (); m_IsRunning = true; m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this)); @@ -671,7 +684,7 @@ namespace stream it->path(); #endif auto localDestination = new StreamingDestination (m_Service, fullPath); - m_Destinations[localDestination->GetIdentity ().GetIdentHash ()] = localDestination; + m_Destinations[localDestination->GetIdentHash ()] = localDestination; numDestinations++; } } @@ -679,6 +692,13 @@ namespace stream LogPrint (numDestinations, " local destinations loaded"); } + StreamingDestination * StreamingDestinations::LoadLocalDestination (const std::string& filename) + { + auto localDestination = new StreamingDestination (m_Service, i2p::util::filesystem::GetFullPath (filename)); + m_Destinations[localDestination->GetIdentHash ()] = localDestination; + return localDestination; + } + Stream * StreamingDestinations::CreateClientStream (const i2p::data::LeaseSet& remote) { if (!m_SharedLocalDestination) return nullptr; @@ -722,7 +742,7 @@ namespace stream return it->second; return nullptr; } - + Stream * CreateStream (const i2p::data::LeaseSet& remote) { return destinations.CreateClientStream (remote); @@ -753,6 +773,11 @@ namespace stream return destinations.FindLocalDestination (destination); } + StreamingDestination * LoadLocalDestination (const std::string& filename) + { + return destinations.LoadLocalDestination (filename); + } + void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len) { uint32_t length = be32toh (*(uint32_t *)buf); diff --git a/Streaming.h b/Streaming.h index 544a1090..c0dbd5e9 100644 --- a/Streaming.h +++ b/Streaming.h @@ -193,6 +193,7 @@ namespace stream void DeleteStream (Stream * stream); StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; }; StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const; + StreamingDestination * LoadLocalDestination (const std::string& filename); private: @@ -216,7 +217,8 @@ namespace stream void StartStreaming (); void StopStreaming (); StreamingDestination * GetSharedLocalDestination (); - StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination); + StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination); + StreamingDestination * LoadLocalDestination (const std::string& filename); // assuming data is I2CP message void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len);