Asio Extensions
Additional functionality built on top of (Boost.)Asio

SOCKS client implementation. More...

template<typename Socket , typename DynamicBuffer , typename GreetHandler >
void_or_deduced asioext::socks::async_greet (Socket &socket, const auth_method *auth_methods, std::size_t num_auth_methods, DynamicBuffer &&buffer, GreetHandler &&handler)
 Asynchronously perform a SOCKS 5 greeting with the remote SOCKS server. More...
 
template<typename Socket , typename DynamicBuffer , typename LoginHandler >
void_or_deduced asioext::socks::async_login (Socket &socket, const std::string &username, const std::string &password, DynamicBuffer &&buffer, LoginHandler &&handler)
 Asynchronously attempt a login on the remote SOCKS 5 server. More...
 
template<typename Socket , typename DynamicBuffer , typename ExecuteHandler >
void_or_deduced asioext::socks::async_execute (Socket &socket, command cmd, const asio::ip::tcp::endpoint &remote, DynamicBuffer &&buffer, ExecuteHandler &&handler)
 Asynchronously attempt to execute the given command. More...
 
template<typename Socket , typename DynamicBuffer , typename ExecuteHandler >
void_or_deduced asioext::socks::async_execute (Socket &socket, command cmd, const std::string &remote, uint16_t port, DynamicBuffer &&buffer, ExecuteHandler &&handler)
 Asynchronously attempt to execute the given command. More...
 
enum  asioext::socks::command : uint8_t { asioext::socks::command::connect = 1, asioext::socks::command::bind = 2, asioext::socks::command::bind_udp = 3 }
 SOCKS commands. More...
 
enum  asioext::socks::version : uint8_t { asioext::socks::version::v4, asioext::socks::version::v5 }
 SOCKS versions. More...
 
enum  asioext::socks::auth_method : uint8_t { asioext::socks::auth_method::none = 0, asioext::socks::auth_method::gssapi = 1, asioext::socks::auth_method::username_password = 2, asioext::socks::auth_method::no_acceptable = 0xff }
 SOCKS login authentication methods. More...
 
enum  asioext::socks::error {
  asioext::socks::error::none = 0, asioext::socks::error::invalid_version, asioext::socks::error::no_acceptable_auth_method, asioext::socks::error::invalid_auth_version,
  asioext::socks::error::login_failed, asioext::socks::error::command_not_supported
}
 SOCKS-specific error codes. More...
 
const error_categoryasioext::socks::get_error_category () noexcept
 Get the error_category for error. More...
 
error_code asioext::socks::make_error_code (error e) noexcept
 

Detailed Description

SOCKS client implementation.

This module contains functions to establish a SOCKS client session on a stream socket.

Enumeration Type Documentation

◆ auth_method

enum asioext::socks::auth_method : uint8_t
strong

SOCKS login authentication methods.

This enum contains the authentication methods listed in the protocol specification.

Enumerator
none 

No authentication.

If sent by the client, indicates that the client supports/allows anonymous access to a SOCKS server.

gssapi 

GSSAPI authentication.

Note
There is currently no public function that handles the login challenge for this authentication type.
username_password 

Username + Password authentication.

Indicates that the client wishes to authenticate the user with a username and password pair.

See also
async_login
no_acceptable 

Server response if no acceptable method was given.

This special enum value is used in case the server rejects all authentication methods it was given.

◆ command

enum asioext::socks::command : uint8_t
strong

SOCKS commands.

This enum contains the supported SOCKS commands the client can ask the server to execute.

Enumerator
connect 

Establish and proxy a TCP connection to the specified target host.

bind 

Bind to the specified port and listen for connections.

bind_udp 

Associate an UDP port.

◆ error

enum asioext::socks::error
strong

SOCKS-specific error codes.

Enumerator
none 

No error.

invalid_version 

SOCKS version mismatch between server and client.

Used in case the client receives a packet with a different

no_acceptable_auth_method 

Server supports none of our authentication methods.

Used in case the server rejects all of our proposed authentication methods

See also
async_greet
invalid_auth_version 

Authentication type version mismatch between client and server.

The version of the agreed-on authentication scheme is different on the server.

login_failed 

The server rejected our login attempt.

command_not_supported 

The SOCKS command we sent was rejected.

The server doesn't understand the command we sent.

