49#define UP_TYPE_SOCKS "SOCKS Proxy"
87 volatile int *signal_received)
99 volatile int *signal_received)
114 msg(
M_NONFATAL,
"SOCKS username and/or password exceeds 255 characters. "
115 "Authentication not possible.");
122 if (!
proxy_send(sd, to_send, strlen(to_send)))
142 if (buf[0] != 5 || buf[1] != 0)
144 msg(
D_LINK_ERRORS,
"socks_username_password_auth: server refused the authentication");
157 const struct event_timeout *server_poll_timeout,
volatile int *signal_received)
163 uint8_t method_sel[3] = { 0x05, 0x01, 0x00 };
166 method_sel[2] = 0x02;
168 if (!
proxy_send(sd, method_sel,
sizeof(method_sel)))
193 if (buf[1] != method_sel[2])
195 msg(
D_LINK_ERRORS,
"socks_handshake: Socks proxy returned unexpected auth");
209 "socks_handshake: server asked for username/login auth but we were "
210 "not provided any credentials");
229#if defined(__GNUC__) || defined(__clang__)
230#pragma GCC diagnostic push
231#pragma GCC diagnostic ignored "-Wsign-conversion"
236 const struct event_timeout *server_poll_timeout,
volatile int *signal_received)
245 addr->
addr.
in4.sin_family = AF_INET;
246 addr->
addr.
in4.sin_addr.s_addr = htonl(INADDR_ANY);
247 addr->
addr.
in4.sin_port = htons(0);
250 while (len < 4 + alen + 2)
284 msg(
D_LINK_ERRORS,
"recv_socks_reply: Socks proxy returned bad address type");
290 if (len < (
int)
sizeof(buf))
298 if (buf[0] != 5 || buf[1] != 0)
305 if (atyp == 1 && addr != NULL)
307 memcpy(&addr->
addr.
in4.sin_addr, buf + 4,
sizeof(addr->
addr.
in4.sin_addr));
308 memcpy(&addr->
addr.
in4.sin_port, buf + 8,
sizeof(addr->
addr.
in4.sin_port));
318#if defined(__GNUC__) || defined(__clang__)
319#pragma GCC diagnostic pop
326 port = atoi(servname);
327 if (port > 0 && port < 65536)
332 const struct servent *
service = getservbyname(servname, NULL);
345 const char *servname,
364 len = (5 + len + 2 >
sizeof(buf)) ? (
sizeof(buf) - 5 - 2) : len;
367 memcpy(buf + 5, host, len);
372 msg(
D_LINK_ERRORS,
"establish_socks_proxy_passthrough: Cannot convert %s to port number",
377 buf[5 + len] = (char)(port >> 8);
378 buf[5 + len + 1] = (char)(port & 0xff);
416 send(ctrl_sd,
"\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00", 10,
MSG_NOSIGNAL);
430 if (!relay_addr->
addr.
in4.sin_addr.s_addr)
432 msg(
D_LINK_ERRORS,
"%s: Socks proxy did not answer with IPv4 address", __func__);
struct buffer buf_sub(struct buffer *buf, int size, bool prepend)
Return a sub-buffer of another buffer.
bool checked_snprintf(char *str, size_t size, const char *format,...)
Like snprintf() but returns an boolean.
static bool buf_write_u16(struct buffer *dest, uint16_t data)
Append a uint16_t to a buffer in network byte order.
static int buf_read_u16(struct buffer *buf)
Read and consume a uint16_t from the front of a buffer.
static bool buf_read(struct buffer *src, void *dest, int size)
Read bytes from the front of a buffer into a caller-supplied destination.
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
static bool buf_write_u8(struct buffer *dest, uint8_t data)
Append a uint8_t to a buffer.
static int buf_read_u8(struct buffer *buf)
Read and consume a uint8_t from the front of a buffer.
#define BLEN(buf)
Return the length of the buffer content in bytes.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
static bool buf_defined(const struct buffer *buf)
Return true iff buf has a non-NULL data pointer.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
size_t strlcpy(char *dest, const char *src, size_t maxlen)
int get_server_poll_remaining_time(const struct event_timeout *server_poll_timeout)
Interface functions to the internal and external multiplexers.
static SERVICE_STATUS_HANDLE service
#define GET_USER_PASS_MANAGEMENT
static bool get_user_pass(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags)
Retrieves the user credentials from various sources depending on the flags.
#define SOCKS_UDPv4_HEADROOM
bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd, struct timeval *timeout, volatile int *signal_received)
bool proxy_send(socket_descriptor_t sd, const void *buf, size_t len)
void register_signal(struct signal_info *si, int signum, const char *signal_text)
Register a soft signal in the signal_info struct si respecting priority.
static const char * print_openvpn_sockaddr(const struct openvpn_sockaddr *addr, struct gc_arena *gc)
static int port_from_servname(const char *servname)
void establish_socks_proxy_passthru(const struct socks_proxy_info *p, socket_descriptor_t sd, const char *host, const char *servname, const struct event_timeout *server_poll_timeout, struct signal_info *sig_info)
static bool socks_proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd, const struct event_timeout *server_poll_timeout, volatile int *signal_received)
static bool socks_username_password_auth(const struct socks_proxy_info *p, socket_descriptor_t sd, const struct event_timeout *server_poll_timeout, volatile int *signal_received)
static bool recv_socks_reply(socket_descriptor_t sd, struct openvpn_sockaddr *addr, const struct event_timeout *server_poll_timeout, volatile int *signal_received)
static bool socks_handshake(const struct socks_proxy_info *p, socket_descriptor_t sd, const struct event_timeout *server_poll_timeout, volatile int *signal_received)
int socks_process_outgoing_udp(struct buffer *buf, const struct link_socket_actual *to)
void establish_socks_proxy_udpassoc(const struct socks_proxy_info *p, socket_descriptor_t ctrl_sd, struct openvpn_sockaddr *relay_addr, const struct event_timeout *server_poll_timeout, struct signal_info *sig_info)
void socks_process_incoming_udp(struct buffer *buf, struct link_socket_actual *from)
struct socks_proxy_info * socks_proxy_new(const char *server, const char *port, const char *authfile)
void socks_proxy_close(struct socks_proxy_info *sp)
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
struct openvpn_sockaddr dest
union openvpn_sockaddr::@051240265251124304325377241125360350250341115171 addr
volatile int signal_received
char password[USER_PASS_LEN]
char username[USER_PASS_LEN]
SOCKET socket_descriptor_t
static int cleanup(void **state)