Browse Source

NTCP2 proxy with authorization

pull/1641/head
orignal 4 years ago
parent
commit
880d1a7ccd
  1. 7
      libi2pd/NTCP2.cpp
  2. 4
      libi2pd/NTCP2.h
  3. 2
      libi2pd/Transports.cpp

7
libi2pd/NTCP2.cpp

@ -1465,11 +1465,14 @@ namespace transport
}); });
} }
void NTCP2Server::UseProxy(ProxyType proxytype, const std::string & addr, uint16_t port) void NTCP2Server::UseProxy(ProxyType proxytype, const std::string& addr, uint16_t port,
const std::string& user, const std::string& pass)
{ {
m_ProxyType = proxytype; m_ProxyType = proxytype;
m_ProxyAddress = addr; m_ProxyAddress = addr;
m_ProxyPort = port; m_ProxyPort = port;
if ((!user.empty () || !pass.empty ()) && m_ProxyType == eHTTPProxy )
m_ProxyAuthorization = "Basic " + i2p::data::ToBase64Standard (user + ":" + pass);
} }
void NTCP2Server::HandleProxyConnect(const boost::system::error_code& ecode, std::shared_ptr<NTCP2Session> conn, std::shared_ptr<boost::asio::deadline_timer> timer) void NTCP2Server::HandleProxyConnect(const boost::system::error_code& ecode, std::shared_ptr<NTCP2Session> conn, std::shared_ptr<boost::asio::deadline_timer> timer)
@ -1539,6 +1542,8 @@ namespace transport
req.uri = "[" + ep.address ().to_string() + "]:" + std::to_string(ep.port ()); req.uri = "[" + ep.address ().to_string() + "]:" + std::to_string(ep.port ());
else else
req.uri = ep.address ().to_string() + ":" + std::to_string(ep.port ()); req.uri = ep.address ().to_string() + ":" + std::to_string(ep.port ());
if (!m_ProxyAuthorization.empty ())
req.AddHeader("Proxy-Authorization", m_ProxyAuthorization);
boost::asio::streambuf writebuff; boost::asio::streambuf writebuff;
std::ostream out(&writebuff); std::ostream out(&writebuff);

4
libi2pd/NTCP2.h

@ -246,7 +246,7 @@ namespace transport
void Connect(std::shared_ptr<NTCP2Session> conn); void Connect(std::shared_ptr<NTCP2Session> conn);
bool UsingProxy() const { return m_ProxyType != eNoProxy; }; bool UsingProxy() const { return m_ProxyType != eNoProxy; };
void UseProxy(ProxyType proxy, const std::string & address, uint16_t port); void UseProxy(ProxyType proxy, const std::string& address, uint16_t port, const std::string& user, const std::string& pass);
void SetLocalAddress (const boost::asio::ip::address& localAddress); void SetLocalAddress (const boost::asio::ip::address& localAddress);
@ -271,7 +271,7 @@ namespace transport
std::list<std::shared_ptr<NTCP2Session> > m_PendingIncomingSessions; std::list<std::shared_ptr<NTCP2Session> > m_PendingIncomingSessions;
ProxyType m_ProxyType; ProxyType m_ProxyType;
std::string m_ProxyAddress; std::string m_ProxyAddress, m_ProxyAuthorization;
uint16_t m_ProxyPort; uint16_t m_ProxyPort;
boost::asio::ip::tcp::resolver m_Resolver; boost::asio::ip::tcp::resolver m_Resolver;
std::unique_ptr<boost::asio::ip::tcp::endpoint> m_ProxyEndpoint; std::unique_ptr<boost::asio::ip::tcp::endpoint> m_ProxyEndpoint;

2
libi2pd/Transports.cpp

@ -188,7 +188,7 @@ namespace transport
if (proxyurl.schema == "http") if (proxyurl.schema == "http")
proxytype = NTCP2Server::eHTTPProxy; proxytype = NTCP2Server::eHTTPProxy;
m_NTCP2Server->UseProxy(proxytype, proxyurl.host, proxyurl.port); m_NTCP2Server->UseProxy(proxytype, proxyurl.host, proxyurl.port, proxyurl.user, proxyurl.pass);
i2p::context.SetStatus (eRouterStatusProxy); i2p::context.SetStatus (eRouterStatusProxy);
} }
else else

Loading…
Cancel
Save