[socks] changes

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2022-01-04 22:26:56 +03:00
parent ab5c966fdf
commit a93a54590f
3 changed files with 36 additions and 9 deletions

View File

@ -483,8 +483,10 @@ namespace proxy {
void HTTPReqHandler::HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec)
{
if(!ec) {
if(m_RequestURL.host.size() > 255) {
if(!ec)
{
if(m_RequestURL.host.size() > 255)
{
GenericProxyError(tr("hostname too long"), m_RequestURL.host);
return;
}
@ -512,7 +514,9 @@ namespace proxy {
reqsize += host.size();
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));
} 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)

View File

@ -243,7 +243,7 @@ namespace client
LogPrint(eLogDebug, "TCPIPPipe: Downstream: ", (int) bytes_transfered, " bytes received");
if (ecode)
{
LogPrint(eLogError, "TCPIPPipe: Downstream read error:" , ecode.message());
LogPrint(eLogError, "TCPIPPipe: Downstream read error: " , ecode.message());
if (ecode != boost::asio::error::operation_aborted)
Terminate();
} else {
@ -256,7 +256,7 @@ namespace client
void TCPIPPipe::HandleDownstreamWrite(const boost::system::error_code & ecode) {
if (ecode)
{
LogPrint(eLogError, "TCPIPPipe: Downstream write error:" , ecode.message());
LogPrint(eLogError, "TCPIPPipe: Downstream write error: " , ecode.message());
if (ecode != boost::asio::error::operation_aborted)
Terminate();
}
@ -267,7 +267,7 @@ namespace client
void TCPIPPipe::HandleUpstreamWrite(const boost::system::error_code & ecode) {
if (ecode)
{
LogPrint(eLogError, "TCPIPPipe: Upstream write error:" , ecode.message());
LogPrint(eLogError, "TCPIPPipe: Upstream write error: " , ecode.message());
if (ecode != boost::asio::error::operation_aborted)
Terminate();
}
@ -280,7 +280,7 @@ namespace client
LogPrint(eLogDebug, "TCPIPPipe: Upstream ", (int)bytes_transfered, " bytes received");
if (ecode)
{
LogPrint(eLogError, "TCPIPPipe: Upstream read error:" , ecode.message());
LogPrint(eLogError, "TCPIPPipe: Upstream read error: " , ecode.message());
if (ecode != boost::asio::error::operation_aborted)
Terminate();
} else {

View File

@ -290,7 +290,30 @@ namespace proxy
}
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
@ -745,7 +768,7 @@ namespace proxy
{
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);
}
else