Go to the documentation of this file.
48 #define UP_TYPE_SOCKS "SOCKS Proxy"
88 volatile int *signal_received)
93 const int timeout_sec = 5;
108 "SOCKS username and/or password exceeds 255 characters. "
109 "Authentication not possible.");
114 size = send(sd, to_send, strlen(to_send),
MSG_NOSIGNAL);
116 if (size != strlen(to_send))
132 tv.tv_sec = timeout_sec;
135 status = select(sd + 1, &reads, NULL, NULL, &tv);
138 if (*signal_received)
172 if (buf[0] != 5 && buf[1] != 0)
174 msg(
D_LINK_ERRORS,
"socks_username_password_auth: server refused the authentication");
188 volatile int *signal_received)
192 const int timeout_sec = 5;
196 char method_sel[3] = { 0x05, 0x01, 0x00 };
199 method_sel[2] = 0x02;
202 size = send(sd, method_sel,
sizeof(method_sel),
MSG_NOSIGNAL);
203 if (size !=
sizeof(method_sel))
219 tv.tv_sec = timeout_sec;
222 status = select(sd + 1, &reads, NULL, NULL, &tv);
225 if (*signal_received)
259 if (buf[0] !=
'\x05')
266 if (buf[1] != method_sel[2])
268 msg(
D_LINK_ERRORS,
"socks_handshake: Socks proxy returned unexpected auth");
281 msg(
D_LINK_ERRORS,
"socks_handshake: server asked for username/login auth but we were "
282 "not provided any credentials");
304 volatile int *signal_received)
310 const int timeout_sec = 5;
314 addr->
addr.
in4.sin_family = AF_INET;
315 addr->
addr.
in4.sin_addr.s_addr = htonl(INADDR_ANY);
316 addr->
addr.
in4.sin_port = htons(0);
319 while (len < 4 + alen + 2)
329 tv.tv_sec = timeout_sec;
332 status = select(sd + 1, &reads, NULL, NULL, &tv);
335 if (*signal_received)
365 msg(
D_LINK_ERRORS,
"ERROR: recv_socks_reply: empty response from socks server");
386 alen = (
unsigned char) c + 1;
394 msg(
D_LINK_ERRORS,
"recv_socks_reply: Socks proxy returned bad address type");
400 if (len < (
int)
sizeof(buf))
408 if (buf[0] !=
'\x05' || buf[1] !=
'\x00')
415 if (atyp ==
'\x01' && addr != NULL)
417 memcpy(&addr->
addr.
in4.sin_addr, buf + 4,
sizeof(addr->
addr.
in4.sin_addr));
418 memcpy(&addr->
addr.
in4.sin_port, buf + 8,
sizeof(addr->
addr.
in4.sin_port));
420 msg(
M_INFO,
"SOCKS proxy wants us to send UDP to %s",
433 port = atoi(servname);
434 if (port >0 && port < 65536)
440 service = getservbyname(servname, NULL);
453 const char *servname,
471 len = (5 + len + 2 >
sizeof(buf)) ? (
sizeof(buf) - 5 - 2) : len;
474 memcpy(buf + 5, host, len);
479 msg(
D_LINK_ERRORS,
"establish_socks_proxy_passthrough: Cannot convert %s to port number", servname);
483 buf[5 + len] = (char) (port >> 8);
484 buf[5 + len + 1] = (char) (port & 0xff);
487 const ssize_t size = send(sd, buf, 5 + len + 2,
MSG_NOSIGNAL);
488 if ((
int)size != 5 + (
int)len + 2)
526 const ssize_t size = send(ctrl_sd,
527 "\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00",
void establish_socks_proxy_udpassoc(struct socks_proxy_info *p, socket_descriptor_t ctrl_sd, socket_descriptor_t udp_sd, struct openvpn_sockaddr *relay_addr, struct signal_info *sig_info)
volatile int signal_received
union openvpn_sockaddr::@14 addr
static bool buf_read(struct buffer *src, void *dest, int size)
static struct gc_arena gc_new(void)
int len
Length in bytes of the actual content within the allocated memory.
int socks_process_outgoing_udp(struct buffer *buf, const struct link_socket_actual *to)
char username[USER_PASS_LEN]
struct buffer buf_sub(struct buffer *buf, int size, bool prepend)
void socks_proxy_close(struct socks_proxy_info *sp)
#define GET_USER_PASS_MANAGEMENT
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static bool buf_write_u16(struct buffer *dest, uint16_t data)
static bool socks_handshake(struct socks_proxy_info *p, socket_descriptor_t sd, volatile int *signal_received)
static bool recv_socks_reply(socket_descriptor_t sd, struct openvpn_sockaddr *addr, volatile int *signal_received)
static bool buf_write_u8(struct buffer *dest, uint8_t data)
void socks_process_incoming_udp(struct buffer *buf, struct link_socket_actual *from)
static void openvpn_fd_set(socket_descriptor_t fd, fd_set *setp)
static int buf_read_u16(struct buffer *buf)
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.
Wrapper structure for dynamically allocated memory.
static int port_from_servname(const char *servname)
static bool socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor_t sd, volatile int *signal_received)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Garbage collection arena used to keep track of dynamically allocated memory.
void establish_socks_proxy_passthru(struct socks_proxy_info *p, socket_descriptor_t sd, const char *host, const char *servname, struct signal_info *sig_info)
static void strncpynt(char *dest, const char *src, size_t maxlen)
SOCKET socket_descriptor_t
static SERVICE_STATUS_HANDLE service
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
static SERVICE_STATUS status
static void gc_free(struct gc_arena *a)
struct socks_proxy_info * socks_proxy_new(const char *server, const char *port, const char *authfile)
#define ALLOC_OBJ_CLEAR(dptr, type)
char password[USER_PASS_LEN]
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
static int buf_read_u8(struct buffer *buf)
struct openvpn_sockaddr dest
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 bool buf_defined(const struct buffer *buf)
static int cleanup(void **state)