34 #elif defined(_MSC_VER) 50 #define UP_TYPE_SOCKS "SOCKS Proxy" 99 volatile int *signal_received)
104 const int timeout_sec = 5;
119 "SOCKS username and/or password exceeds 255 characters. " 120 "Authentication not possible.");
125 size = send(sd, to_send, strlen(to_send),
MSG_NOSIGNAL);
127 if (size != strlen(to_send))
143 tv.tv_sec = timeout_sec;
146 status = select(sd + 1, &reads, NULL, NULL, &tv);
149 if (*signal_received)
183 if (buf[0] != 5 && buf[1] != 0)
185 msg(
D_LINK_ERRORS,
"socks_username_password_auth: server refused the authentication");
199 volatile int *signal_received)
203 const int timeout_sec = 5;
207 char method_sel[3] = { 0x05, 0x01, 0x00 };
210 method_sel[2] = 0x02;
213 size = send(sd, method_sel,
sizeof(method_sel),
MSG_NOSIGNAL);
214 if (size !=
sizeof(method_sel))
230 tv.tv_sec = timeout_sec;
233 status = select(sd + 1, &reads, NULL, NULL, &tv);
236 if (*signal_received)
270 if (buf[0] !=
'\x05')
277 if (buf[1] != method_sel[2])
279 msg(
D_LINK_ERRORS,
"socks_handshake: Socks proxy returned unexpected auth");
292 msg(
D_LINK_ERRORS,
"socks_handshake: server asked for username/login auth but we were " 293 "not provided any credentials");
315 volatile int *signal_received)
321 const int timeout_sec = 5;
325 addr->
addr.
in4.sin_family = AF_INET;
326 addr->
addr.
in4.sin_addr.s_addr = htonl(INADDR_ANY);
327 addr->
addr.
in4.sin_port = htons(0);
330 while (len < 4 + alen + 2)
340 tv.tv_sec = timeout_sec;
343 status = select(sd + 1, &reads, NULL, NULL, &tv);
346 if (*signal_received)
392 alen = (
unsigned char) c + 1;
400 msg(
D_LINK_ERRORS,
"recv_socks_reply: Socks proxy returned bad address type");
406 if (len < (
int)
sizeof(buf))
414 if (buf[0] !=
'\x05' || buf[1] !=
'\x00')
421 if (atyp ==
'\x01' && addr != NULL)
423 memcpy(&addr->
addr.
in4.sin_addr, buf + 4,
sizeof(addr->
addr.
in4.sin_addr));
424 memcpy(&addr->
addr.
in4.sin_port, buf + 8,
sizeof(addr->
addr.
in4.sin_port));
426 msg(
M_INFO,
"SOCKS proxy wants us to send UDP to %s",
439 port = atoi(servname);
440 if (port >0 && port < 65536)
446 service = getservbyname(servname, NULL);
449 return service->s_port;
459 const char *servname,
460 volatile int *signal_received)
477 len = (5 + len + 2 >
sizeof(buf)) ? (
sizeof(buf) - 5 - 2) : len;
480 memcpy(buf + 5, host, len);
485 msg(
D_LINK_ERRORS,
"establish_socks_proxy_passthrough: Cannot convert %s to port number", servname);
489 buf[5 + len] = (char) (port >> 8);
490 buf[5 + len + 1] = (char) (port & 0xff);
494 if ((
int)size != 5 + (
int)len + 2)
511 if (!*signal_received)
523 volatile int *signal_received)
534 const ssize_t size = send(ctrl_sd,
535 "\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00",
554 if (!*signal_received)
static bool buf_write_u8(struct buffer *dest, int data)
static void strncpynt(char *dest, const char *src, size_t maxlen)
void socks_proxy_close(struct socks_proxy_info *sp)
void establish_socks_proxy_passthru(struct socks_proxy_info *p, socket_descriptor_t sd, const char *host, const char *servname, volatile int *signal_received)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
Packet geometry parameters.
static void gc_free(struct gc_arena *a)
static void frame_add_to_extra_link(struct frame *frame, const int increment)
static int buf_read_u8(struct buffer *buf)
static bool recv_socks_reply(socket_descriptor_t sd, struct openvpn_sockaddr *addr, volatile int *signal_received)
void socks_adjust_frame_parameters(struct frame *frame, int proto)
static const char * print_openvpn_sockaddr(const struct openvpn_sockaddr *addr, struct gc_arena *gc)
static void get_signal(volatile int *sig)
void socks_process_incoming_udp(struct buffer *buf, struct link_socket_actual *from)
char username[USER_PASS_LEN]
struct socks_proxy_info * socks_proxy_new(const char *server, const char *port, const char *authfile)
static bool buf_read(struct buffer *src, void *dest, int size)
int len
Length in bytes of the actual content within the allocated memory.
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
static struct gc_arena gc_new(void)
#define ALLOC_OBJ_CLEAR(dptr, type)
struct buffer buf_sub(struct buffer *buf, int size, bool prepend)
static bool buf_write_u16(struct buffer *dest, int data)
static void openvpn_fd_set(socket_descriptor_t fd, fd_set *setp)
static SERVICE_STATUS_HANDLE service
union openvpn_sockaddr::@10 addr
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)
int socks_process_outgoing_udp(struct buffer *buf, const struct link_socket_actual *to)
static bool get_user_pass(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags)
static bool buf_defined(const struct buffer *buf)
SOCKET socket_descriptor_t
Wrapper structure for dynamically allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
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, volatile int *signal_received)
static int buf_read_u16(struct buffer *buf)
char password[USER_PASS_LEN]
static bool socks_handshake(struct socks_proxy_info *p, socket_descriptor_t sd, volatile int *signal_received)
static SERVICE_STATUS status
struct openvpn_sockaddr dest
#define GET_USER_PASS_MANAGEMENT