Browse Source

[socks] changes

Signed-off-by: R4SAS <r4sas@i2pmail.org>
socks5
R4SAS 3 years ago
parent
commit
a93a54590f
  1. 10
      libi2pd_client/HTTPProxy.cpp
  2. 27
      libi2pd_client/SOCKS.cpp

10
libi2pd_client/HTTPProxy.cpp

@ -483,8 +483,10 @@ namespace proxy {
void HTTPReqHandler::HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec) void HTTPReqHandler::HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec)
{ {
if(!ec) { if(!ec)
if(m_RequestURL.host.size() > 255) { {
if(m_RequestURL.host.size() > 255)
{
GenericProxyError(tr("hostname too long"), m_RequestURL.host); GenericProxyError(tr("hostname too long"), m_RequestURL.host);
return; return;
} }
@ -512,7 +514,9 @@ namespace proxy {
reqsize += host.size(); reqsize += host.size();
m_socks_buf[++reqsize] = 0; m_socks_buf[++reqsize] = 0;
boost::asio::async_write(*m_proxysock, boost::asio::buffer(m_socks_buf, reqsize), boost::asio::transfer_all(), std::bind(&HTTPReqHandler::HandleSocksProxySendHandshake, this, std::placeholders::_1, std::placeholders::_2)); boost::asio::async_write(*m_proxysock, boost::asio::buffer(m_socks_buf, reqsize), boost::asio::transfer_all(), std::bind(&HTTPReqHandler::HandleSocksProxySendHandshake, this, std::placeholders::_1, std::placeholders::_2));
} else GenericProxyError(tr("cannot connect to upstream socks proxy"), ec.message()); }
else
GenericProxyError(tr("cannot connect to upstream socks proxy"), ec.message());
} }
void HTTPReqHandler::HandleSocksProxySendHandshake(const boost::system::error_code & ec, std::size_t bytes_transferred) void HTTPReqHandler::HandleSocksProxySendHandshake(const boost::system::error_code & ec, std::size_t bytes_transferred)

27
libi2pd_client/SOCKS.cpp

@ -290,7 +290,30 @@ namespace proxy
} }
else else
{ {
return GenerateSOCKS5Response(SOCKS5_GEN_FAIL, m_addrtype, m_address, m_port); // dirty hack, SOCKS5_GEN_FAIL == 1, that's a "establish a TCP/IP stream connection" command upstreamRequestSize = 6; // header + port
m_upstream_request[0] = '\x05'; // version
m_upstream_request[1] = '\x01'; // request tcp socket opening
m_upstream_request[2] = '\x00'; // reserved
m_upstream_request[3] = m_addrtype; // address type
switch (m_addrtype)
{
case ADDR_IPV4:
upstreamRequestSize += 4;
htobe32buf(m_upstream_request + 4, m_address.ip);
htobe16buf(m_upstream_request + upstreamRequestSize - 2, m_port);
break;
case ADDR_IPV6:
upstreamRequestSize += 16;
memcpy(m_upstream_request + 4, m_address.ipv6, 16);
htobe16buf(m_upstream_request + upstreamRequestSize - 2, m_port);
break;
case ADDR_DNS:
upstreamRequestSize += (1 + m_address.dns.size); // name length + resolved address
m_upstream_request[4] = m_address.dns.size;
memcpy(m_upstream_request + 5, m_address.dns.value, m_address.dns.size); // 4 - header + 1 - record size
htobe16buf(m_upstream_request + upstreamRequestSize - 2, m_port);
break;
}
} }
} }
else if (version == 4) // SOCKS4a else if (version == 4) // SOCKS4a
@ -745,7 +768,7 @@ namespace proxy
{ {
if (m_upstream_response[0] == '\x05' && m_upstream_response[1] != AUTH_UNACCEPTABLE) if (m_upstream_response[0] == '\x05' && m_upstream_response[1] != AUTH_UNACCEPTABLE)
{ {
LogPrint(eLogInfo, "SOCKS: upstream SOCKS5 proxy: success greeting"); LogPrint(eLogInfo, "SOCKS: upstream SOCKS5 proxy: success greeting, sending connection request");
SendUpstreamRequest(m_socksv, false); SendUpstreamRequest(m_socksv, false);
} }
else else

Loading…
Cancel
Save