OpenVPN
proxy.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "syshead.h"
28
29#include "common.h"
30#include "misc.h"
31#include "crypto.h"
32#include "win32.h"
33#include "socket.h"
34#include "fdmisc.h"
35#include "proxy.h"
36#include "base64.h"
37#include "httpdigest.h"
38#include "memdbg.h"
39#include "forward.h"
40
41#define UP_TYPE_PROXY "HTTP Proxy"
42
43struct http_proxy_options *
45{
46 if (!*hpo)
47 {
49 /* http proxy defaults */
50 (*hpo)->http_version = "1.0";
51 }
52 return *hpo;
53}
54
55
56#if defined(__GNUC__) || defined(__clang__)
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Wsign-conversion"
59#endif
60
61/* cached proxy username/password */
63
64bool
65proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
66 struct timeval *timeout, volatile int *signal_received)
67{
68 fd_set reads;
69 FD_ZERO(&reads);
70 openvpn_fd_set(sd, &reads);
71
72 const int status = openvpn_select(sd + 1, &reads, NULL, NULL, timeout);
73
74 get_signal(signal_received);
75 if (*signal_received)
76 {
77 return false;
78 }
79
80 /* timeout? */
81 if (status == 0)
82 {
83 msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read timeout expired", name);
84 return false;
85 }
86
87 /* error */
88 if (status < 0)
89 {
90 msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read failed on select()", name);
91 return false;
92 }
93
94 /* read single char */
95 const ssize_t size = recv(sd, (void *)c, 1, MSG_NOSIGNAL);
96
97 /* error? */
98 if (size != 1)
99 {
100 msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read failed on recv()", name);
101 return false;
102 }
103
104 return true;
105}
106
107
108static bool
109recv_line(socket_descriptor_t sd, char *buf, int len, const int timeout_sec, const bool verbose,
110 struct buffer *lookahead, volatile int *signal_received)
111{
112 struct buffer la;
113 int lastc = 0;
114
115 CLEAR(la);
116 if (lookahead)
117 {
118 la = *lookahead;
119 }
120
121 while (true)
122 {
123 struct timeval tv;
124 uint8_t c;
125
126 if (buf_defined(&la))
127 {
128 ASSERT(buf_init(&la, 0));
129 }
130
131 tv.tv_sec = timeout_sec;
132 tv.tv_usec = 0;
133
134 if (!proxy_recv_char(&c, "recv_line", sd, &tv, signal_received))
135 {
136 return false;
137 }
138
139#if 0
140 if (isprint(c))
141 {
142 msg(M_INFO, "PROXY: read '%c' (%d)", c, (int)c);
143 }
144 else
145 {
146 msg(M_INFO, "PROXY: read (%d)", (int)c);
147 }
148#endif
149
150 /* store char in buffer */
151 if (len > 1)
152 {
153 *buf++ = c;
154 --len;
155 }
156
157 /* also store char in lookahead buffer */
158 if (buf_defined(&la))
159 {
160 buf_write_u8(&la, c);
161 if (!isprint(c) && !isspace(c)) /* not ascii? */
162 {
163 if (verbose)
164 {
166 "recv_line: Non-ASCII character (%d) read on recv()", (int)c);
167 }
168 *lookahead = la;
169 return false;
170 }
171 }
172
173 /* end of line? */
174 if (lastc == '\r' && c == '\n')
175 {
176 break;
177 }
178
179 lastc = c;
180 }
181
182 /* append trailing null */
183 if (len > 0)
184 {
185 *buf++ = '\0';
186 }
187
188 return true;
189}
190
191bool
192proxy_send(socket_descriptor_t sd, const void *buf, size_t len)
193{
194 const ssize_t size = openvpn_send(sd, buf, len, MSG_NOSIGNAL);
195 if (size != (ssize_t)len)
196 {
197 msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()");
198 return false;
199 }
200 return true;
201}
202
203static bool
205{
206 bool ret;
207
208 struct buffer buf = alloc_buf(strlen(src) + 2);
209 ASSERT(buf_write(&buf, src, strlen(src)));
210 ASSERT(buf_write(&buf, "\r\n", 2));
211 ret = proxy_send(sd, BSTR(&buf), BLEN(&buf));
212 free_buf(&buf);
213 return ret;
214}
215
216static bool
218{
219 return send_line_crlf(sd, "");
220}
221
222uint8_t *
224{
225 uint8_t *ret = NULL;
226 char *b64out = NULL;
227 ASSERT(openvpn_base64_encode((const void *)str, src_len, &b64out) >= 0);
229 free(b64out);
230 return ret;
231}
232
233uint8_t *
235{
236 return make_base64_string2(str, (int)strlen((const char *)str), gc);
237}
238
239static const char *
241{
242 struct buffer out = alloc_buf_gc(strlen(p->up.username) + strlen(p->up.password) + 2, gc);
243 ASSERT(strlen(p->up.username) > 0);
244 buf_printf(&out, "%s:%s", p->up.username, p->up.password);
245 char *ret = (char *)make_base64_string((const uint8_t *)BSTR(&out), gc);
246 secure_memzero(BSTR(&out), out.len);
247 return ret;
248}
249
250static void
255
256static void
258{
259 /*
260 * in case of forced (re)load, make sure the static storage is set as
261 * undefined, otherwise get_user_pass() won't try to load any credential
262 */
263 if (force)
264 {
266 }
267
269 {
270 unsigned int flags = GET_USER_PASS_MANAGEMENT;
271 const char *auth_file = p->options.auth_file;
272 if (p->options.auth_file_up)
273 {
274 auth_file = p->options.auth_file_up;
275 }
276 if (p->queried_creds && !static_proxy_user_pass.nocache)
277 {
279 }
280 if (p->options.inline_creds)
281 {
283 }
285 static_proxy_user_pass.nocache = p->options.nocache;
287 }
288
289 /*
290 * Using cached credentials
291 */
292 p->queried_creds = true;
293 p->up = static_proxy_user_pass; /* this is a copy of protected memory */
294}
295
296#if defined(__GNUC__) || defined(__clang__)
297#pragma GCC diagnostic pop
298#endif
299
300#if 0
301/* function only used in #if 0 debug statement */
302static void
304 int timeout,
305 volatile int *signal_received)
306{
307 char buf[256];
308 while (true)
309 {
310 if (!recv_line(sd, buf, sizeof(buf), timeout, true, NULL, signal_received))
311 {
312 return;
313 }
314 chomp(buf);
315 msg(D_PROXY, "PROXY HEADER: '%s'", buf);
316 }
317}
318#endif
319
320/*
321 * Extract the Proxy-Authenticate header from the stream.
322 * Consumes all headers.
323 */
324static int
326 volatile int *signal_received)
327{
328 char buf[256];
329 int ret = HTTP_AUTH_NONE;
330 while (true)
331 {
332 if (!recv_line(sd, buf, sizeof(buf), timeout, true, NULL, signal_received))
333 {
334 free(*data);
335 *data = NULL;
336 return HTTP_AUTH_NONE;
337 }
338 chomp(buf);
339 if (!strlen(buf))
340 {
341 return ret;
342 }
343 if (ret == HTTP_AUTH_NONE && !strncmp(buf, "Proxy-Authenticate: ", 20))
344 {
345 if (!strncmp(buf + 20, "Basic ", 6))
346 {
347 msg(D_PROXY, "PROXY AUTH BASIC: '%s'", buf);
348 *data = string_alloc(buf + 26, NULL);
350 }
351 else if (!strncmp(buf + 20, "Digest ", 7))
352 {
353 msg(D_PROXY, "PROXY AUTH DIGEST: '%s'", buf);
354 *data = string_alloc(buf + 27, NULL);
356 }
357 }
358 }
359}
360
361static void
363{
364 free(p->proxy_authenticate);
365 p->proxy_authenticate = data;
366}
367
368/*
369 * Parse out key/value pairs from Proxy-Authenticate string.
370 * Return true on success, or false on parse failure.
371 */
372static bool
373get_key_value(const char *str, /* source string */
374 char *key, /* key stored here */
375 char *value, /* value stored here */
376 int max_key_len, int max_value_len, const char **endptr) /* next search position */
377{
378 int c;
379 bool starts_with_quote = false;
380 bool escape = false;
381
382 for (c = max_key_len - 1; (*str && (*str != '=') && c--);)
383 {
384 *key++ = *str++;
385 }
386 *key = '\0';
387
388 if ('=' != *str++)
389 {
390 /* no key/value found */
391 return false;
392 }
393
394 if ('\"' == *str)
395 {
396 /* quoted string */
397 str++;
398 starts_with_quote = true;
399 }
400
401 for (c = max_value_len - 1; *str && c--; str++)
402 {
403 switch (*str)
404 {
405 case '\\':
406 if (!escape)
407 {
408 /* possibly the start of an escaped quote */
409 escape = true;
410 *value++ = '\\'; /* even though this is an escape character, we still
411 * store it as-is in the target buffer */
412 continue;
413 }
414 break;
415
416 case ',':
418 {
419 /* this signals the end of the value if we didn't get a starting quote
420 * and then we do "sloppy" parsing */
421 c = 0; /* the end */
422 continue;
423 }
424 break;
425
426 case '\r':
427 case '\n':
428 /* end of string */
429 c = 0;
430 continue;
431
432 case '\"':
434 {
435 /* end of string */
436 c = 0;
437 continue;
438 }
439 break;
440 }
441 escape = false;
442 *value++ = *str;
443 }
444 *value = '\0';
445
446 *endptr = str;
447
448 return true; /* success */
449}
450
451static char *
452get_pa_var(const char *key, const char *pa, struct gc_arena *gc)
453{
454 char k[64];
455 char v[256];
456 const char *content = pa;
457
458 while (true)
459 {
460 const int status = get_key_value(content, k, v, sizeof(k), sizeof(v), &content);
461 if (status)
462 {
463 if (!strcmp(key, k))
464 {
465 return string_alloc(v, gc);
466 }
467 }
468 else
469 {
470 return NULL;
471 }
472
473 /* advance to start of next key */
474 if (*content == ',')
475 {
476 ++content;
477 }
478 while (*content && isspace(*content))
479 {
480 ++content;
481 }
482 }
483}
484
485struct http_proxy_info *
487{
488 struct http_proxy_info *p;
489
490 if (!o || !o->server)
491 {
492 msg(M_FATAL, "HTTP_PROXY: server not specified");
493 }
494
495 ASSERT(o->port);
496
498 p->options = *o;
499
500 /* parse authentication method */
502 if (o->auth_method_string)
503 {
504 if (!strcmp(o->auth_method_string, "none"))
505 {
507 }
508 else if (!strcmp(o->auth_method_string, "basic"))
509 {
511 }
512 else
513 {
514 msg(M_FATAL, "ERROR: unknown HTTP authentication method: '%s'", o->auth_method_string);
515 }
516 }
517
518 /* When basic authentication is requested, get credentials now.
519 * In case of "auto" negotiation credentials will be retrieved later once
520 * we know whether we need any. */
522 {
524 }
525
526 p->defined = true;
527 return p;
528}
529
530void
532{
533 if (hp)
534 {
535 free(hp->proxy_authenticate);
536 }
537 free(hp);
538}
539
540static bool
542 socket_descriptor_t sd, /* already open to proxy */
543 const char *host /* openvpn server remote */
544)
545{
546 char buf[512];
547 int i;
548 bool host_header_sent = false;
549
550 /*
551 * Send custom headers if provided
552 * If content is NULL the whole header is in name
553 * Also remember if we already sent a Host: header
554 */
555 for (i = 0; i < MAX_CUSTOM_HTTP_HEADER && p->options.custom_headers[i].name; i++)
556 {
558 {
559 snprintf(buf, sizeof(buf), "%s: %s", p->options.custom_headers[i].name,
561 if (!strcasecmp(p->options.custom_headers[i].name, "Host"))
562 {
563 host_header_sent = true;
564 }
565 }
566 else
567 {
568 snprintf(buf, sizeof(buf), "%s", p->options.custom_headers[i].name);
569 if (!strncasecmp(p->options.custom_headers[i].name, "Host:", 5))
570 {
571 host_header_sent = true;
572 }
573 }
574
575 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
576 if (!send_line_crlf(sd, buf))
577 {
578 return false;
579 }
580 }
581
582 if (!host_header_sent)
583 {
584 snprintf(buf, sizeof(buf), "Host: %s", host);
585 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
586 if (!send_line_crlf(sd, buf))
587 {
588 return false;
589 }
590 }
591
592 /* send User-Agent string if provided */
593 if (p->options.user_agent)
594 {
595 snprintf(buf, sizeof(buf), "User-Agent: %s", p->options.user_agent);
596 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
597 if (!send_line_crlf(sd, buf))
598 {
599 return false;
600 }
601 }
602
603 return true;
604}
605
606
607bool
609 socket_descriptor_t sd, /* already open to proxy */
610 const char *host, /* openvpn server remote */
611 const char *port, /* openvpn server port */
612 const struct event_timeout *server_poll_timeout,
613 struct buffer *lookahead, struct signal_info *sig_info)
614{
615 struct gc_arena gc = gc_new();
616 char buf[512];
617 int status;
618 int nparms;
619 bool ret = false;
620 bool processed = false;
621 volatile int *signal_received = &sig_info->signal_received;
622
623 /* get user/pass if not previously given */
625 {
626 get_user_pass_http(p, false);
627
628 if (p->up.nocache)
629 {
631 }
633 }
634
635 /* are we being called again after getting the digest server nonce in the previous transaction?
636 */
638 {
639 nparms = 1;
640 status = 407;
641 }
642 else
643 {
644 /* format HTTP CONNECT message */
645 snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", host, port, p->options.http_version);
646
647 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
648
649 /* send HTTP CONNECT message to proxy */
650 if (!send_line_crlf(sd, buf))
651 {
652 goto error;
653 }
654
655 if (!add_proxy_headers(p, sd, host))
656 {
657 goto error;
658 }
659
660 /* auth specified? */
661 switch (p->auth_method)
662 {
663 case HTTP_AUTH_NONE:
664 break;
665
666 case HTTP_AUTH_BASIC:
667 snprintf(buf, sizeof(buf), "Proxy-Authorization: Basic %s",
669 msg(D_PROXY, "Attempting Basic Proxy-Authorization");
670 dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s'", buf);
671 if (!send_line_crlf(sd, buf))
672 {
673 goto error;
674 }
675 break;
676
677 default:
678 ASSERT(0);
679 }
680
681 /* clear any sensitive content in buf */
682 secure_memzero(buf, sizeof(buf));
683
684 /* send empty CR, LF */
685 if (!send_crlf(sd))
686 {
687 goto error;
688 }
689
690 /* receive reply from proxy */
691 if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining_time(server_poll_timeout),
692 true, NULL, signal_received))
693 {
694 goto error;
695 }
696
697 /* remove trailing CR, LF */
698 chomp(buf);
699
700 msg(D_PROXY, "HTTP proxy returned: '%s'", buf);
701
702 /* parse return string */
703 nparms = sscanf(buf, "%*s %d", &status);
704 }
705
706 /* check for a "407 Proxy Authentication Required" response */
707 while (nparms >= 1 && status == 407)
708 {
709 msg(D_PROXY, "Proxy requires authentication");
710
711 if (p->auth_method == HTTP_AUTH_BASIC && !processed)
712 {
713 processed = true;
714 }
715 else if (p->auth_method == HTTP_AUTH_DIGEST && !processed)
716 {
717 const char *pa = p->proxy_authenticate;
718 ASSERT(pa);
719
720 const char *http_method = "CONNECT";
721 const char *nonce_count = "00000001";
722 const char *qop = "auth";
723 const char *username = p->up.username;
724 const char *password = p->up.password;
725 char *opaque_kv = "";
726 char uri[128];
727 uint8_t cnonce_raw[8];
728 HASHHEX session_key;
729 HASHHEX response;
730
731 const char *realm = get_pa_var("realm", pa, &gc);
732 const char *nonce = get_pa_var("nonce", pa, &gc);
733 const char *algor = get_pa_var("algorithm", pa, &gc);
734 const char *opaque = get_pa_var("opaque", pa, &gc);
735
736 if (!realm || !nonce)
737 {
738 msg(D_LINK_ERRORS, "HTTP proxy: digest auth failed, malformed response "
739 "from server: realm= or nonce= missing");
740 goto error;
741 }
742
743 /* generate a client nonce */
744 prng_bytes(cnonce_raw, sizeof(cnonce_raw));
745 uint8_t *cnonce = make_base64_string2(cnonce_raw, sizeof(cnonce_raw), &gc);
746
747 /* build the digest response */
748 snprintf(uri, sizeof(uri), "%s:%s", host, port);
749
750 if (opaque)
751 {
752 const size_t len = strlen(opaque) + 16;
753 opaque_kv = gc_malloc(len, false, &gc);
754 snprintf(opaque_kv, len, ", opaque=\"%s\"", opaque);
755 }
756
757 DigestCalcHA1(algor, username, realm, password, nonce, (char *)cnonce, session_key);
758 DigestCalcResponse(session_key, nonce, nonce_count, (char *)cnonce, qop,
759 http_method, uri, NULL, response);
760
761 /* format HTTP CONNECT message */
762 snprintf(buf, sizeof(buf), "%s %s HTTP/%s", http_method, uri,
764
765 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
766
767 /* send HTTP CONNECT message to proxy */
768 if (!send_line_crlf(sd, buf))
769 {
770 goto error;
771 }
772
773 /* send HOST etc, */
774 if (!add_proxy_headers(p, sd, host))
775 {
776 goto error;
777 }
778
779 /* send digest response */
780 if (!checked_snprintf(
781 buf, sizeof(buf),
782 "Proxy-Authorization: Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", qop=%s, nc=%s, cnonce=\"%s\", response=\"%s\"%s",
783 username, realm, nonce, uri, qop, nonce_count, cnonce, response, opaque_kv))
784 {
785 goto error;
786 }
787
788 msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);
789 if (!send_line_crlf(sd, buf))
790 {
791 goto error;
792 }
793 if (!send_crlf(sd))
794 {
795 goto error;
796 }
797 /* clear any sensitive content in buf */
798 secure_memzero(buf, sizeof(buf));
799
800 /* receive reply from proxy */
801 if (!recv_line(sd, buf, sizeof(buf),
802 get_server_poll_remaining_time(server_poll_timeout), true, NULL,
803 signal_received))
804 {
805 goto error;
806 }
807
808 /* remove trailing CR, LF */
809 chomp(buf);
810
811 msg(D_PROXY, "HTTP proxy returned: '%s'", buf);
812
813 /* parse return string */
814 nparms = sscanf(buf, "%*s %d", &status);
815 processed = true;
816 }
817 else if (p->options.auth_retry)
818 {
819 /* figure out what kind of authentication the proxy needs */
820 char *pa = NULL;
821 const int method = get_proxy_authenticate(
822 sd, get_server_poll_remaining_time(server_poll_timeout), &pa, signal_received);
823 if (method != HTTP_AUTH_NONE)
824 {
825 if (pa)
826 {
827 msg(D_PROXY, "HTTP proxy authenticate '%s'", pa);
828 }
829 if (p->options.auth_retry == PAR_NCT && method == HTTP_AUTH_BASIC)
830 {
831 msg(D_PROXY,
832 "HTTP proxy: support for basic auth and other cleartext proxy auth methods is disabled");
833 free(pa);
834 goto error;
835 }
836 p->auth_method = method;
838 ret = true;
839 goto done;
840 }
841 else
842 {
843 msg(D_PROXY,
844 "HTTP proxy: do not recognize the authentication method required by proxy");
845 free(pa);
846 goto error;
847 }
848 }
849 else
850 {
851 if (!processed)
852 {
853 msg(D_PROXY, "HTTP proxy: no support for proxy authentication method");
854 }
855 goto error;
856 }
857 }
858
859 /* check return code, success = 200 */
860 if (nparms < 1 || status != 200)
861 {
862 msg(D_LINK_ERRORS, "HTTP proxy returned bad status");
863#if 0
864 /* DEBUGGING -- show a multi-line HTTP error response */
865 dump_residual(sd, get_server_poll_remaining_time(server_poll_timeout), signal_received);
866#endif
867 goto error;
868 }
869
870 /* SUCCESS */
871
872 /* receive line from proxy and discard */
873 if (!recv_line(sd, NULL, 0, get_server_poll_remaining_time(server_poll_timeout), true, NULL,
874 signal_received))
875 {
876 goto error;
877 }
878
879 /*
880 * Toss out any extraneous chars, but don't throw away the
881 * start of the OpenVPN data stream (put it in lookahead).
882 */
883 while (recv_line(sd, NULL, 0, 2, false, lookahead, signal_received))
884 {
885 }
886
887 /* reset queried_creds so that we don't think that the next creds request is due to an auth
888 * error */
889 p->queried_creds = false;
890
891#if 0
892 if (lookahead && BLEN(lookahead))
893 {
894 msg(M_INFO, "HTTP PROXY: lookahead: %s", format_hex(BPTR(lookahead), BLEN(lookahead), 0));
895 }
896#endif
897
898done:
899 purge_user_pass(&p->up, true);
900 gc_free(&gc);
901 return ret;
902
903error:
904 purge_user_pass(&p->up, true);
905 register_signal(sig_info, SIGUSR1, "HTTP proxy error"); /* SOFT-SIGUSR1 -- HTTP proxy error */
906 gc_free(&gc);
907 return ret;
908}
void free_buf(struct buffer *buf)
Free the memory allocated for a buffer.
Definition buffer.c:174
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:231
void chomp(char *str)
Remove trailing newline and carriage-return characters from a string.
Definition buffer.c:596
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
Definition buffer.c:321
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
Definition buffer.c:77
struct buffer alloc_buf(size_t size)
Allocate a buffer of the given size.
Definition buffer.c:60
bool checked_snprintf(char *str, size_t size, const char *format,...)
Like snprintf() but returns an boolean.
Definition buffer.c:1150
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define BPTR(buf)
Return a pointer to the start of the buffer content.
Definition buffer.h:139
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
Definition buffer.h:748
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
Definition buffer.h:1239
static bool buf_write_u8(struct buffer *dest, uint8_t data)
Append a uint8_t to a buffer.
Definition buffer.h:1288
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
Definition buffer.h:2132
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
static char * format_hex(const uint8_t *data, size_t size, size_t maxoutput, struct gc_arena *gc)
Format a binary buffer as a hex string with spaces every 4 bytes.
Definition buffer.h:960
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
Definition buffer.h:2036
static bool buf_defined(const struct buffer *buf)
Return true iff buf has a non-NULL data pointer.
Definition buffer.h:399
#define buf_init(buf, offset)
Definition buffer.h:364
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
void prng_bytes(uint8_t *output, int len)
Definition crypto.c:1695
Data Channel Cryptography Module.
#define D_PROXY
Definition errlevel.h:72
#define D_SHOW_KEYS
Definition errlevel.h:118
#define M_INFO
Definition errlevel.h:54
#define D_LINK_ERRORS
Definition errlevel.h:56
static void openvpn_fd_set(socket_descriptor_t fd, fd_set *setp)
Definition fdmisc.h:44
int get_server_poll_remaining_time(const struct event_timeout *server_poll_timeout)
Definition forward.c:520
Interface functions to the internal and external multiplexers.
void DigestCalcResponse(const HASHHEX HA1, const char *pszNonce, const char *pszNonceCount, const char *pszCNonce, const char *pszQop, const char *pszMethod, const char *pszDigestUri, const HASHHEX HEntity, HASHHEX Response)
Definition httpdigest.c:91
void DigestCalcHA1(const char *pszAlg, const char *pszUserName, const char *pszRealm, const char *pszPassword, const char *pszNonce, const char *pszCNonce, HASHHEX SessionKey)
Definition httpdigest.c:61
unsigned char HASHHEX[HASHHEXLEN+1]
Definition httpdigest.h:26
static SERVICE_STATUS status
Definition interactive.c:52
void unprotect_user_pass(struct user_pass *up)
Decrypt username and password buffers in user_pass.
Definition misc.c:829
void purge_user_pass(struct user_pass *up, const bool force)
Definition misc.c:485
void protect_user_pass(struct user_pass *up)
Encrypt username and password buffers in user_pass.
Definition misc.c:809
#define GET_USER_PASS_MANAGEMENT
Definition misc.h:113
#define GET_USER_PASS_INLINE_CREDS
indicates that auth_file is actually inline creds
Definition misc.h:126
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.
Definition misc.h:155
#define GET_USER_PASS_PREVIOUS_CREDS_FAILED
Definition misc.h:119
#define CLEAR(x)
Definition basic.h:32
#define M_FATAL
Definition error.h:90
#define dmsg(flags,...)
Definition error.h:164
#define msg(flags,...)
Definition error.h:152
#define ASSERT(x)
Definition error.h:221
#define M_ERRNO
Definition error.h:95
static bool send_crlf(socket_descriptor_t sd)
Definition proxy.c:217
static struct user_pass static_proxy_user_pass
Definition proxy.c:62
static bool add_proxy_headers(const struct http_proxy_info *p, socket_descriptor_t sd, const char *host)
Definition proxy.c:541
bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd, struct timeval *timeout, volatile int *signal_received)
Definition proxy.c:65
static bool recv_line(socket_descriptor_t sd, char *buf, int len, const int timeout_sec, const bool verbose, struct buffer *lookahead, volatile int *signal_received)
Definition proxy.c:109
void http_proxy_close(struct http_proxy_info *hp)
Definition proxy.c:531
static void clear_user_pass_http(void)
Definition proxy.c:251
static char * get_pa_var(const char *key, const char *pa, struct gc_arena *gc)
Definition proxy.c:452
static const char * username_password_as_base64(const struct http_proxy_info *p, struct gc_arena *gc)
Definition proxy.c:240
struct http_proxy_info * http_proxy_new(const struct http_proxy_options *o)
Definition proxy.c:486
struct http_proxy_options * init_http_proxy_options_once(struct http_proxy_options **hpo, struct gc_arena *gc)
Definition proxy.c:44
static void store_proxy_authenticate(struct http_proxy_info *p, char *data)
Definition proxy.c:362
static bool get_key_value(const char *str, char *key, char *value, int max_key_len, int max_value_len, const char **endptr)
Definition proxy.c:373
bool proxy_send(socket_descriptor_t sd, const void *buf, size_t len)
Definition proxy.c:192
static bool send_line_crlf(socket_descriptor_t sd, const char *src)
Definition proxy.c:204
bool establish_http_proxy_passthru(struct http_proxy_info *p, socket_descriptor_t sd, const char *host, const char *port, const struct event_timeout *server_poll_timeout, struct buffer *lookahead, struct signal_info *sig_info)
Definition proxy.c:608
static void get_user_pass_http(struct http_proxy_info *p, const bool force)
Definition proxy.c:257
uint8_t * make_base64_string2(const uint8_t *str, int src_len, struct gc_arena *gc)
Definition proxy.c:223
uint8_t * make_base64_string(const uint8_t *str, struct gc_arena *gc)
Definition proxy.c:234
static int get_proxy_authenticate(socket_descriptor_t sd, int timeout, char **data, volatile int *signal_received)
Definition proxy.c:325
#define UP_TYPE_PROXY
Definition proxy.c:41
#define PAR_NCT
Definition proxy.h:51
#define MAX_CUSTOM_HTTP_HEADER
Definition proxy.h:43
#define HTTP_AUTH_BASIC
Definition proxy.h:31
#define HTTP_AUTH_NONE
Definition proxy.h:30
#define HTTP_AUTH_DIGEST
Definition proxy.h:32
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.
Definition sig.c:228
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
Definition sig.h:109
#define MSG_NOSIGNAL
Definition socket.h:251
static int openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition socket.h:316
static ssize_t openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
Definition socket.h:324
int openvpn_base64_encode(const void *data, int size, char **str)
Definition base64.c:51
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
uint8_t * data
Pointer to the allocated memory.
Definition buffer.h:78
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
const char * name
Definition proxy.h:39
const char * content
Definition proxy.h:40
struct user_pass up
Definition proxy.h:71
bool defined
Definition proxy.h:68
int auth_method
Definition proxy.h:69
bool queried_creds
Definition proxy.h:73
char * proxy_authenticate
Definition proxy.h:72
struct http_proxy_options options
Definition proxy.h:70
const char * http_version
Definition proxy.h:57
const char * port
Definition proxy.h:47
const char * user_agent
Definition proxy.h:58
const char * auth_method_string
Definition proxy.h:54
struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER]
Definition proxy.h:59
const char * server
Definition proxy.h:46
Container for unidirectional cipher and HMAC key material.
Definition crypto.h:145
volatile int signal_received
Definition sig.h:42
bool defined
Definition misc.h:56
char password[USER_PASS_LEN]
Definition misc.h:71
bool nocache
Definition misc.h:60
char username[USER_PASS_LEN]
Definition misc.h:70
SOCKET socket_descriptor_t
Definition syshead.h:441
#define SIGUSR1
Definition syshead.h:57
struct gc_arena gc
Definition test_ssl.c:138