◆ version

enum asioext::socks::version : uint8_t
strong

SOCKS versions.

This enum contains constants representing the different SOCKS versions.

Enumerator
v4 
v5 

Function Documentation

◆ async_execute() [1/2]

template<typename Socket , typename DynamicBuffer , typename ExecuteHandler >
void_or_deduced asioext::socks::async_execute ( Socket &  socket,
command  cmd,
const asio::ip::tcp::endpoint &  remote,
DynamicBuffer &&  buffer,
ExecuteHandler &&  handler 
)

Asynchronously attempt to execute the given command.

This function asynchronously executes the given SOCKS command. The following commands are supported by a SOCKS 5 server:

  • connect: Establish a connection to the given remote endpoint. Any data sent/received on the socket after successful command execution belongs to the proxied connection.
Parameters
socketThe connected socket. The remote endpoint needs to be a successfully greeted SOCKS 5 proxy.
cmdThe command to execute.
remoteThe remote endpoint.
bufferA linear_buffer that is used to buffer sent/received messages.
handlerThe handler to be called when the execute operation completes. The function signature of the handler must be:
void handler(
// Result of operation.
const error_code& error,
);

◆ async_execute() [2/2]

template<typename Socket , typename DynamicBuffer , typename ExecuteHandler >
void_or_deduced asioext::socks::async_execute ( Socket &  socket,
command  cmd,
const std::string remote,
uint16_t  port,
DynamicBuffer &&  buffer,
ExecuteHandler &&  handler 
)

Asynchronously attempt to execute the given command.

This function asynchronously executes the given SOCKS command. The following commands are supported by a SOCKS 5 server:

  • connect: Establish a connection to the given remote endpoint. Any data sent/received on the socket after successful command execution belongs to the proxied connection.
Parameters
socketThe connected socket. The remote endpoint needs to be a successfully greeted SOCKS 5 proxy.
cmdThe command to execute.
remoteHostname of the remote endpoint.
portPort of the remote endpoint.
bufferA linear_buffer that is used to buffer sent/received messages.
handlerThe handler to be called when the execute operation completes. The function signature of the handler must be:
void handler(
// Result of operation.
const error_code& error,
);

◆ async_greet()

template<typename Socket , typename DynamicBuffer , typename GreetHandler >
void_or_deduced asioext::socks::async_greet ( Socket &  socket,
const auth_method auth_methods,
std::size_t  num_auth_methods,
DynamicBuffer &&  buffer,
GreetHandler &&  handler 
)

Asynchronously perform a SOCKS 5 greeting with the remote SOCKS server.

This function attempts to perform a SOCKS 5 greeting on the given socket which needs to be connected to the remote proxy server you wish to "greet".

Parameters
socketThe connected socket. The remote endpoint needs to be a SOCKS 5 proxy.
auth_methodsArray containing the allowed authentication methods.
num_auth_methodsNumber of authentication methods entries.
bufferA DynamicBuffer that is used to buffer sent/received messages.
handlerThe handler to be called when the greet operation completes. The function signature of the handler must be:
void handler(
// Result of operation.
const error_code& error,
// Authentication method chosen by the remote end.
auth_method chosen_method
);

◆ async_login()

template<typename Socket , typename DynamicBuffer , typename LoginHandler >
void_or_deduced asioext::socks::async_login ( Socket &  socket,
const std::string username,
const std::string password,
DynamicBuffer &&  buffer,
LoginHandler &&  handler 
)

Asynchronously attempt a login on the remote SOCKS 5 server.

This function attempts to log in to the remote SOCKS 5 server with the given credentials. The given socket must be connected to a SOCKS 5 proxy server and the initial greeting must have resulted in the user/password authentication scheme being chosen.

Parameters
socketThe connected socket. The remote endpoint needs to be a successfully greeted SOCKS 5 proxy.
usernameUsername on the remote end.
passwordPassword of the remote user.
bufferA linear_buffer that is used to buffer sent/received messages.
handlerThe handler to be called when the login operation completes. The function signature of the handler must be:
void handler(
// Result of operation.
const error_code& error,
);

◆ get_error_category()

const error_category& asioext::socks::get_error_category ( )
noexcept

Get the error_category for error.

◆ make_error_code()

error_code asioext::socks::make_error_code ( error  e)
inlinenoexcept