OpenVPN
misc.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 * Copyright (C) 2014-2015 David Sommerseth <davids@redhat.com>
10 * Copyright (C) 2016-2026 David Sommerseth <davids@openvpn.net>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, see <https://www.gnu.org/licenses/>.
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include "syshead.h"
30
31#include "buffer.h"
32#include "misc.h"
33#include "base64.h"
34#include "tun.h"
35#include "error.h"
36#include "otime.h"
37#include "plugin.h"
38#include "options.h"
39#include "manage.h"
40#include "crypto.h"
41#include "route.h"
42#include "console.h"
43#include "win32.h"
44
45#include "memdbg.h"
46
47#ifdef ENABLE_IPROUTE
48const char *iproute_path = IPROUTE_PATH; /* GLOBAL */
49#endif
50
51/*
52 * Set standard file descriptors to /dev/null
53 */
54void
55set_std_files_to_null(bool stdin_only)
56{
57#if defined(HAVE_DUP) && defined(HAVE_DUP2)
58 int fd;
59 if ((fd = open("/dev/null", O_RDWR, 0)) != -1)
60 {
61 dup2(fd, 0);
62 if (!stdin_only)
63 {
64 dup2(fd, 1);
65 dup2(fd, 2);
66 }
67 if (fd > 2)
68 {
69 close(fd);
70 }
71 }
72#endif
73}
74
75#if defined(__GNUC__) || defined(__clang__)
76#pragma GCC diagnostic push
77#pragma GCC diagnostic ignored "-Wconversion"
78#endif
79
80#ifdef ENABLE_MANAGEMENT
81/* Get username/password from the management interface */
82static bool
83auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags,
84 const char *auth_challenge)
85{
86 const char *sc = NULL;
87
89 {
90 management_auth_failure(management, prefix, "previous auth credentials failed");
91 }
92
94 {
95 sc = auth_challenge;
96 }
97 if (!management_query_user_pass(management, up, prefix, flags, sc))
98 {
99 if ((flags & GET_USER_PASS_NOFATAL) != 0)
100 {
101 return false;
102 }
103 else
104 {
105 msg(M_FATAL,
106 "ERROR: could not read %s username/password/ok/string from management interface",
107 prefix);
108 }
109 }
110 return true;
111}
112
126static struct auth_challenge_info *
128{
130
131 struct auth_challenge_info *ac;
132 const int len = strlen(auth_challenge);
133 char *work = (char *)gc_malloc(len + 1, false, gc);
134 const char *cp;
135
136 struct buffer b;
137 buf_set_read(&b, (const uint8_t *)auth_challenge, len);
138
140
141 /* parse prefix */
142 if (!buf_parse(&b, ':', work, len))
143 {
144 return NULL;
145 }
146 if (strcmp(work, "CRV1"))
147 {
148 return NULL;
149 }
150
151 /* parse flags */
152 if (!buf_parse(&b, ':', work, len))
153 {
154 return NULL;
155 }
156 for (cp = work; *cp != '\0'; ++cp)
157 {
158 const char c = *cp;
159 if (c == 'E')
160 {
161 ac->flags |= CR_ECHO;
162 }
163 else if (c == 'R')
164 {
165 ac->flags |= CR_RESPONSE;
166 }
167 }
168
169 /* parse state ID */
170 if (!buf_parse(&b, ':', work, len))
171 {
172 return NULL;
173 }
174 ac->state_id = string_alloc(work, gc);
175
176 /* parse user name */
177 if (!buf_parse(&b, ':', work, len))
178 {
179 return NULL;
180 }
181 ac->user = (char *)gc_malloc(strlen(work) + 1, true, gc);
182 openvpn_base64_decode(work, (void *)ac->user, -1);
183
184 /* parse challenge text */
186
187 return ac;
188}
189
190#endif /* ifdef ENABLE_MANAGEMENT */
191
192#if defined(__GNUC__) || defined(__clang__)
193#pragma GCC diagnostic pop
194#endif
195
196/*
197 * Get and store a username/password
198 */
199
200bool
201get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix,
202 const unsigned int flags, const char *auth_challenge)
203{
204 struct gc_arena gc = gc_new();
205
206 if (!up->defined)
207 {
208 bool from_authfile = (auth_file && !streq(auth_file, "stdin"));
209 bool username_from_stdin = false;
210 bool password_from_stdin = false;
211 bool response_from_stdin = true;
212
215 {
216 msg(M_WARN, "Note: previous '%s' credentials failed", prefix);
217 }
218#ifdef ENABLE_MANAGEMENT
219 /*
220 * Get username/password from management interface?
221 */
222 if (management && (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))
224 {
225 response_from_stdin = false;
226 if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
227 {
228 return false;
229 }
230 }
231 else
232#endif /* ifdef ENABLE_MANAGEMENT */
233 /*
234 * Get NEED_OK confirmation from the console
235 */
236 if (flags & GET_USER_PASS_NEED_OK)
237 {
238 struct buffer user_prompt = alloc_buf_gc(128, &gc);
239
240 buf_printf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->username);
241 if (!query_user_SINGLE(BSTR(&user_prompt), up->password, USER_PASS_LEN, false))
242 {
243 msg(M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
244 }
245
246 if (!strlen(up->password))
247 {
248 strcpy(up->password, "ok");
249 }
250 }
251 else if (flags & GET_USER_PASS_INLINE_CREDS)
252 {
253 struct buffer buf;
254 buf_set_read(&buf, (uint8_t *)auth_file, strlen(auth_file) + 1);
255 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
256 {
257 buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
258 }
259 buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
260
261 if (strlen(up->password) == 0)
262 {
263 password_from_stdin = 1;
264 }
265 }
266 /*
267 * Read from auth file unless this is a dynamic challenge request.
268 */
269 else if (from_authfile && !(flags & GET_USER_PASS_DYNAMIC_CHALLENGE))
270 {
271 /*
272 * Try to get username/password from a file.
273 */
274 FILE *fp;
275 char password_buf[USER_PASS_LEN] = { '\0' };
276
277 fp = platform_fopen(auth_file, "r");
278 if (!fp)
279 {
280 msg(M_ERR, "Error opening '%s' auth file: %s", prefix, auth_file);
281 }
282
283 if ((flags & GET_USER_PASS_PASSWORD_ONLY) == 0)
284 {
285 /* Read username first */
286 if (fgets(up->username, USER_PASS_LEN, fp) == NULL)
287 {
288 msg(M_FATAL, "Error reading username from %s authfile: %s", prefix,
289 auth_file);
290 }
291 }
292 chomp(up->username);
293
294 if (fgets(password_buf, USER_PASS_LEN, fp) != NULL)
295 {
296 chomp(password_buf);
297 }
298
299 if (flags & GET_USER_PASS_PASSWORD_ONLY && !password_buf[0])
300 {
301 msg(M_FATAL, "Error reading password from %s authfile: %s", prefix, auth_file);
302 }
303
304 if (password_buf[0])
305 {
306 strncpy(up->password, password_buf, USER_PASS_LEN);
307 }
308 else
309 {
310 password_from_stdin = 1;
311 }
312
313 fclose(fp);
314
315 if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && strlen(up->username) == 0)
316 {
317 msg(M_FATAL, "ERROR: username from %s authfile '%s' is empty", prefix,
318 auth_file);
319 }
320 }
321 else
322 {
323 username_from_stdin = true;
324 password_from_stdin = true;
325 }
326
327 /*
328 * Get username/password from standard input?
329 */
330 if (username_from_stdin || password_from_stdin || response_from_stdin)
331 {
332#ifdef ENABLE_MANAGEMENT
333 /* If management-query-passwords is true, we could be here because
334 * of no password present in auth-file or inline. In that case
335 * query via the management interface instead of stdin/console.
336 */
337 if (management && (flags & GET_USER_PASS_MANAGEMENT)
339 && password_from_stdin
340 && !(flags & GET_USER_PASS_USERNAME_ONLY))
341 {
342 msg(D_LOW,
343 "No '%s' password found in authfile or inline. Querying the management interface",
344 prefix);
345 if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
346 {
347 return false;
348 }
349 }
350 else if (auth_challenge && (flags & GET_USER_PASS_DYNAMIC_CHALLENGE) && response_from_stdin)
351 {
353 if (ac)
354 {
355 char *response = (char *)gc_malloc(USER_PASS_LEN, false, &gc);
356 struct buffer packed_resp, challenge;
357
358 challenge = alloc_buf_gc(14 + strlen(ac->challenge_text), &gc);
359 buf_printf(&challenge, "CHALLENGE: %s", ac->challenge_text);
360 buf_set_write(&packed_resp, (uint8_t *)up->password, USER_PASS_LEN);
361
362 if (!query_user_SINGLE(BSTR(&challenge), response,
364 {
365 msg(M_FATAL, "ERROR: could not read challenge response from stdin");
366 }
368 buf_printf(&packed_resp, "CRV1::%s::%s", ac->state_id, response);
369 }
370 else
371 {
372 msg(M_FATAL, "ERROR: received malformed challenge request from server");
373 }
374 }
375 else
376#endif /* ifdef ENABLE_MANAGEMENT */
377 {
378 struct buffer user_prompt = alloc_buf_gc(128, &gc);
379 struct buffer pass_prompt = alloc_buf_gc(128, &gc);
380
382 buf_printf(&user_prompt, "Enter %s Username:", prefix);
383 buf_printf(&pass_prompt, "Enter %s Password:", prefix);
384
385 if (username_from_stdin && !(flags & GET_USER_PASS_PASSWORD_ONLY))
386 {
387 query_user_add(BSTR(&user_prompt), up->username, USER_PASS_LEN, true);
388 }
389
390 if (password_from_stdin && !(flags & GET_USER_PASS_USERNAME_ONLY))
391 {
392 query_user_add(BSTR(&pass_prompt), up->password, USER_PASS_LEN, false);
393 }
394
395 if (!query_user_exec())
396 {
397 msg(M_FATAL, "ERROR: Failed retrieving username or password");
398 }
399
400 if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
401 {
402 if (strlen(up->username) == 0)
403 {
404 msg(M_FATAL, "ERROR: %s username is empty", prefix);
405 }
406 }
407
408#ifdef ENABLE_MANAGEMENT
410 && response_from_stdin)
411 {
412 char *response = (char *)gc_malloc(USER_PASS_LEN, false, &gc);
413 struct buffer packed_resp, challenge;
414 char *pw64 = NULL, *resp64 = NULL;
415
416 challenge = alloc_buf_gc(14 + strlen(auth_challenge), &gc);
417 buf_printf(&challenge, "CHALLENGE: %s", auth_challenge);
418
419 if (!query_user_SINGLE(BSTR(&challenge), response, USER_PASS_LEN,
421 {
422 msg(M_FATAL, "ERROR: could not retrieve static challenge response");
423 }
425 {
426 if (openvpn_base64_encode(up->password, (int)strlen(up->password), &pw64) == -1
427 || openvpn_base64_encode(response, (int)strlen(response), &resp64) == -1)
428 {
429 msg(M_FATAL, "ERROR: could not base64-encode password/static_response");
430 }
431 buf_set_write(&packed_resp, (uint8_t *)up->password, USER_PASS_LEN);
432 buf_printf(&packed_resp, "SCRV1:%s:%s", pw64, resp64);
433 string_clear(pw64);
434 free(pw64);
435 string_clear(resp64);
436 free(resp64);
437 }
438 else
439 {
440 if (strlen(up->password) + strlen(response) >= USER_PASS_LEN)
441 {
442 msg(M_FATAL,
443 "ERROR: could not concatenate password/static_response: string too long");
444 }
445 strncat(up->password, response, USER_PASS_LEN - strlen(up->password) - 1);
446 }
447 }
448#endif /* ifdef ENABLE_MANAGEMENT */
449 }
450 }
451
452 /* Use tag for blank password if we are not prompting for one */
453 if (flags & GET_USER_PASS_USERNAME_ONLY)
454 {
455 strncpy(up->password, blank_up, sizeof(up->password));
456 }
457
460
461 up->defined = true;
462 }
463
464#if 0
465 msg(M_INFO, "GET_USER_PASS %s u='%s' p='%s'", prefix, up->username, up->password);
466#endif
467
468 gc_free(&gc);
469
470 return true;
471}
472
473void
474purge_user_pass(struct user_pass *up, const bool force)
475{
476 const bool nocache = up->nocache;
477
478 if (nocache || force)
479 {
480 secure_memzero(up, sizeof(*up));
481 up->nocache = nocache;
482 }
483 else
484 {
485 static bool warn_shown = false;
486
488 /*
489 * don't show warning if the pass has been replaced by a token: this is an
490 * artificial "auth-nocache"
491 */
492 if (!warn_shown)
493 {
494 msg(M_WARN,
495 "WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this");
496 warn_shown = true;
497 }
498 }
499}
500
501void
502set_auth_token(struct user_pass *tk, const char *token)
503{
504 if (strlen(token))
505 {
507 strncpynt(tk->password, token, USER_PASS_LEN);
508 tk->token_defined = true;
509
510 /*
511 * If username already set, tk is fully defined.
512 */
513 if (strlen(tk->username))
514 {
515 tk->defined = true;
516 }
518 }
519}
520
521void
522set_auth_token_user(struct user_pass *tk, const char *username)
523{
524 if (strlen(username))
525 {
527 /* Clear the username before decoding to ensure no old material is left
528 * and also allow decoding to not use all space to ensure the last byte is
529 * always 0 */
530 CLEAR(tk->username);
531 int len = openvpn_base64_decode(username, tk->username, USER_PASS_LEN - 1);
532 tk->defined = len > 0;
533 if (!tk->defined)
534 {
535 msg(D_PUSH, "Error decoding auth-token-username");
536 }
538 }
539}
540
541
542/*
543 * Process string received by untrusted peer before
544 * printing to console or log file.
545 *
546 * Assumes that string has been null terminated.
547 */
548const char *
549safe_print(const char *str, struct gc_arena *gc)
550{
551 return string_mod_const(str, CC_PRINT, CC_CRLF, '.', gc);
552}
553
554const char **
555make_arg_array(const char *first, const char *parms, struct gc_arena *gc)
556{
557 char **ret = NULL;
558 int base = 0;
559 const int max_parms = MAX_PARMS + 2;
560 int n = 0;
561
562 /* alloc return array */
563 ALLOC_ARRAY_CLEAR_GC(ret, char *, max_parms, gc);
564
565 /* process first parameter, if provided */
566 if (first)
567 {
568 ret[base++] = string_alloc(first, gc);
569 }
570
571 if (parms)
572 {
573 n = parse_line(parms, &ret[base], max_parms - base - 1, "make_arg_array", 0, M_WARN, gc);
574 ASSERT(n >= 0 && n + base + 1 <= max_parms);
575 }
576 ret[base + n] = NULL;
577
578 return (const char **)ret;
579}
580
581static const char **
582make_inline_array(const char *str, struct gc_arena *gc)
583{
584 char line[OPTION_LINE_SIZE];
585 struct buffer buf;
586 int len = 0;
587 char **ret = NULL;
588 int i = 0;
589
590 buf_set_read(&buf, (const uint8_t *)str, strlen(str));
591 while (buf_parse(&buf, '\n', line, sizeof(line)))
592 {
593 ++len;
594 }
595
596 /* alloc return array */
597 ALLOC_ARRAY_CLEAR_GC(ret, char *, len + 1, gc);
598
599 buf_set_read(&buf, (const uint8_t *)str, strlen(str));
600 while (buf_parse(&buf, '\n', line, sizeof(line)))
601 {
602 chomp(line);
603 ASSERT(i < len);
604 ret[i] = string_alloc(skip_leading_whitespace(line), gc);
605 ++i;
606 }
607 ASSERT(i <= len);
608 ret[i] = NULL;
609 return (const char **)ret;
610}
611
612static const char **
613make_arg_copy(char **p, struct gc_arena *gc)
614{
615 char **ret = NULL;
616 const int len = string_array_len((const char **)p);
617 const int max_parms = len + 1;
618 int i;
619
620 /* alloc return array */
621 ALLOC_ARRAY_CLEAR_GC(ret, char *, max_parms, gc);
622
623 for (i = 0; i < len; ++i)
624 {
625 ret[i] = p[i];
626 }
627
628 return (const char **)ret;
629}
630
631const char **
632make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
633{
634 const int argc = string_array_len((const char **)p);
635 if (is_inline)
636 {
637 return make_inline_array(p[0], gc);
638 }
639 else if (argc == 0)
640 {
641 return make_arg_array(NULL, NULL, gc);
642 }
643 else if (argc == 1)
644 {
645 return make_arg_array(p[0], NULL, gc);
646 }
647 else if (argc == 2)
648 {
649 return make_arg_array(p[0], p[1], gc);
650 }
651 else
652 {
653 return make_arg_copy(p, gc);
654 }
655}
656
657/*
658 * Remove security-sensitive strings from control message
659 * so that they will not be output to log file.
660 */
661const char *
662sanitize_control_message(const char *src, struct gc_arena *gc)
663{
664 char *ret = gc_malloc(strlen(src) + 1, false, gc);
665 char *dest = ret;
666 bool redact = false;
667 int skip = 0;
668
669 for (;;)
670 {
671 const char c = *src;
672 if (c == '\0')
673 {
674 break;
675 }
676 if (c == 'S' && !strncmp(src, "SESS_ID_", 8))
677 {
678 skip = 7;
679 redact = true;
680 }
681 else if (c == 'e' && !strncmp(src, "echo ", 5))
682 {
683 skip = 4;
684 redact = true;
685 }
686 else if (!check_debug_level(D_SHOW_KEYS) && (c == 'a' && !strncmp(src, "auth-token ", 11)))
687 {
688 /* Unless --verb is 7 or higher (D_SHOW_KEYS), hide
689 * the auth-token value coming in the src string
690 */
691 skip = 10;
692 redact = true;
693 }
694
695 if (c == ',') /* end of redacted item? */
696 {
697 skip = 0;
698 redact = false;
699 }
700
701 if (redact)
702 {
703 if (skip > 0)
704 {
705 --skip;
706 *dest++ = c;
707 }
708 }
709 else
710 {
711 *dest++ = c;
712 }
713
714 ++src;
715 }
716 *dest = '\0';
717 return ret;
718}
719
720/* helper to parse peer_info received from multi client, validate
721 * (this is untrusted data) and put into environment
722 */
723bool
725{
726 int state = 0;
727 while (*line)
728 {
729 const uint8_t c = *line;
730 switch (state)
731 {
732 case 0:
733 case 1:
734 if (c == '=' && state == 1)
735 {
736 state = 2;
737 }
738 else if (isalnum(c) || c == '_')
739 {
740 state = 1;
741 }
742 else
743 {
744 return false;
745 }
746 /* Intentional [[fallthrough]]; */
747 case 2:
748 /* after the '=', replace non-printable or shell meta with '_' */
749 if (!isprint(c) || isspace(c) || c == '$' || c == '(' || c == '`')
750 {
751 *line = '_';
752 }
753 }
754 line++;
755 }
756 return (state == 2);
757}
758
759void
760output_peer_info_env(struct env_set *es, const char *peer_info)
761{
762 char line[256];
763 struct buffer buf;
764 buf_set_read(&buf, (const uint8_t *)peer_info, strlen(peer_info));
765 while (buf_parse(&buf, '\n', line, sizeof(line)))
766 {
767 chomp(line);
769 && (strncmp(line, "IV_", 3) == 0 || strncmp(line, "UV_", 3) == 0
770 || strncmp(line, "ID", 2) == 0))
771 {
772 msg(M_INFO, "peer info: %s", line);
773 env_set_add(es, line);
774 }
775 else
776 {
777 msg(M_WARN, "validation failed on peer_info line received");
778 }
779 }
780}
781
782struct buffer
783prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
784{
785 size_t len = strlen(dir) + strlen(PATH_SEPARATOR_STR) + strlen(path) + 1;
786 struct buffer combined_path = alloc_buf_gc(len, gc);
787 buf_printf(&combined_path, "%s%s%s", dir, PATH_SEPARATOR_STR, path);
788 ASSERT(combined_path.len > 0);
789
790 return combined_path;
791}
792
793void
795{
796 if (up->protected)
797 {
798 return;
799 }
800#ifdef _WIN32
801 if (protect_buffer_win32(up->username, sizeof(up->username))
802 && protect_buffer_win32(up->password, sizeof(up->password)))
803 {
804 up->protected = true;
805 }
806 else
807 {
808 purge_user_pass(up, true);
809 }
810#endif
811}
812
813void
815{
816 if (!up->protected)
817 {
818 return;
819 }
820#ifdef _WIN32
821 if (unprotect_buffer_win32(up->username, sizeof(up->username))
822 && unprotect_buffer_win32(up->password, sizeof(up->password)))
823 {
824 up->protected = false;
825 }
826 else
827 {
828 purge_user_pass(up, true);
829 }
830#endif
831}
const char * skip_leading_whitespace(const char *str)
Return a pointer past any leading whitespace in a string.
Definition buffer.c:547
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:226
void string_clear(char *str)
Securely clear a null-terminated string.
Definition buffer.c:639
void chomp(char *str)
Remove trailing newline and carriage-return characters from a string.
Definition buffer.c:584
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
Definition buffer.c:318
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
bool string_mod(char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
Modifies a string in place by replacing certain classes of characters of it with a specified characte...
Definition buffer.c:995
const char * string_mod_const(const char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace, struct gc_arena *gc)
Returns a copy of a string with certain classes of characters of it replaced with a specified charact...
Definition buffer.c:1045
int string_array_len(const char **array)
Return the number of elements in a NULL-terminated array of strings.
Definition buffer.c:651
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Extract the next token from a buffer, delimited by a given character.
Definition buffer.c:765
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:606
Buffer management functions and garbage collection.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
Allocate and zero-initialise a garbage-collected array of n elements.
Definition buffer.h:2093
#define CC_CRLF
carriage return or newline
Definition buffer.h:1737
static void buf_set_write(struct buffer *buf, uint8_t *data, int size)
Initialise a buffer with an externally provided writable memory region.
Definition buffer.h:658
static void buf_set_read(struct buffer *buf, const uint8_t *data, size_t size)
Initialise a buffer with an externally provided read-only memory region.
Definition buffer.h:687
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
Definition buffer.h:769
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
Definition buffer.h:2134
static void strncpynt(char *dest, const char *src, size_t maxlen)
Like strncpy() but always null-terminates the destination.
Definition buffer.h:710
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1976
#define CC_PRINT
printable (>= 32, != 127)
Definition buffer.h:1708
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1960
void query_user_clear(void)
Wipes all data put into all of the query_user structs.
Definition console.c:44
void query_user_add(char *prompt, char *resp, int resp_len, bool echo)
Adds an item to ask the user for.
Definition console.c:56
static bool query_user_SINGLE(char *prompt, char *resp, int resp_len, bool echo)
A plain "make Gert happy" wrapper.
Definition console.h:118
static bool query_user_exec(void)
Wrapper function enabling query_user_exec() if no alternative methods have been enabled.
Definition console.h:103
Data Channel Cryptography Module.
void env_set_add(struct env_set *es, const char *str)
Definition env_set.c:192
#define D_PUSH
Definition errlevel.h:82
#define D_SHOW_KEYS
Definition errlevel.h:120
#define D_LOW
Definition errlevel.h:96
#define M_INFO
Definition errlevel.h:54
void management_auth_failure(struct management *man, const char *type, const char *reason)
Definition manage.c:3211
bool management_query_user_pass(struct management *man, struct user_pass *up, const char *type, const unsigned int flags, const char *static_challenge)
Definition manage.c:3609
static bool management_query_user_pass_enabled(const struct management *man)
Definition manage.h:421
static const char ** make_inline_array(const char *str, struct gc_arena *gc)
Definition misc.c:582
void unprotect_user_pass(struct user_pass *up)
Decrypt username and password buffers in user_pass.
Definition misc.c:814
bool get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *auth_challenge)
Retrieves the user credentials from various sources depending on the flags.
Definition misc.c:201
const char ** make_arg_array(const char *first, const char *parms, struct gc_arena *gc)
Definition misc.c:555
void purge_user_pass(struct user_pass *up, const bool force)
Definition misc.c:474
bool validate_peer_info_line(char *line)
Definition misc.c:724
void set_auth_token_user(struct user_pass *tk, const char *username)
Sets the auth-token username by base64 decoding the passed username.
Definition misc.c:522
void set_std_files_to_null(bool stdin_only)
Definition misc.c:55
void output_peer_info_env(struct env_set *es, const char *peer_info)
Definition misc.c:760
struct buffer prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
Prepend a directory to a path.
Definition misc.c:783
static struct auth_challenge_info * parse_auth_challenge(const char *auth_challenge, struct gc_arena *gc)
Parses an authentication challenge string and returns an auth_challenge_info structure.
Definition misc.c:127
void protect_user_pass(struct user_pass *up)
Encrypt username and password buffers in user_pass.
Definition misc.c:794
const char ** make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
Definition misc.c:632
static const char ** make_arg_copy(char **p, struct gc_arena *gc)
Definition misc.c:613
const char * safe_print(const char *str, struct gc_arena *gc)
Definition misc.c:549
const char * sanitize_control_message(const char *src, struct gc_arena *gc)
Definition misc.c:662
static bool auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags, const char *auth_challenge)
Definition misc.c:83
void set_auth_token(struct user_pass *tk, const char *token)
Sets the auth-token to token.
Definition misc.c:502
#define USER_PASS_LEN
Definition misc.h:67
#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT
indicates password and response should be concatenated
Definition misc.h:128
#define GET_USER_PASS_MANAGEMENT
Definition misc.h:113
#define GET_USER_PASS_PASSWORD_ONLY
Definition misc.h:115
#define GET_USER_PASS_USERNAME_ONLY
indicate that only username should be prompted for auth-user-pass
Definition misc.h:130
#define GET_USER_PASS_STATIC_CHALLENGE_ECHO
SCRV1 protocol – echo response.
Definition misc.h:123
#define CR_ECHO
Definition misc.h:80
#define CR_RESPONSE
Definition misc.h:81
#define GET_USER_PASS_INLINE_CREDS
indicates that auth_file is actually inline creds
Definition misc.h:126
#define GET_USER_PASS_STATIC_CHALLENGE
SCRV1 protocol – static challenge.
Definition misc.h:122
#define GET_USER_PASS_NEED_OK
Definition misc.h:116
#define GET_USER_PASS_NOFATAL
Definition misc.h:117
static const char blank_up[]
Definition misc.h:52
#define GET_USER_PASS_PREVIOUS_CREDS_FAILED
Definition misc.h:119
#define GET_USER_PASS_DYNAMIC_CHALLENGE
CRV1 protocol – dynamic challenge.
Definition misc.h:121
#define BOOL_CAST(x)
Definition basic.h:26
#define CLEAR(x)
Definition basic.h:32
static bool check_debug_level(msglvl_t level)
Definition error.h:253
#define M_FATAL
Definition error.h:90
#define M_ERR
Definition error.h:106
#define msg(flags,...)
Definition error.h:152
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
#define streq(x, y)
Definition options.h:727
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc)
#define MAX_PARMS
Definition options.h:51
#define OPTION_LINE_SIZE
Definition options.h:57
FILE * platform_fopen(const char *path, const char *mode)
Definition platform.c:500
int openvpn_base64_decode(const char *str, void *data, int size)
Definition base64.c:160
int openvpn_base64_encode(const void *data, int size, char **str)
Definition base64.c:51
static char * auth_challenge
Definition ssl.c:292
const char * user
Definition misc.h:84
const char * state_id
Definition misc.h:85
const char * challenge_text
Definition misc.h:86
unsigned int flags
Definition misc.h:82
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
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
bool token_defined
Definition misc.h:59
bool protected
Definition misc.h:61
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
#define PATH_SEPARATOR_STR
Definition syshead.h:433
struct gc_arena gc
Definition test_ssl.c:122
bool protect_buffer_win32(char *buf, DWORD len)
Encrypt a region of memory using CryptProtectMemory() with access restricted to the current process.
Definition win32.c:1629
bool unprotect_buffer_win32(char *buf, DWORD len)
Decrypt a previously encrypted region of memory using CryptUnProtectMemory() with access restricted t...
Definition win32.c:1647