33#define LOG(kind, ...) GNUNET_log_from (kind, "util-socks", __VA_ARGS__)
35#define LOG_STRERROR(kind, syscall) \
36 GNUNET_log_from_strerror (kind, "util-socks", syscall)
40#define SOCKS5_AUTH_REJECT 0xFF
41#define SOCKS5_AUTH_NOAUTH 0x00
42#define SOCKS5_AUTH_GSSAPI 0x01
43#define SOCKS5_AUTH_USERPASS 0x02
44#define SOCKS5_AUTH_CHAP 0x03
45#define SOCKS5_AUTH_EAP 0x05
46#define SOCKS5_AUTH_MAF 0x08
50#define SOCKS5_REP_SUCCEEDED 0x00
51#define SOCKS5_REP_FAIL 0x01
52#define SOCKS5_REP_NALLOWED 0x02
53#define SOCKS5_REP_NUNREACH 0x03
54#define SOCKS5_REP_HUNREACH 0x04
55#define SOCKS5_REP_REFUSED 0x05
56#define SOCKS5_REP_EXPIRED 0x06
57#define SOCKS5_REP_CNOTSUP 0x07
58#define SOCKS5_REP_ANOTSUP 0x08
59#define SOCKS5_REP_INVADDR 0x09
70 return "general SOCKS server failure";
73 return "connection not allowed by ruleset";
76 return "Network unreachable";
79 return "Host unreachable";
82 return "connection refused";
88 return "Command not supported";
91 return "Address not supported";
94 return "Invalid address";
114 size_t l = strlen (s);
119 "SOCKS5 cannot handle hostnames, usernames, or passwords over 255 bytes, truncating.\n");
122 *(b++) = (
unsigned char) l;
128#define SOCKS5_step_greet 0
129#define SOCKS5_step_auth 1
130#define SOCKS5_step_cmd 2
131#define SOCKS5_step_done 3
151 struct GNUNET_CONNECTION_TransmitHandle *
th;
189#define register_reciever_wants(ih) ((SOCKS5_step_cmd == ih->step) ? 10 : 2)
192struct GNUNET_CONNECTION_TransmitHandle *
218 unsigned char *b = ih->
instart;
219 size_t available = ih->
inend - b;
223 if (available < want)
253 "Not a SOCKS5 server / Nonsensical authentication\n");
278 "SOCKS5 connection error : %s\n",
287 b +=
sizeof(
struct in_addr);
291 b +=
sizeof(
struct in6_addr);
306 "SOCKS5 server : %s\n",
333 const struct sockaddr *addr,
341 ih->
inend += available;
396 "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
402 "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
414 unsigned int l = e - b;
429struct GNUNET_CONNECTION_TransmitHandle *
464 unsigned char *b = ih->
outbuf;
468 unsigned char *n = b++;
540 if (1 == inet_pton (AF_INET, host, &ia.in4))
544 b +=
sizeof(
struct in_addr);
546 else if (1 == inet_pton (AF_INET6, host, &ia.in6))
550 b +=
sizeof(
struct in6_addr);
559 *(uint16_t *) b = htons (
port);
573struct GNUNET_CONNECTION_Handle *
575 struct GNUNET_CONNECTION_Handle *c)
610struct GNUNET_CONNECTION_Handle *
615 struct GNUNET_CONNECTION_Handle *socks5;
620 unsigned long long port0;
621 unsigned long long port1;
632 if ((port0 > 65535) || (port0 <= 0))
636 "Attempting to use invalid port %d as SOCKS proxy for service `%s'.\n"),
645 (port1 > 65535) || (port1 <= 0) ||
653 "Attempting to proxy service `%s' to invalid port %d or hostname.\n"),
665 socks5 = GNUNET_CONNECTION_create_from_connect (
cfg,
666 (host0 != NULL) ? host0
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
static uint16_t port
Port number.
static char * service_name
Option -s: service name (hash to get service descriptor)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_SOCKS_check_service(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
Check if a SOCKS proxy is required by a service.
struct GNUNET_CONNECTION_Handle * GNUNET_SOCKS_do_connect(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
Try to connect to a service configured to use a SOCKS5 proxy.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
static unsigned int size
Size of the "table".
struct GNUNET_CONNECTION_TransmitHandle * register_sender(struct GNUNET_SOCKS_Handshake *ih)
Register SOCKS5 handshake sender.
#define SOCKS5_AUTH_USERPASS
#define register_reciever_wants(ih)
#define SOCKS5_REP_REFUSED
#define SOCKS5_REP_HUNREACH
#define SOCKS5_REP_ANOTSUP
void SOCKS5_handshake_done(struct GNUNET_SOCKS_Handshake *ih)
Conclude the SOCKS5 handshake successfully.
size_t transmit_ready(void *cls, size_t size, void *buf)
Register SOCKS5 handshake sender.
unsigned char * SOCK5_proto_string(unsigned char *b, const char *s)
Encode a string for the SOCKS5 protocol by prefixing it a byte stating its length and stripping the t...
const char * SOCKS5_REP_names(int rep)
struct GNUNET_SOCKS_Handshake * GNUNET_SOCKS_init_handshake(const char *user, const char *pass)
Initialize a SOCKS5 handshake for authentication via username and password.
#define SOCKS5_REP_EXPIRED
#define SOCKS5_REP_NUNREACH
#define SOCKS5_REP_NALLOWED
struct GNUNET_CONNECTION_Handle * GNUNET_SOCKS_run_handshake(struct GNUNET_SOCKS_Handshake *ih, struct GNUNET_CONNECTION_Handle *c)
Run a SOCKS5 handshake on an open but unused TCP connection.
#define SOCKS5_AUTH_NOAUTH
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
#define SOCKS5_REP_CNOTSUP
struct GNUNET_SOCKS_Handshake * GNUNET_SOCKS_init_handshake_noauth()
Initialize a SOCKS5 handshake without authentication, thereby possibly sharing a Tor circuit with ano...
void register_reciever(struct GNUNET_SOCKS_Handshake *ih, int want)
Register callback to read from the SOCKS5 proxy.
#define SOCKS5_AUTH_REJECT
#define SOCKS5_REP_INVADDR
#define SOCKS5_step_greet
void SOCKS5_handshake_step(struct GNUNET_SOCKS_Handshake *ih)
Read one step in the SOCKS5 handshake.
#define SOCKS5_REP_SUCCEEDED
void GNUNET_SOCKS_set_handshake_destination(struct GNUNET_SOCKS_Handshake *ih, const char *host, uint16_t port)
Build request that the SOCKS5 proxy open a TCP/IP stream to the given host and port.
State of the SOCKS5 handshake.
struct GNUNET_CONNECTION_TransmitHandle * th
Transmission handle on socks5_connection.
unsigned char outbuf[1024]
Precomputed SOCKS5 handshake output buffer.
unsigned char inbuf[1024]
SOCKS5 handshake input buffer.
unsigned char * outstep[4]
Pointers delineating protoocol steps in the output buffer.
unsigned char * instart
Pointers delimiting the current step in the input buffer.
struct GNUNET_CONNECTION_Handle * target_connection
Connection handle initially returned to client.
struct GNUNET_CONNECTION_Handle * socks5_connection
Connection handle used for SOCKS5.
int step
Our stage in the SOCKS5 handshake.
Time for relative time used by GNUnet, in microseconds.