OpenVPN
push.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 "push.h"
30
31#include "acc.h"
32#include "options.h"
33#include "crypto.h"
34#include "ssl.h"
35#include "ssl_verify.h"
36#include "ssl_ncp.h"
37#include "manage.h"
38
39#include "memdbg.h"
40#include "ssl_util.h"
41#include "options_util.h"
42#include "resolve.h"
43
44/*
45 * Auth username/password
46 *
47 * Client received an authentication failed message from server.
48 * Runs on client.
49 */
50void
51receive_auth_failed(struct context *c, const struct buffer *buffer)
52{
53 msg(M_VERB0, "AUTH: Received control message: %s", CBSTR(buffer));
54 c->options.no_advance = true;
55
56 if (!c->options.pull)
57 {
58 return;
59 }
60
61 struct buffer buf = *buffer;
62
63 /* If the AUTH_FAIL message ends with a , it is an extended message that
64 * contains further flags */
65 bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
66
67 const char *reason = NULL;
68 if (authfail_extended && BLEN(&buf))
69 {
70 reason = CBSTR(&buf);
71 }
72
73 if (authfail_extended && buf_string_match_head_str(&buf, "TEMP"))
74 {
75 parse_auth_failed_temp(&c->options, reason + strlen("TEMP"));
76 register_signal(c->sig, SIGUSR1, "auth-temp-failure (server temporary reject)");
77 }
78
79 /* Before checking how to react on AUTH_FAILED, first check if the
80 * failed auth might be the result of an expired auth-token.
81 * Note that a server restart will trigger a generic AUTH_FAILED
82 * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
83 * identical for this scenario */
84 else if (ssl_clean_auth_token())
85 {
86 /* SOFT-SIGUSR1 -- Auth failure error */
87 register_signal(c->sig, SIGUSR1, "auth-failure (auth-token)");
88 c->options.no_advance = true;
89 }
90 else
91 {
92 switch (auth_retry_get())
93 {
94 case AR_NONE:
95 /* SOFT-SIGTERM -- Auth failure error */
96 register_signal(c->sig, SIGTERM, "auth-failure");
97 break;
98
99 case AR_INTERACT:
100 ssl_purge_auth(false);
101 /* Intentional [[fallthrough]]; */
102
103 case AR_NOINTERACT:
104 /* SOFT-SIGTUSR1 -- Auth failure error */
105 register_signal(c->sig, SIGUSR1, "auth-failure");
106 break;
107
108 default:
109 ASSERT(0);
110 }
111 }
112#ifdef ENABLE_MANAGEMENT
113 if (management)
114 {
116 }
117 /*
118 * Save the dynamic-challenge text even when management is defined
119 */
120 if (authfail_extended && buf_string_match_head_str(&buf, "CRV1:") && BLEN(&buf))
121 {
123 }
124#endif /* ifdef ENABLE_MANAGEMENT */
125}
126
127/*
128 * Act on received restart message from server
129 */
130void
131server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart,
132 const int adv)
133{
134 if (c->options.pull)
135 {
136 struct buffer buf = *buffer;
137 const char *m = "";
138 if (buf_advance(&buf, adv) && buf_read_u8(&buf) == ',' && BLEN(&buf))
139 {
140 m = BSTR(&buf);
141 }
142
143 /* preserve cached passwords? */
144 /* advance to next server? */
145 {
146 bool purge = true;
147
148 if (m[0] == '[')
149 {
150 int i;
151 for (i = 1; m[i] != '\0' && m[i] != ']'; ++i)
152 {
153 if (m[i] == 'P')
154 {
155 purge = false;
156 }
157 else if (m[i] == 'N')
158 {
159 /* next server? */
160 c->options.no_advance = false;
161 }
162 }
163 }
164 if (purge)
165 {
166 ssl_purge_auth(true);
167 }
168 }
169
170 if (restart)
171 {
172 msg(D_STREAM_ERRORS, "Connection reset command was pushed by server ('%s')", m);
173 /* SOFT-SIGUSR1 -- server-pushed connection reset */
174 register_signal(c->sig, SIGUSR1, "server-pushed-connection-reset");
175 }
176 else
177 {
178 msg(D_STREAM_ERRORS, "Halt command was pushed by server ('%s')", m);
179 /* SOFT-SIGTERM -- server-pushed halt */
180 register_signal(c->sig, SIGTERM, "server-pushed-halt");
181 }
182#ifdef ENABLE_MANAGEMENT
183 if (management)
184 {
185 management_notify("info", c->sig->signal_text, m);
186 }
187#endif
188 }
189}
190
191void
193{
194 dmsg(D_STREAM_ERRORS, "CC-EEN exit message received by peer");
195 /* With control channel exit notification, we want to give the session
196 * enough time to handle retransmits and acknowledgment, so that eventual
197 * retries from the client to resend the exit or ACKs will not trigger
198 * a new session (we already forgot the session but the packet's HMAC
199 * is still valid). This could happen for the entire period that the
200 * HMAC timeslot is still valid, but waiting five seconds here does not
201 * hurt much, takes care of the retransmits, and is easier code-wise.
202 *
203 * This does not affect OCC exit since the HMAC session code will
204 * ignore DATA packets
205 * */
206 if (c->options.mode == MODE_SERVER)
207 {
208 if (!schedule_exit(c))
209 {
210 /* Return early when we don't need to notify management */
211 return;
212 }
213 }
214 else
215 {
216 register_signal(c->sig, SIGUSR1, "remote-exit");
217 }
218#ifdef ENABLE_MANAGEMENT
219 if (management)
220 {
221 management_notify("info", "remote-exit", "EXIT");
222 }
223#endif
224}
225
226static void
228{
229 int max_acc_len = 0;
230 struct tls_multi *multi = c->c2.tls_multi;
231
232 if (multi->acc_negotiated_protocols)
233 {
234 return;
235 }
236
237 if (!multi->opt.acc_protocols || !c->options.pull)
238 {
239 msg(D_PUSH_ERRORS, "Peer tried to push app custom control list "
240 "without client announcing support for it");
241 return;
242 }
243
244 /* example string to parse: ACC:1400 A:6 flower:happy */
245 /* Skip over the ACC: prefix */
246 buf_advance(buf, 4);
247
248 struct gc_arena gc = gc_new();
249 const char *protocols = parse_acc_parameters(buf_cstr(buf), " ", &max_acc_len, false, &gc);
250 if (!protocols)
251 {
252 msg(D_PUSH_ERRORS, "WARNING: Received ACC info command with invalid parameters");
253 gc_free(&gc);
254 return;
255 }
256
257 /* check if the list from the server is a real subset of our list */
258 struct buffer common_list = get_list_intersection(&gc, protocols, multi->opt.acc_protocols);
259
260 if (buf_len(&common_list) == 0 || !streq(protocols, buf_cstr(&common_list)))
261 {
262 msg(D_PUSH_ERRORS, "App custom control list from server contains "
263 "unsupported protocols");
264 gc_free(&gc);
265 return;
266 }
267
268 multi->acc_negotiated_protocols = string_alloc(protocols, NULL);
269 multi->acc_max_message_length = max_acc_len;
271 gc_free(&gc);
272}
273
274void
275peer_pushed_info(struct context *c, const struct buffer *buffer, const int adv)
276{
277 const char *m = "";
278 struct buffer buf = *buffer;
279
280 if (buf_advance(&buf, adv) && buf_read_u8(&buf) == ',' && BLEN(&buf))
281 {
282 m = BSTR(&buf);
283 }
284
285 if (strncmp(m, "ACC:", 4) == 0)
286 {
288 return;
289 }
290
291#ifdef ENABLE_MANAGEMENT
292 struct gc_arena gc;
293 if (management)
294 {
295 gc = gc_new();
296
297 /*
298 * We use >INFOMSG here instead of plain >INFO since INFO is used to
299 * for management greeting and we don't want to confuse the client
300 */
301 struct buffer out = alloc_buf_gc(256, &gc);
302 if (buf_printf(&out, ">%s:%s", "INFOMSG", m))
303 {
305 }
306 else
307 {
309 "WARNING: Received INFO command is too long, won't notify management client.");
310 }
311
312 gc_free(&gc);
313 }
314#endif
315 msg(D_PUSH, "Info command was pushed by peer ('%s')", m);
316}
317
318void
319receive_cr_response(struct context *c, const struct buffer *buffer)
320{
321 struct buffer buf = *buffer;
322 const char *m = "";
323
324 if (buf_advance(&buf, 11) && buf_read_u8(&buf) == ',' && BLEN(&buf))
325 {
326 m = BSTR(&buf);
327 }
328#ifdef ENABLE_MANAGEMENT
330 const struct man_def_auth_context *mda = session->opt->mda_context;
331 const struct env_set *es = session->opt->es;
332 unsigned int mda_key_id = get_primary_key(c->c2.tls_multi)->mda_key_id;
333
334 management_notify_client_cr_response(mda_key_id, mda, es, m);
335#endif
336#if ENABLE_PLUGIN
338#endif
340 msg(D_PUSH, "CR response was sent by client ('%s')", m);
341}
342
343
351static void
352parse_auth_pending_keywords(const struct buffer *buffer, unsigned int *server_timeout)
353{
354 struct buffer buf = *buffer;
355
356 /* does the buffer start with "AUTH_PENDING," ? */
357 if (!buf_advance(&buf, strlen("AUTH_PENDING")) || !(buf_read_u8(&buf) == ',') || !BLEN(&buf))
358 {
359#ifdef ENABLE_MANAGEMENT
360 if (management)
361 {
363 NULL);
364 }
365#endif
366
367 return;
368 }
369
370 /* parse the keywords in the same way that push options are parsed */
371 char line[OPTION_LINE_SIZE];
372
373#ifdef ENABLE_MANAGEMENT
374 /* Need to do the management notification with the keywords before
375 * buf_parse is called, as it will insert \0 bytes into the buffer */
376 if (management)
377 {
379 NULL);
380 }
381#endif
382
383 while (buf_parse(&buf, ',', line, sizeof(line)))
384 {
385 if (sscanf(line, "timeout %u", server_timeout) != 1)
386 {
387 msg(D_PUSH, "ignoring AUTH_PENDING parameter: %s", line);
388 }
389 }
390}
391
392#if defined(__GNUC__) || defined(__clang__)
393#pragma GCC diagnostic push
394#pragma GCC diagnostic ignored "-Wsign-conversion"
395#endif
396
397void
398receive_auth_pending(struct context *c, const struct buffer *buffer)
399{
400 if (!c->options.pull)
401 {
402 return;
403 }
404
405 /* Cap the increase at the maximum time we are willing stay in the
406 * pending authentication state */
407 unsigned int max_timeout =
409
410 /* try to parse parameter keywords, default to hand-winow timeout if the
411 * server does not supply a timeout */
412 unsigned int server_timeout = c->options.handshake_window;
413 parse_auth_pending_keywords(buffer, &server_timeout);
414
415 msg(D_PUSH,
416 "AUTH_PENDING received, extending handshake timeout from %ds "
417 "to %us",
418 c->options.handshake_window, min_uint(max_timeout, server_timeout));
419
420 const struct key_state *ks = get_primary_key(c->c2.tls_multi);
421 c->c2.push_request_timeout = ks->established + min_uint(max_timeout, server_timeout);
422}
423
438static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
439 msglvl_t msglevel, const char *fmt, ...)
440#ifdef __GNUC__
441#if __USE_MINGW_ANSI_STDIO
442 __attribute__((format(gnu_printf, 4, 5)))
443#else
444 __attribute__((format(__printf__, 4, 5)))
445#endif
446#endif
447 ;
448
449/*
450 * Send auth failed message from server to client.
451 *
452 * Does nothing if an exit is already scheduled
453 */
454void
455send_auth_failed(struct context *c, const char *client_reason)
456{
457 if (!schedule_exit(c))
458 {
459 msg(D_TLS_DEBUG, "exit already scheduled for context");
460 return;
461 }
462
463 struct gc_arena gc = gc_new();
464 static const char auth_failed[] = "AUTH_FAILED";
465 size_t len;
466
467 len = (client_reason ? strlen(client_reason) + 1 : 0) + sizeof(auth_failed);
468 if (len > PUSH_BUNDLE_SIZE)
469 {
470 len = PUSH_BUNDLE_SIZE;
471 }
472
473 {
474 struct buffer buf = alloc_buf_gc(len, &gc);
475 buf_printf(&buf, auth_failed);
476 if (client_reason)
477 {
478 buf_printf(&buf, ",%s", client_reason);
479 }
480
481 /* We kill the whole session, send the AUTH_FAILED to any TLS session
482 * that might be active */
484 D_PUSH);
486 D_PUSH);
487
489 }
490
491 gc_free(&gc);
492}
493
494bool
496 const char *extra, unsigned int timeout)
497{
498 struct key_state *ks = &session->key[KS_PRIMARY];
499
500 static const char info_pre[] = "INFO_PRE,";
501
502 const char *const peer_info = tls_multi->peer_info;
503 unsigned int proto = extract_iv_proto(peer_info);
504
505 /* Calculate the maximum timeout and subtract the time we already waited */
506 unsigned int max_timeout =
508 time_t time_elapsed = now - ks->initial;
509 if (time_elapsed < 0 || time_elapsed >= (time_t)max_timeout)
510 {
511 return false;
512 }
513 max_timeout -= (unsigned int)time_elapsed;
514 timeout = min_uint(max_timeout, timeout);
515
516 struct gc_arena gc = gc_new();
517 if ((proto & IV_PROTO_AUTH_PENDING_KW) == 0)
518 {
520 }
521 else
522 {
523 static const char auth_pre[] = "AUTH_PENDING,timeout ";
524 /* Assume a worst case of 8 byte uint64 in decimal which */
525 /* needs 20 bytes */
526 size_t len = 20 + 1 + sizeof(auth_pre);
527 struct buffer buf = alloc_buf_gc(len, &gc);
528 buf_printf(&buf, auth_pre);
529 buf_printf(&buf, "%u", timeout);
531 }
532
533 size_t len = strlen(extra) + 1 + sizeof(info_pre);
534 if (len > PUSH_BUNDLE_SIZE)
535 {
536 gc_free(&gc);
537 return false;
538 }
539
540 struct buffer buf = alloc_buf_gc(len, &gc);
541 buf_printf(&buf, info_pre);
542 buf_printf(&buf, "%s", extra);
544
545 ks->auth_deferred_expire = now + timeout;
546
547 gc_free(&gc);
548 return true;
549}
550
551/*
552 * Send restart message from server to client.
553 */
554void
555send_restart(struct context *c, const char *kill_msg)
556{
557 schedule_exit(c);
558 send_control_channel_string(c, kill_msg ? kill_msg : "RESTART", D_PUSH);
559}
560
561/*
562 * Push/Pull
563 */
564
565void
567{
568 struct gc_arena gc = gc_new();
569 uint64_t option_types_found = 0;
570
571 msg(D_PUSH, "PUSH: Received control message: '%s'",
573
575 &option_types_found);
576
577 if (status == PUSH_MSG_ERROR)
578 {
579 msg(D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s",
581 }
584 {
585 c->options.push_option_types_found |= option_types_found;
586
587 /* delay bringing tun/tap up until --push parms received from remote */
589 {
591 {
592 goto error;
593 }
594 if (status == PUSH_MSG_REPLY)
595 {
596 if (!do_up(c, true, c->options.push_option_types_found))
597 {
598 msg(D_PUSH_ERRORS, "Failed to open tun/tap interface");
599 goto error;
600 }
601 }
602 else
603 {
604 /* Clear push_update_options_found for next PUSH_UPDATE sequence */
606
607 /* Use accumulated option_types_found for the entire PUSH_UPDATE sequence */
609 {
610 msg(M_WARN, "No updatable options found in incoming PUSH_UPDATE message");
611 }
613 {
614 msg(D_PUSH_ERRORS, "Failed to update options");
615 goto error;
616 }
617 }
618 }
621 }
622
623 goto cleanup;
624
625error:
626 register_signal(c->sig, SIGUSR1, "process-push-msg-failed");
627cleanup:
628 gc_free(&gc);
629}
630
631bool
633{
634 const struct key_state *ks = get_primary_key(c->c2.tls_multi);
635
636 /* We timeout here under two conditions:
637 * a) we reached the hard limit of push_request_timeout
638 * b) we have not seen anything from the server in hand_window time
639 *
640 * for non auth-pending scenario, push_request_timeout is the same as
641 * hand_window timeout. For b) every PUSH_REQUEST is a acknowledged by
642 * the server by a P_ACK_V1 packet that reset the keepalive timer
643 */
644
647 {
648 return send_control_channel_string(c, "PUSH_REQUEST", D_PUSH);
649 }
650 else
651 {
652 msg(D_STREAM_ERRORS, "No reply from server to push requests in %ds",
653 (int)(now - ks->established));
654 /* SOFT-SIGUSR1 -- server-pushed connection reset */
655 register_signal(c->sig, SIGUSR1, "no-push-reply");
656 return false;
657 }
658}
659
666void
668 struct push_list *push_list)
669{
670 /*
671 * If server uses --auth-gen-token and we have an auth token
672 * to send to the client
673 */
675 {
677
678 char *base64user = NULL;
680 (int)strlen(tls_multi->locked_username), &base64user);
681 if (ret < USER_PASS_LEN && ret > 0)
682 {
683 push_option_fmt(gc, push_list, M_USAGE, "auth-token-user %s", base64user);
684 }
685 free(base64user);
686 }
687}
688
696static void
698{
699 struct tls_multi *tls_multi = c->c2.tls_multi;
700 struct options *o = &c->options;
701
702 /* ipv6 */
704 {
705 push_option_fmt(gc, push_list, M_USAGE, "ifconfig-ipv6 %s/%d %s",
709 }
710
711 /* ipv4 */
714 {
717 {
719 }
720 push_option_fmt(gc, push_list, M_USAGE, "ifconfig %s %s",
723 }
724
726 {
728 }
729 /*
730 * If server uses --auth-gen-token and we have an auth token
731 * to send to the client
732 */
734
735 /*
736 * Push the selected cipher, at this point the cipher has been
737 * already negotiated and been fixed.
738 *
739 * We avoid pushing the cipher to clients not supporting NCP
740 * to avoid error messages in their logs
741 */
743 {
744 push_option_fmt(gc, push_list, M_USAGE, "cipher %s", o->ciphername);
745 }
746
747 struct buffer proto_flags = alloc_buf_gc(128, gc);
748
750 {
751 buf_printf(&proto_flags, " cc-exit");
752
753 /* if the cc exit flag is supported, pushing tls-ekm via protocol-flags
754 * is also supported */
756 {
757 buf_printf(&proto_flags, " tls-ekm");
758 }
759 }
761 {
762 push_option_fmt(gc, push_list, M_USAGE, "key-derivation tls-ekm");
763 }
764
766 {
767 buf_printf(&proto_flags, " dyn-tls-crypt");
768 }
769
771 {
772 buf_printf(&proto_flags, " aead-epoch");
773 }
774
775 if (buf_len(&proto_flags) > 0)
776 {
777 push_option_fmt(gc, push_list, M_USAGE, "protocol-flags%s", buf_str(&proto_flags));
778 }
779
780 /* Push our mtu to the peer if it supports pushable MTUs */
781 int client_max_mtu = peer_info_extract_uint(tls_multi->peer_info, "IV_MTU=");
782
783 if (client_max_mtu != 0)
784 {
785 push_option_fmt(gc, push_list, M_USAGE, "tun-mtu %d", o->ce.tun_mtu);
786 if (client_max_mtu < o->ce.tun_mtu)
787 {
788 msg(M_WARN,
789 "Warning: reported maximum MTU from client (%d) is lower "
790 "than MTU used on the server (%d). Add tun-mtu-max %d "
791 "to client configuration.",
792 client_max_mtu, o->ce.tun_mtu, o->ce.tun_mtu);
793 }
794 }
795
797 {
798 push_option_fmt(gc, push_list, M_USAGE, "custom-control %d A:6 %s",
800 }
801}
802
803#if defined(__GNUC__) || defined(__clang__)
804#pragma GCC diagnostic pop
805#endif
806
807static bool
808send_push_options(struct context *c, struct buffer *buf, struct push_list *push_list, size_t safe_cap,
809 bool *push_sent, bool *multi_push)
810{
811 struct push_entry *e = push_list->head;
812
813 while (e)
814 {
815 if (e->enable)
816 {
817 const size_t l = strlen(e->option);
818 if (!buf_size_valid(l))
819 {
820 msg(M_WARN, "--push option is too long");
821 return false;
822 }
823 if (BLENZ(buf) + l >= safe_cap)
824 {
825 buf_printf(buf, ",push-continuation 2");
826 {
827 const bool status = send_control_channel_string(c, BSTR(buf), D_PUSH);
828 if (!status)
829 {
830 return false;
831 }
832 *push_sent = true;
833 *multi_push = true;
834 buf_reset_len(buf);
835 buf_printf(buf, "%s", push_reply_cmd);
836 }
837 }
838 if (BLENZ(buf) + l >= safe_cap)
839 {
840 msg(M_WARN, "--push option is too long");
841 return false;
842 }
843 buf_printf(buf, ",%s", e->option);
844 }
845 e = e->next;
846 }
847 return true;
848}
849
850void
852{
853 struct gc_arena gc = gc_new();
854 struct push_list push_list = { 0 };
855 struct tls_session *session = &multi->session[TM_ACTIVE];
856
858
859 /* prepare auth token should always add the auth-token option */
860 struct push_entry *e = push_list.head;
861 ASSERT(e && e->enable);
862
863 /* Construct a mimimal control channel push reply message */
864 struct buffer buf = alloc_buf_gc(PUSH_BUNDLE_SIZE, &gc);
865 buf_printf(&buf, "%s,%s", push_reply_cmd, e->option);
867 gc_free(&gc);
868}
869
870bool
871send_push_reply(struct context *c, struct push_list *per_client_push_list)
872{
873 struct gc_arena gc = gc_new();
874 struct buffer buf = alloc_buf_gc(PUSH_BUNDLE_SIZE, &gc);
875 bool multi_push = false;
876 const size_t extra = 84; /* extra space for possible trailing ifconfig and push-continuation */
877 const size_t safe_cap = BCAP(&buf) - extra;
878 bool push_sent = false;
879
880 buf_printf(&buf, "%s", push_reply_cmd);
881
882 /* send options which are common to all clients */
883 if (!send_push_options(c, &buf, &c->options.push_list, safe_cap, &push_sent, &multi_push))
884 {
885 goto fail;
886 }
887
888 /* send client-specific options */
889 if (!send_push_options(c, &buf, per_client_push_list, safe_cap, &push_sent, &multi_push))
890 {
891 goto fail;
892 }
893
894 if (multi_push)
895 {
896 buf_printf(&buf, ",push-continuation 1");
897 }
898
899 if (BLENZ(&buf) >= sizeof(push_reply_cmd))
900 {
901 const bool status = send_control_channel_string(c, BSTR(&buf), D_PUSH);
902 if (!status)
903 {
904 goto fail;
905 }
906 push_sent = true;
907 }
908
909 /* If nothing have been pushed, send an empty push,
910 * as the client is expecting a response
911 */
912 if (!push_sent)
913 {
914 bool status = false;
915
916 buf_reset_len(&buf);
917 buf_printf(&buf, "%s", push_reply_cmd);
919 if (!status)
920 {
921 goto fail;
922 }
923 }
924
925 gc_free(&gc);
926 return true;
927
928fail:
929 gc_free(&gc);
930 return false;
931}
932
933static void
934push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
935 msglvl_t msglevel)
936{
937 if (!string_class(opt, CC_ANY, CC_COMMA))
938 {
939 msg(msglevel, "PUSH OPTION FAILED (illegal comma (',') in string): '%s'", opt);
940 }
941 else
942 {
943 struct push_entry *e;
944 ALLOC_OBJ_CLEAR_GC(e, struct push_entry, gc);
945 e->enable = true;
946 e->option = opt;
947 if (push_list->head)
948 {
950 push_list->tail->next = e;
951 push_list->tail = e;
952 }
953 else
954 {
956 push_list->head = e;
957 push_list->tail = e;
958 }
959 }
960}
961
962void
963push_option(struct options *o, const char *opt, msglvl_t msglevel)
964{
965 push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
966}
967
968void
970{
971 if (o->push_list.head)
972 {
973 const struct push_entry *e = o->push_list.head;
974 push_reset(o);
975 while (e)
976 {
977 push_option_ex(&o->gc, &o->push_list, string_alloc(e->option, &o->gc), true, M_FATAL);
978 e = e->next;
979 }
980 }
981}
982
983void
984push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
985{
986 const char **argv = make_extended_arg_array(p, false, gc);
987 const char *opt = print_argv(argv, gc, 0);
988 push_option(o, opt, msglevel);
989}
990
991static bool
993 msglvl_t msglevel, const char *format, ...)
994{
995 va_list arglist;
996 char tmp[256] = { 0 };
997 int len;
998 va_start(arglist, format);
999 len = vsnprintf(tmp, sizeof(tmp), format, arglist);
1000 va_end(arglist);
1001 if (len < 0 || len >= (int)sizeof(tmp))
1002 {
1003 return false;
1004 }
1005 push_option_ex(gc, push_list, string_alloc(tmp, gc), true, msglevel);
1006 return true;
1007}
1008
1009void
1011{
1012 CLEAR(o->push_list);
1013}
1014
1015void
1016push_remove_option(struct options *o, const char *p)
1017{
1018 msg(D_PUSH_DEBUG, "PUSH_REMOVE searching for: '%s'", p);
1019
1020 /* ifconfig is special, as not part of the push list */
1021 if (streq(p, "ifconfig"))
1022 {
1024 return;
1025 }
1026
1027 /* ifconfig-ipv6 is special, as not part of the push list */
1028 if (streq(p, "ifconfig-ipv6"))
1029 {
1031 return;
1032 }
1033
1034 if (o && o->push_list.head)
1035 {
1036 struct push_entry *e = o->push_list.head;
1037
1038 /* cycle through the push list */
1039 while (e)
1040 {
1041 if (e->enable && strncmp(e->option, p, strlen(p)) == 0)
1042 {
1043 msg(D_PUSH_DEBUG, "PUSH_REMOVE removing: '%s'", e->option);
1044 e->enable = false;
1045 }
1046
1047 e = e->next;
1048 }
1049 }
1050}
1051
1052int
1054{
1055 int ret = PUSH_MSG_ERROR;
1056
1057
1060 {
1061 const char *client_reason = tls_client_reason(c->c2.tls_multi);
1062 send_auth_failed(c, client_reason);
1064 }
1067 {
1068 update_time();
1069 if (c->c2.sent_push_reply_expiry > now)
1070 {
1072 }
1073 else
1074 {
1075 /* per-client push options - peer-id, cipher, ifconfig, ipv6-ifconfig */
1076 struct push_list push_list = { 0 };
1077 struct gc_arena gc = gc_new();
1078
1080 if (send_push_reply(c, &push_list))
1081 {
1082 ret = PUSH_MSG_REQUEST;
1083 c->c2.sent_push_reply_expiry = now + 30;
1084 }
1085 gc_free(&gc);
1086 }
1087 }
1088 else
1089 {
1091 }
1092
1093 return ret;
1094}
1095
1096static void
1097push_update_digest(md_ctx_t *ctx, struct buffer *buf, const struct options *opt)
1098{
1099 char line[OPTION_PARM_SIZE];
1100 while (buf_parse(buf, ',', line, sizeof(line)))
1101 {
1102 /* peer-id and auth-token might change on restart and this should not
1103 * trigger reopening tun
1104 * Also other options that only affect the control channel should
1105 * not trigger a reopen of the tun device
1106 */
1107 if (strprefix(line, "peer-id ")
1108 || strprefix(line, "auth-token ")
1109 || strprefix(line, "auth-token-user")
1110 || strprefix(line, "protocol-flags ")
1111 || strprefix(line, "key-derivation ")
1112 || strprefix(line, "explicit-exit-notify ")
1113 || strprefix(line, "ping ")
1114 || strprefix(line, "ping-restart ")
1115 || strprefix(line, "ping-timer "))
1116 {
1117 continue;
1118 }
1119 /* tun reopen only needed if cipher change can change tun MTU */
1120 if (strprefix(line, "cipher ") && opt->ce.tun_mtu_defined)
1121 {
1122 continue;
1123 }
1124 md_ctx_update(ctx, (const uint8_t *)line, strlen(line) + 1);
1125 }
1126}
1127
1128static int
1129process_incoming_push_reply(struct context *c, uint64_t permission_mask,
1130 uint64_t *option_types_found, struct buffer *buf)
1131{
1132 int ret = PUSH_MSG_ERROR;
1133 const int ch = buf_read_u8(buf);
1134 if (ch == ',')
1135 {
1136 struct buffer buf_orig = (*buf);
1138 {
1140 md_ctx_init(c->c2.pulled_options_state, "SHA256");
1142 }
1143 if (apply_push_options(c, &c->options, buf, permission_mask, option_types_found, c->c2.es,
1144 false))
1145 {
1147 switch (c->options.push_continuation)
1148 {
1149 case 0:
1150 case 1:
1154 c->c2.pulled_options_state = NULL;
1156 ret = PUSH_MSG_REPLY;
1157 break;
1158
1159 case 2:
1161 break;
1162 }
1163 }
1164 else
1165 {
1166 throw_signal_soft(SIGUSR1, "Offending option received from server");
1167 }
1168 }
1169 else if (ch == '\0')
1170 {
1171 ret = PUSH_MSG_REPLY;
1172 }
1173 /* show_settings (&c->options); */
1174 return ret;
1175}
1176
1177int
1179 bool honor_received_options, uint64_t permission_mask,
1180 uint64_t *option_types_found)
1181{
1182 struct buffer buf = *buffer;
1183
1184 if (buf_string_compare_advance(&buf, "PUSH_REQUEST"))
1185 {
1186 c->c2.push_request_received = true;
1188 }
1189 else if (honor_received_options && buf_string_compare_advance(&buf, push_reply_cmd))
1190 {
1191 return process_incoming_push_reply(c, permission_mask, option_types_found, &buf);
1192 }
1193 else if (honor_received_options && buf_string_compare_advance(&buf, push_update_cmd))
1194 {
1195 if (dco_enabled(&c->options))
1196 {
1197 msg(M_WARN, "WARN: PUSH_UPDATE messages cannot currently be processed in client mode while DCO is enabled, ignoring."
1198 " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");
1199 return PUSH_MSG_ERROR;
1200 }
1201 return process_push_update(c, &c->options, permission_mask, option_types_found, &buf, false);
1202 }
1203 else
1204 {
1205 return PUSH_MSG_ERROR;
1206 }
1207}
1208
1209
1210/*
1211 * Remove iroutes from the push_list.
1212 */
1213void
1215{
1216 if (o && o->push_list.head && (o->iroutes || o->iroutes_ipv6))
1217 {
1218 struct gc_arena gc = gc_new();
1219 struct push_entry *e = o->push_list.head;
1220
1221 /* cycle through the push list */
1222 while (e)
1223 {
1224 char *p[MAX_PARMS + 1];
1225
1226 /* parse the push item */
1227 CLEAR(p);
1228 if (e->enable
1229 && parse_line(e->option, p, SIZE(p) - 1, "[PUSH_ROUTE_REMOVE]", 1, D_ROUTE_DEBUG,
1230 &gc))
1231 {
1232 bool enable = true;
1233
1234 /* is the push item a route directive? */
1235 if (p[0] && !strcmp(p[0], "route") && !p[3] && o->iroutes)
1236 {
1237 /* get route parameters */
1238 bool status1, status2;
1239 const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], 0, &status1, NULL);
1240 const in_addr_t netmask = getaddr(
1241 GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255.255", 0, &status2, NULL);
1242
1243 /* did route parameters parse correctly? */
1244 if (status1 && status2)
1245 {
1246 const struct iroute *ir;
1247
1248 /* does route match an iroute? */
1249 for (ir = o->iroutes; ir != NULL; ir = ir->next)
1250 {
1251 if (network == ir->network
1252 && netmask
1253 == netbits_to_netmask(ir->netbits >= 0 ? ir->netbits : 32))
1254 {
1255 enable = false;
1256 break;
1257 }
1258 }
1259 }
1260 }
1261 else if (p[0] && !strcmp(p[0], "route-ipv6") && !p[2] && o->iroutes_ipv6)
1262 {
1263 /* get route parameters */
1264 struct in6_addr network;
1265 unsigned int netbits;
1266
1267 /* parse route-ipv6 arguments */
1268 if (get_ipv6_addr(p[1], &network, &netbits, D_ROUTE_DEBUG))
1269 {
1270 const struct iroute_ipv6 *ir;
1271
1272 /* does this route-ipv6 match an iroute-ipv6? */
1273 for (ir = o->iroutes_ipv6; ir != NULL; ir = ir->next)
1274 {
1275 if (!memcmp(&network, &ir->network, sizeof(network))
1276 && netbits == ir->netbits)
1277 {
1278 enable = false;
1279 break;
1280 }
1281 }
1282 }
1283 }
1284
1285 /* should we copy the push item? */
1286 e->enable = enable;
1287 if (!enable)
1288 {
1289 msg(D_PUSH, "REMOVE PUSH ROUTE: '%s'", e->option);
1290 }
1291 }
1292
1293 e = e->next;
1294 }
1295
1296 gc_free(&gc);
1297 }
1298}
char * parse_acc_parameters(const char *capabilities, const char *delim, int *max_acc_len, bool server, struct gc_arena *gc)
Parses an info message from the server that contains app custom control info information prior to the...
Definition acc.c:286
struct buffer get_list_intersection(struct gc_arena *gc, const char *list1, const char *list2)
Calculates the intersection of two list that are both separated by : Items in the result will have th...
Definition acc.c:350
void notify_client_acc_protocols(struct tls_multi *multi)
Notifies a client via management interface of the negotiated app custom protocols.
Definition acc.c:447
bool buf_string_compare_advance(struct buffer *src, const char *match)
Compare the head of src with match and advance past it if equal.
Definition buffer.c:743
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:231
bool string_class(const char *str, const unsigned int inclusive, const unsigned int exclusive)
Test whether all characters in a string satisfy a character class filter.
Definition buffer.c:1003
char * print_argv(const char **p, struct gc_arena *gc, const unsigned int flags)
Format a NULL-terminated argument vector as a single string.
Definition buffer.c:677
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 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:783
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
bool buf_string_match_head_str(const struct buffer *src, const char *match)
Return true if the head of src matches the string match.
Definition buffer.c:727
#define CC_COMMA
comma
Definition buffer.h:1707
static bool buf_size_valid(const size_t size)
Return true iff size is within the allowed buffer size range.
Definition buffer.h:543
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define CC_ANY
any character
Definition buffer.h:1686
#define streq(x, y)
helper to work around the semantics of the strcmp() return value
Definition buffer.h:1822
static const char * buf_cstr(const struct buffer *buf)
Return the buffer content pointer cast to const char *.
Definition buffer.h:585
static int buf_len(const struct buffer *buf)
Return the length of the buffer content.
Definition buffer.h:462
static bool buf_advance(struct buffer *buf, ssize_t size)
Advance the content start of a buffer, consuming bytes from the front.
Definition buffer.h:1165
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
Definition buffer.h:2132
static int buf_read_u8(struct buffer *buf)
Read and consume a uint8_t from the front of a buffer.
Definition buffer.h:1495
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
static void buf_reset_len(struct buffer *buf)
Reset the length and offset of a buffer to zero.
Definition buffer.h:616
#define BCAP(buf)
Return the number of bytes available for appending to the buffer.
Definition buffer.h:161
#define BLENZ(buf)
Return the length of the buffer content as a size_t.
Definition buffer.h:153
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define CBSTR(buf)
Return the buffer content pointer cast to const char *.
Definition buffer.h:159
static bool strprefix(const char *str, const char *prefix)
Return true iff str starts with prefix.
Definition buffer.h:1814
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
static char * buf_str(struct buffer *buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:572
#define PUSH_BUNDLE_SIZE
Definition common.h:89
Data Channel Cryptography Module.
#define CO_USE_TLS_KEY_MATERIAL_EXPORT
Bit-flag indicating that data channel key derivation is done using TLS keying material export [RFC570...
Definition crypto.h:347
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
Definition crypto.h:363
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
Definition crypto.h:367
#define CO_USE_CC_EXIT_NOTIFY
Bit-flag indicating that explicit exit notifies should be sent via the control channel instead of usi...
Definition crypto.h:359
md_ctx_t * md_ctx_new(void)
void md_ctx_update(md_ctx_t *ctx, const uint8_t *src, size_t src_len)
void md_ctx_cleanup(md_ctx_t *ctx)
void md_ctx_final(md_ctx_t *ctx, uint8_t *dst)
void md_ctx_init(md_ctx_t *ctx, const char *mdname)
Initialises the given message digest context.
void md_ctx_free(md_ctx_t *ctx)
struct md_ctx md_ctx_t
#define D_PUSH
Definition errlevel.h:81
#define M_VERB0
Definition errlevel.h:52
#define D_ROUTE_DEBUG
Definition errlevel.h:130
#define D_PUSH_DEBUG
Definition errlevel.h:146
#define D_STREAM_ERRORS
Definition errlevel.h:62
#define D_PUSH_ERRORS
Definition errlevel.h:66
#define D_TLS_DEBUG
Definition errlevel.h:161
void reschedule_multi_process(struct context *c)
Reschedule tls_multi_process.
Definition forward.c:407
bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
Definition forward.c:414
bool schedule_exit(struct context *c)
Definition forward.c:544
bool send_control_channel_string_dowork(struct tls_session *session, const char *str, msglvl_t msglevel)
Definition forward.c:386
#define TM_INITIAL
As yet un-trusted tls_session \ being negotiated.
Definition ssl_common.h:553
#define KS_PRIMARY
Primary key state index.
Definition ssl_common.h:472
#define TM_ACTIVE
Active tls_session.
Definition ssl_common.h:552
bool do_update(struct context *c, uint64_t option_types_found)
A simplified version of the do_up() function.
Definition init.c:2440
uint64_t pull_permission_mask(const struct context *c)
Definition init.c:2493
bool do_up(struct context *c, bool pulled_options, uint64_t option_types_found)
Definition init.c:2305
static unsigned int min_uint(unsigned int x, unsigned int y)
Definition integer.h:66
static unsigned int max_uint(unsigned int x, unsigned int y)
Definition integer.h:53
static SERVICE_STATUS status
Definition interactive.c:52
static void event_timeout_clear(struct event_timeout *et)
Clears the timeout and reset all values to 0.
Definition interval.h:153
void management_notify_generic(const char *str)
Definition manage.c:3101
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
Definition manage.c:2948
void management_auth_failure(const struct management *man, const char *type, const char *reason)
Definition manage.c:3277
void management_notify_client_cr_response(unsigned mda_key_id, const struct man_def_auth_context *mdac, const struct env_set *es, const char *response)
Definition manage.c:3158
void management_notify(const char *severity, const char *type, const char *text)
Definition manage.c:3095
#define OPENVPN_STATE_AUTH_PENDING
Definition manage.h:473
const char ** make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
Definition misc.c:643
const char * sanitize_control_message(const char *src, struct gc_arena *gc)
Definition misc.c:673
#define CLEAR(x)
Definition basic.h:32
#define SIZE(x)
Definition basic.h:29
#define M_USAGE
Definition error.h:107
#define M_FATAL
Definition error.h:90
#define dmsg(flags,...)
Definition error.h:164
#define msg(flags,...)
Definition error.h:152
unsigned int msglvl_t
Definition error.h:77
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
bool options_postprocess_pull(struct options *o, struct env_set *es)
Definition options.c:3218
int auth_retry_get(void)
Definition options.c:3288
#define MODE_SERVER
Definition options.h:265
#define AR_INTERACT
Definition options.h:960
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:981
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 OPTION_PARM_SIZE
Definition options.h:56
#define AR_NONE
Definition options.h:959
#define AR_NOINTERACT
Definition options.h:961
#define MAX_PARMS
Definition options.h:51
bool apply_push_options(struct context *c, struct options *options, struct buffer *buf, uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es, bool is_update)
#define OPTION_LINE_SIZE
Definition options.h:57
const char * parse_auth_failed_temp(struct options *o, const char *reason)
time_t now
Definition otime.c:33
static void update_time(void)
Definition otime.h:84
int process_incoming_push_request(struct context *c)
Definition push.c:1053
void receive_auth_pending(struct context *c, const struct buffer *buffer)
Parses an AUTH_PENDING message and if in pull mode extends the timeout.
Definition push.c:398
bool send_auth_pending_messages(const struct tls_multi *tls_multi, struct tls_session *session, const char *extra, unsigned int timeout)
Sends the auth pending control messages to a client.
Definition push.c:495
void push_option(struct options *o, const char *opt, msglvl_t msglevel)
Definition push.c:963
void receive_auth_failed(struct context *c, const struct buffer *buffer)
Definition push.c:51
void send_restart(struct context *c, const char *kill_msg)
Definition push.c:555
static bool send_push_options(struct context *c, struct buffer *buf, struct push_list *push_list, size_t safe_cap, bool *push_sent, bool *multi_push)
Definition push.c:808
void server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart, const int adv)
Definition push.c:131
void push_reset(struct options *o)
Definition push.c:1010
void receive_cr_response(struct context *c, const struct buffer *buffer)
Definition push.c:319
void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
Definition push.c:984
void send_auth_failed(struct context *c, const char *client_reason)
Definition push.c:455
void peer_pushed_info(struct context *c, const struct buffer *buffer, const int adv)
This message is called when an INFO or INFO_PRE message is received from a peer.
Definition push.c:275
static void prepare_push_reply(struct context *c, struct gc_arena *gc, struct push_list *push_list)
Prepare push options, based on local options.
Definition push.c:697
void clone_push_list(struct options *o)
Definition push.c:969
void receive_exit_message(struct context *c)
Definition push.c:192
void prepare_auth_token_push_reply(struct tls_multi *tls_multi, struct gc_arena *gc, struct push_list *push_list)
Prepare push option for auth-token.
Definition push.c:667
static void push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable, msglvl_t msglevel)
Definition push.c:934
bool send_push_request(struct context *c)
Definition push.c:632
void push_remove_option(struct options *o, const char *p)
Definition push.c:1016
int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, uint64_t permission_mask, uint64_t *option_types_found)
Definition push.c:1178
void incoming_push_message(struct context *c, const struct buffer *buffer)
Definition push.c:566
static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, msglvl_t msglevel, const char *fmt,...)
Add an option to the given push list by providing a format string.
Definition push.c:992
static int process_incoming_push_reply(struct context *c, uint64_t permission_mask, uint64_t *option_types_found, struct buffer *buf)
Definition push.c:1129
static void push_update_digest(md_ctx_t *ctx, struct buffer *buf, const struct options *opt)
Definition push.c:1097
void remove_iroutes_from_push_route_list(struct options *o)
Definition push.c:1214
static void parse_auth_pending_keywords(const struct buffer *buffer, unsigned int *server_timeout)
Parse the keyword for the AUTH_PENDING request.
Definition push.c:352
bool send_push_reply(struct context *c, struct push_list *per_client_push_list)
Definition push.c:871
static void parse_server_pushed_info_acc(struct context *c, struct buffer *buf)
Definition push.c:227
void send_push_reply_auth_token(struct tls_multi *multi)
Sends a push reply message only containin the auth-token to update the auth-token on the client.
Definition push.c:851
int process_push_update(struct context *c, struct options *o, uint64_t permission_mask, uint64_t *option_types_found, struct buffer *buf, bool msg_sender)
Handles the receiving of a push-update message and applies updates to the specified options.
Definition push_util.c:14
#define PUSH_MSG_REQUEST
Definition push.h:29
#define PUSH_MSG_REQUEST_DEFERRED
Definition push.h:31
#define PUSH_MSG_ERROR
Definition push.h:28
#define PUSH_MSG_REPLY
Definition push.h:30
#define PUSH_MSG_UPDATE
Definition push.h:35
#define push_update_cmd
Definition push.h:38
#define push_reply_cmd
Definition push.h:37
#define PUSH_MSG_AUTH_FAILURE
Definition push.h:32
#define PUSH_MSG_CONTINUATION
Definition push.h:33
#define PUSH_MSG_ALREADY_REPLIED
Definition push.h:34
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, msglvl_t msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
Definition resolve.c:489
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
Definition resolve.c:442
DNS resolution.
#define GETADDR_HOST_ORDER
Definition resolve.h:40
static in_addr_t netbits_to_netmask(const int netbits)
Definition route.h:399
void throw_signal_soft(const int signum, const char *signal_text)
Throw a soft global signal.
Definition sig.c:204
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
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
int openvpn_base64_encode(const void *data, int size, char **str)
Definition base64.c:51
void ssl_purge_auth(const bool auth_user_pass_only)
Definition ssl.c:411
void ssl_put_auth_challenge(const char *cr_str)
Definition ssl.c:436
bool ssl_clean_auth_token(void)
Definition ssl.c:400
Control Channel SSL/Data channel negotiation module.
#define IV_PROTO_AUTH_PENDING_KW
Supports signaling keywords with AUTH_PENDING, e.g.
Definition ssl.h:90
@ CAS_CONNECT_DONE
Definition ssl_common.h:601
@ CAS_FAILED
Option import failed or explicitly denied the client.
Definition ssl_common.h:593
#define UP_TYPE_AUTH
Definition ssl_common.h:41
static const struct key_state * get_primary_key(const struct tls_multi *multi)
gets an item of key_state objects in the order they should be scanned by data channel modules.
Definition ssl_common.h:771
bool tls_peer_supports_ncp(const char *peer_info)
Returns whether the client supports NCP either by announcing IV_NCP>=2 or the IV_CIPHERS list.
Definition ssl_ncp.c:69
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
unsigned int peer_info_extract_uint(const char *peer_info, const char *field)
Extracts the named integer variable and returns its value or 0 if it cannot be extracted.
Definition ssl_util.c:113
SSL utility functions.
static unsigned int extract_iv_proto(const char *peer_info)
Extracts the IV_PROTO variable and returns its value or 0 if it cannot be extracted.
Definition ssl_util.h:77
void verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response)
Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE.
enum tls_auth_status tls_authentication_status(struct tls_multi *multi)
Return current session authentication state of the tls_multi structure This will return TLS_AUTHENTIC...
void verify_crresponse_script(struct tls_multi *multi, const char *cr_response)
Runs the –client-crresponse script if one is defined.
Control Channel Verification Module.
@ TLS_AUTHENTICATION_SUCCEEDED
Definition ssl_verify.h:75
@ TLS_AUTHENTICATION_FAILED
Definition ssl_verify.h:76
static const char * tls_client_reason(const struct tls_multi *multi)
Definition ssl_verify.h:278
Definition argv.h:35
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
bool tun_mtu_defined
Definition options.h:133
int tun_mtu
Definition options.h:129
bool push_request_received
Definition openvpn.h:398
bool push_ifconfig_ipv6_defined
Definition openvpn.h:405
bool push_ifconfig_defined
Definition openvpn.h:399
md_ctx_t * pulled_options_state
Definition openvpn.h:415
bool pulled_options_digest_init_done
Definition openvpn.h:414
struct env_set * es
Definition openvpn.h:394
time_t push_request_timeout
Definition openvpn.h:411
struct event_timeout wait_for_connect
Definition openvpn.h:259
struct event_timeout push_request_interval
Definition openvpn.h:410
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:300
time_t sent_push_reply_expiry
Definition openvpn.h:400
struct in6_addr push_ifconfig_ipv6_remote
Definition openvpn.h:408
int push_ifconfig_ipv6_netbits
Definition openvpn.h:407
struct in6_addr push_ifconfig_ipv6_local
Definition openvpn.h:406
in_addr_t push_ifconfig_local_alias
Definition openvpn.h:403
in_addr_t push_ifconfig_remote_netmask
Definition openvpn.h:402
struct sha256_digest pulled_options_digest
Definition openvpn.h:416
in_addr_t push_ifconfig_local
Definition openvpn.h:401
Contains all state information for one tunnel.
Definition openvpn.h:445
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:474
struct context_2 c2
Level 2 context.
Definition openvpn.h:490
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:446
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
struct iroute_ipv6 * next
Definition route.h:271
unsigned int netbits
Definition route.h:270
struct in6_addr network
Definition route.h:269
in_addr_t network
Definition route.h:262
int netbits
Definition route.h:263
struct iroute * next
Definition route.h:264
Security parameter state of one TLS and data channel key session.
Definition ssl_common.h:208
time_t established
Definition ssl_common.h:228
unsigned int mda_key_id
Definition ssl_common.h:263
time_t initial
Definition ssl_common.h:227
time_t peer_last_packet
Definition ssl_common.h:231
time_t auth_deferred_expire
Definition ssl_common.h:260
unsigned int imported_protocol_flags
Definition options.h:735
uint64_t push_option_types_found
Definition options.h:559
bool push_ifconfig_ipv6_blocked
Definition options.h:526
int handshake_window
Definition options.h:651
const char * ifconfig_local
Definition options.h:327
struct connection_entry ce
Definition options.h:294
struct iroute_ipv6 * iroutes_ipv6
Definition options.h:513
struct push_list push_list
Definition options.h:487
int push_continuation
Definition options.h:558
const char * ciphername
Definition options.h:573
int mode
Definition options.h:266
bool pull
Definition options.h:557
struct gc_arena gc
Definition options.h:258
struct iroute * iroutes
Definition options.h:512
int renegotiate_seconds
Definition options.h:643
bool no_advance
Definition options.h:299
uint64_t push_update_options_found
Definition options.h:560
bool push_ifconfig_ipv4_blocked
Definition options.h:521
Definition pushlist.h:29
struct push_entry * next
Definition pushlist.h:30
bool enable
Definition pushlist.h:31
const char * option
Definition pushlist.h:32
struct push_entry * head
Definition pushlist.h:37
struct push_entry * tail
Definition pushlist.h:38
uint8_t digest[SHA256_DIGEST_LENGTH]
Definition crypto.h:127
const char * signal_text
Definition sig.h:44
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:619
char * peer_info
A multi-line string of general-purpose info received from peer over control channel.
Definition ssl_common.h:680
char * locked_username
The locked username is the username we assume the client is using.
Definition ssl_common.h:657
enum multi_status multi_state
Definition ssl_common.h:640
int acc_max_message_length
the maximum length of an ACC control channel message
Definition ssl_common.h:741
struct tls_options opt
Definition ssl_common.h:624
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
Definition ssl_common.h:721
char * auth_token
If server sends a generated auth-token, this is the token to use for future user/pass authentications...
Definition ssl_common.h:686
bool use_peer_id
Definition ssl_common.h:709
bool use_asymmetric_peer_id
Definition ssl_common.h:710
char * acc_negotiated_protocols
the protocols that are negotiated with the peer.
Definition ssl_common.h:738
uint32_t rx_peer_id
Definition ssl_common.h:707
interval_t renegotiate_seconds
Definition ssl_common.h:354
const char * acc_protocols
The app custom control protocols we should announce as supported.
Definition ssl_common.h:462
int handshake_window
Definition ssl_common.h:342
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:497
#define SIGTERM
Definition syshead.h:59
#define SIGUSR1
Definition syshead.h:57
uint32_t in_addr_t
Definition syshead.h:52
__attribute__((unused))
Definition test.c:42
static int cleanup(void **state)
struct gc_arena gc
Definition test_ssl.c:138