Browse Source

Introduce missing call to request verification, so unknown address types and commands are handled properly, allow for extra socket data after the request for fast request sending, it will just be forwarded on I2PConnect

pull/138/head
Francisco Blas (klondike) Izquierdo Riera 10 years ago
parent
commit
7da95bd28a
  1. 19
      SOCKS.cpp
  2. 4
      SOCKS.h

19
SOCKS.cpp

@ -149,12 +149,12 @@ namespace proxy @@ -149,12 +149,12 @@ namespace proxy
m_state = nstate;
}
void SOCKSHandler::ValidateSOCKSRequest() {
bool SOCKSHandler::ValidateSOCKSRequest() {
if ( m_cmd != CMD_CONNECT ) {
//TODO: we need to support binds and other shit!
LogPrint(eLogError,"--- SOCKS unsupported command: ", m_cmd);
SocksRequestFailed(SOCKS5_CMD_UNSUP);
return;
return false;
}
//TODO: we may want to support other address types!
if ( m_addrtype != ADDR_DNS ) {
@ -167,14 +167,15 @@ namespace proxy @@ -167,14 +167,15 @@ namespace proxy
break;
}
SocksRequestFailed(SOCKS5_ADDR_UNSUP);
return;
return false;
}
//TODO: we may want to support other domains
if(m_addrtype == ADDR_DNS && m_address.dns.ToString().find(".i2p") == std::string::npos) {
LogPrint(eLogError,"--- SOCKS invalid hostname: ", m_address.dns.ToString());
SocksRequestFailed(SOCKS5_ADDR_UNSUP);
return;
return false;
}
return true;
}
bool SOCKSHandler::HandleData(uint8_t *sock_buff, std::size_t len)
@ -315,10 +316,10 @@ namespace proxy @@ -315,10 +316,10 @@ namespace proxy
}
sock_buff++;
len--;
if (len && m_state == DONE) {
LogPrint(eLogError,"--- SOCKS rejected because we can't handle extra data");
SocksRequestFailed(SOCKS5_GEN_FAIL);
return false;
if (m_state == DONE) {
m_remaining_data_len = len;
m_remaining_data = sock_buff;
return ValidateSOCKSRequest();
}
}
return true;
@ -363,7 +364,7 @@ namespace proxy @@ -363,7 +364,7 @@ namespace proxy
LogPrint (eLogInfo,"--- SOCKS New I2PTunnel connection");
auto connection = std::make_shared<i2p::client::I2PTunnelConnection>((i2p::client::I2PTunnel *)m_parent, m_sock, m_stream);
m_parent->AddConnection (connection);
connection->I2PConnect ();
connection->I2PConnect (m_remaining_data,m_remaining_data_len);
Done();
}
else

4
SOCKS.h

@ -94,7 +94,7 @@ namespace proxy @@ -94,7 +94,7 @@ namespace proxy
void EnterState(state nstate, uint8_t parseleft = 1);
bool HandleData(uint8_t *sock_buff, std::size_t len);
void ValidateSOCKSRequest();
bool ValidateSOCKSRequest();
void HandleSockRecv(const boost::system::error_code & ecode, std::size_t bytes_transfered);
void Done();
void Terminate();
@ -114,8 +114,10 @@ namespace proxy @@ -114,8 +114,10 @@ namespace proxy
SOCKSServer * m_parent;
boost::asio::ip::tcp::socket * m_sock;
std::shared_ptr<i2p::stream::Stream> m_stream;
uint8_t *m_remaining_data; //Data left to be sent
uint8_t m_response[7+max_socks_hostname_size];
address m_address; //Address
std::size_t m_remaining_data_len; //Size of the data left to be sent
uint32_t m_4aip; //Used in 4a requests
uint16_t m_port;
uint8_t m_command;

Loading…
Cancel
Save