Skip to content

Commit

Permalink
NTCP2 proxy with authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 11, 2021
1 parent 744b251 commit 880d1a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions libi2pd/NTCP2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ProxyAddress = addr;
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)
Expand Down Expand Up @@ -1538,8 +1541,10 @@ namespace transport
if(ep.address ().is_v6 ())
req.uri = "[" + ep.address ().to_string() + "]:" + std::to_string(ep.port ());
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;
std::ostream out(&writebuff);
out << req.to_string();
Expand Down
4 changes: 2 additions & 2 deletions libi2pd/NTCP2.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace transport
void Connect(std::shared_ptr<NTCP2Session> conn);

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);

Expand All @@ -271,7 +271,7 @@ namespace transport
std::list<std::shared_ptr<NTCP2Session> > m_PendingIncomingSessions;

ProxyType m_ProxyType;
std::string m_ProxyAddress;
std::string m_ProxyAddress, m_ProxyAuthorization;
uint16_t m_ProxyPort;
boost::asio::ip::tcp::resolver m_Resolver;
std::unique_ptr<boost::asio::ip::tcp::endpoint> m_ProxyEndpoint;
Expand Down
2 changes: 1 addition & 1 deletion libi2pd/Transports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace transport
if (proxyurl.schema == "http")
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);
}
else
Expand Down

0 comments on commit 880d1a7

Please sign in to comment.