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
392void
393receive_auth_pending(struct context *c, const struct buffer *buffer)
394{
395 if (!c->options.pull)
396 {
397 return;
398 }
399
400 /* Cap the increase at the maximum time we are willing stay in the
401 * pending authentication state */
402 unsigned int max_timeout =
404
405 /* try to parse parameter keywords, default to hand-winow timeout if the
406 * server does not supply a timeout */
407 unsigned int server_timeout = c->options.handshake_window;
408 parse_auth_pending_keywords(buffer, &server_timeout);
409
410 msg(D_PUSH,
411 "AUTH_PENDING received, extending handshake timeout from %ds "
412 "to %us",
413 c->options.handshake_window, min_uint(max_timeout, server_timeout));
414
415 const struct key_state *ks = get_primary_key(c->c2.tls_multi);
416 c->c2.push_request_timeout = ks->established + min_uint(max_timeout, server_timeout);
417}
418
433static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
434 msglvl_t msglevel, const char *fmt, ...)
435#ifdef __GNUC__
436#if __USE_MINGW_ANSI_STDIO
437 __attribute__((format(gnu_printf, 4, 5)))
438#else
439 __attribute__((format(__printf__, 4, 5)))
440#endif
441#endif
442 ;
443
444/*
445 * Send auth failed message from server to client.
446 *
447 * Does nothing if an exit is already scheduled
448 */
449void
450send_auth_failed(struct context *c, const char *client_reason)
451{
452 if (!schedule_exit(c))
453 {
454 msg(D_TLS_DEBUG, "exit already scheduled for context");
455 return;
456 }
457
458 struct gc_arena gc = gc_new();
459 static const char auth_failed[] = "AUTH_FAILED";
460 size_t len;
461
462 len = (client_reason ? strlen(client_reason) + 1 : 0) + sizeof(auth_failed);
463 if (len > PUSH_BUNDLE_SIZE)
464 {
465 len = PUSH_BUNDLE_SIZE;
466 }
467
468 {
469 struct buffer buf = alloc_buf_gc(len, &gc);
470 buf_printf(&buf, auth_failed);
471 if (client_reason)
472 {
473 buf_printf(&buf, ",%s", client_reason);
474 }
475
476 /* We kill the whole session, send the AUTH_FAILED to any TLS session
477 * that might be active */
479 D_PUSH);
481 D_PUSH);
482
484 }
485
486 gc_free(&gc);
487}
488
489bool
491 const char *extra, unsigned int timeout)
492{
493 struct key_state *ks = &session->key[KS_PRIMARY];
494
495 static const char info_pre[] = "INFO_PRE,";
496
497 const char *const peer_info = tls_multi->peer_info;
498 unsigned int proto = extract_iv_proto(peer_info);
499
500 /* Calculate the maximum timeout and subtract the time we already waited */
501 unsigned int max_timeout =
503 time_t time_elapsed = now - ks->initial;
504 if (time_elapsed < 0 || time_elapsed >= (time_t)max_timeout)
505 {
506 return false;
507 }
508 max_timeout -= (unsigned int)time_elapsed;
509 timeout = min_uint(max_timeout, timeout);
510
511 struct gc_arena gc = gc_new();
512 if ((proto & IV_PROTO_AUTH_PENDING_KW) == 0)
513 {
515 }
516 else
517 {
518 static const char auth_pre[] = "AUTH_PENDING,timeout ";
519 /* Assume a worst case of 8 byte uint64 in decimal which */
520 /* needs 20 bytes */
521 size_t len = 20 + 1 + sizeof(auth_pre);
522 struct buffer buf = alloc_buf_gc(len, &gc);
523 buf_printf(&buf, auth_pre);
524 buf_printf(&buf, "%u", timeout);
526 }
527
528 size_t len = strlen(extra) + 1 + sizeof(info_pre);
529 if (len > PUSH_BUNDLE_SIZE)
530 {
531 gc_free(&gc);
532 return false;
533 }
534
535 struct buffer buf = alloc_buf_gc(len, &gc);
536 buf_printf(&buf, info_pre);
537 buf_printf(&buf, "%s", extra);
539
540 ks->auth_deferred_expire = now + timeout;
541
542 gc_free(&gc);
543 return true;
544}
545
546/*
547 * Send restart message from server to client.
548 */
549void
550send_restart(struct context *c, const char *kill_msg)
551{
552 schedule_exit(c);
553 send_control_channel_string(c, kill_msg ? kill_msg : "RESTART", D_PUSH);
554}
555
556/*
557 * Push/Pull
558 */
559
560void
562{
563 struct gc_arena gc = gc_new();
564 uint64_t option_types_found = 0;
565
566 msg(D_PUSH, "PUSH: Received control message: '%s'",
568
570 &option_types_found);
571
572 if (status == PUSH_MSG_ERROR)
573 {
574 msg(D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s",
576 }
579 {
580 c->options.push_option_types_found |= option_types_found;
581
582 /* delay bringing tun/tap up until --push parms received from remote */
584 {
586 {
587 goto error;
588 }
589 if (status == PUSH_MSG_REPLY)
590 {
591 if (!do_up(c, true, c->options.push_option_types_found))
592 {
593 msg(D_PUSH_ERRORS, "Failed to open tun/tap interface");
594 goto error;
595 }
596 }
597 else
598 {
599 /* Clear push_update_options_found for next PUSH_UPDATE sequence */
601
602 /* Use accumulated option_types_found for the entire PUSH_UPDATE sequence */
604 {
605 msg(M_WARN, "No updatable options found in incoming PUSH_UPDATE message");
606 }
608 {
609 msg(D_PUSH_ERRORS, "Failed to update options");
610 goto error;
611 }
612 }
613 }
616 }
617
618 goto cleanup;
619
620error:
621 register_signal(c->sig, SIGUSR1, "process-push-msg-failed");
622cleanup:
623 gc_free(&gc);
624}
625
626bool
628{
629 const struct key_state *ks = get_primary_key(c->c2.tls_multi);
630
631 /* We timeout here under two conditions:
632 * a) we reached the hard limit of push_request_timeout
633 * b) we have not seen anything from the server in hand_window time
634 *
635 * for non auth-pending scenario, push_request_timeout is the same as
636 * hand_window timeout. For b) every PUSH_REQUEST is a acknowledged by
637 * the server by a P_ACK_V1 packet that reset the keepalive timer
638 */
639
642 {
643 return send_control_channel_string(c, "PUSH_REQUEST", D_PUSH);
644 }
645 else
646 {
647 msg(D_STREAM_ERRORS, "No reply from server to push requests in %ds",
648 (int)(now - ks->established));
649 /* SOFT-SIGUSR1 -- server-pushed connection reset */
650 register_signal(c->sig, SIGUSR1, "no-push-reply");
651 return false;
652 }
653}
654
661void
663 struct push_list *push_list)
664{
665 /*
666 * If server uses --auth-gen-token and we have an auth token
667 * to send to the client
668 */
670 {
672
673 char *base64user = NULL;
675 (int)strlen(tls_multi->locked_username), &base64user);
676 if (ret < USER_PASS_LEN && ret > 0)
677 {
678 push_option_fmt(gc, push_list, M_USAGE, "auth-token-user %s", base64user);
679 }
680 free(base64user);
681 }
682}
683
691static void
693{
694 struct tls_multi *tls_multi = c->c2.tls_multi;
695 struct options *o = &c->options;
696
697 /* ipv6 */
699 {
700 push_option_fmt(gc, push_list, M_USAGE, "ifconfig-ipv6 %s/%d %s",
704 }
705
706 /* ipv4 */
709 {
712 {
714 }
715 push_option_fmt(gc, push_list, M_USAGE, "ifconfig %s %s",
718 }
719
721 {
723 }
724 /*
725 * If server uses --auth-gen-token and we have an auth token
726 * to send to the client
727 */
729
730 /*
731 * Push the selected cipher, at this point the cipher has been
732 * already negotiated and been fixed.
733 *
734 * We avoid pushing the cipher to clients not supporting NCP
735 * to avoid error messages in their logs
736 */
738 {
739 push_option_fmt(gc, push_list, M_USAGE, "cipher %s", o->ciphername);
740 }
741
742 struct buffer proto_flags = alloc_buf_gc(128, gc);
743
745 {
746 buf_printf(&proto_flags, " cc-exit");
747
748 /* if the cc exit flag is supported, pushing tls-ekm via protocol-flags
749 * is also supported */
751 {
752 buf_printf(&proto_flags, " tls-ekm");
753 }
754 }
756 {
757 push_option_fmt(gc, push_list, M_USAGE, "key-derivation tls-ekm");
758 }
759
761 {
762 buf_printf(&proto_flags, " dyn-tls-crypt");
763 }
764
766 {
767 buf_printf(&proto_flags, " aead-epoch");
768 }
769
770 if (buf_len(&proto_flags) > 0)
771 {
772 push_option_fmt(gc, push_list, M_USAGE, "protocol-flags%s", buf_str(&proto_flags));
773 }
774
775 /* Push our mtu to the peer if it supports pushable MTUs */
776 int client_max_mtu = peer_info_extract_uint(tls_multi->peer_info, "IV_MTU=");
777
778 if (client_max_mtu != 0)
779 {
780 push_option_fmt(gc, push_list, M_USAGE, "tun-mtu %d", o->ce.tun_mtu);
781 if (client_max_mtu < o->ce.tun_mtu)
782 {
783 msg(M_WARN,
784 "Warning: reported maximum MTU from client (%d) is lower "
785 "than MTU used on the server (%d). Add tun-mtu-max %d "
786 "to client configuration.",
787 client_max_mtu, o->ce.tun_mtu, o->ce.tun_mtu);
788 }
789 }
790
792 {
793 push_option_fmt(gc, push_list, M_USAGE, "custom-control %d A:6 %s",
795 }
796}
797
798static bool
799send_push_options(struct context *c, struct buffer *buf, struct push_list *push_list, int safe_cap,
800 bool *push_sent, bool *multi_push)
801{
802 struct push_entry *e = push_list->head;
803
804 while (e)
805 {
806 if (e->enable)
807 {
808 const size_t l = strlen(e->option);
809 if (!buf_size_valid(l))
810 {
811 msg(M_WARN, "--push option is too long");
812 return false;
813 }
814 if (BLEN(buf) + (int)l >= safe_cap)
815 {
816 buf_printf(buf, ",push-continuation 2");
817 {
818 const bool status = send_control_channel_string(c, BSTR(buf), D_PUSH);
819 if (!status)
820 {
821 return false;
822 }
823 *push_sent = true;
824 *multi_push = true;
825 buf_reset_len(buf);
826 buf_printf(buf, "%s", push_reply_cmd);
827 }
828 }
829 if (BLEN(buf) + (int)l >= safe_cap)
830 {
831 msg(M_WARN, "--push option is too long");
832 return false;
833 }
834 buf_printf(buf, ",%s", e->option);
835 }
836 e = e->next;
837 }
838 return true;
839}
840
841void
843{
844 struct gc_arena gc = gc_new();
845 struct push_list push_list = { 0 };
846 struct tls_session *session = &multi->session[TM_ACTIVE];
847
849
850 /* prepare auth token should always add the auth-token option */
851 struct push_entry *e = push_list.head;
852 ASSERT(e && e->enable);
853
854 /* Construct a mimimal control channel push reply message */
855 struct buffer buf = alloc_buf_gc(PUSH_BUNDLE_SIZE, &gc);
856 buf_printf(&buf, "%s,%s", push_reply_cmd, e->option);
858 gc_free(&gc);
859}
860
861bool
862send_push_reply(struct context *c, struct push_list *per_client_push_list)
863{
864 struct gc_arena gc = gc_new();
865 struct buffer buf = alloc_buf_gc(PUSH_BUNDLE_SIZE, &gc);
866 bool multi_push = false;
867 const int extra = 84; /* extra space for possible trailing ifconfig and push-continuation */
868 const int safe_cap = BCAP(&buf) - extra;
869 bool push_sent = false;
870
871 buf_printf(&buf, "%s", push_reply_cmd);
872
873 /* send options which are common to all clients */
874 if (!send_push_options(c, &buf, &c->options.push_list, safe_cap, &push_sent, &multi_push))
875 {
876 goto fail;
877 }
878
879 /* send client-specific options */
880 if (!send_push_options(c, &buf, per_client_push_list, safe_cap, &push_sent, &multi_push))
881 {
882 goto fail;
883 }
884
885 if (multi_push)
886 {
887 buf_printf(&buf, ",push-continuation 1");
888 }
889
890 if (BLENZ(&buf) >= sizeof(push_reply_cmd))
891 {
892 const bool status = send_control_channel_string(c, BSTR(&buf), D_PUSH);
893 if (!status)
894 {
895 goto fail;
896 }
897 push_sent = true;
898 }
899
900 /* If nothing have been pushed, send an empty push,
901 * as the client is expecting a response
902 */
903 if (!push_sent)
904 {
905 bool status = false;
906
907 buf_reset_len(&buf);
908 buf_printf(&buf, "%s", push_reply_cmd);
910 if (!status)
911 {
912 goto fail;
913 }
914 }
915
916 gc_free(&gc);
917 return true;
918
919fail:
920 gc_free(&gc);
921 return false;
922}
923
924static void
925push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
926 msglvl_t msglevel)
927{
928 if (!string_class(opt, CC_ANY, CC_COMMA))
929 {
930 msg(msglevel, "PUSH OPTION FAILED (illegal comma (',') in string): '%s'", opt);
931 }
932 else
933 {
934 struct push_entry *e;
935 ALLOC_OBJ_CLEAR_GC(e, struct push_entry, gc);
936 e->enable = true;
937 e->option = opt;
938 if (push_list->head)
939 {
941 push_list->tail->next = e;
942 push_list->tail = e;
943 }
944 else
945 {
947 push_list->head = e;
948 push_list->tail = e;
949 }
950 }
951}
952
953void
954push_option(struct options *o, const char *opt, msglvl_t msglevel)
955{
956 push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
957}
958
959void
961{
962 if (o->push_list.head)
963 {
964 const struct push_entry *e = o->push_list.head;
965 push_reset(o);
966 while (e)
967 {
968 push_option_ex(&o->gc, &o->push_list, string_alloc(e->option, &o->gc), true, M_FATAL);
969 e = e->next;
970 }
971 }
972}
973
974void
975push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
976{
977 const char **argv = make_extended_arg_array(p, false, gc);
978 const char *opt = print_argv(argv, gc, 0);
979 push_option(o, opt, msglevel);
980}
981
982static bool
984 msglvl_t msglevel, const char *format, ...)
985{
986 va_list arglist;
987 char tmp[256] = { 0 };
988 int len;
989 va_start(arglist, format);
990 len = vsnprintf(tmp, sizeof(tmp), format, arglist);
991 va_end(arglist);
992 if (len < 0 || len >= (int)sizeof(tmp))
993 {
994 return false;
995 }
996 push_option_ex(gc, push_list, string_alloc(tmp, gc), true, msglevel);
997 return true;
998}
999
1000void
1002{
1003 CLEAR(o->push_list);
1004}
1005
1006void
1007push_remove_option(struct options *o, const char *p)
1008{
1009 msg(D_PUSH_DEBUG, "PUSH_REMOVE searching for: '%s'", p);
1010
1011 /* ifconfig is special, as not part of the push list */
1012 if (streq(p, "ifconfig"))
1013 {
1015 return;
1016 }
1017
1018 /* ifconfig-ipv6 is special, as not part of the push list */
1019 if (streq(p, "ifconfig-ipv6"))
1020 {
1022 return;
1023 }
1024
1025 if (o && o->push_list.head)
1026 {
1027 struct push_entry *e = o->push_list.head;
1028
1029 /* cycle through the push list */
1030 while (e)
1031 {
1032 if (e->enable && strncmp(e->option, p, strlen(p)) == 0)
1033 {
1034 msg(D_PUSH_DEBUG, "PUSH_REMOVE removing: '%s'", e->option);
1035 e->enable = false;
1036 }
1037
1038 e = e->next;
1039 }
1040 }
1041}
1042
1043int
1045{
1046 int ret = PUSH_MSG_ERROR;
1047
1048
1051 {
1052 const char *client_reason = tls_client_reason(c->c2.tls_multi);
1053 send_auth_failed(c, client_reason);
1055 }
1058 {
1059 update_time();
1060 if (c->c2.sent_push_reply_expiry > now)
1061 {
1063 }
1064 else
1065 {
1066 /* per-client push options - peer-id, cipher, ifconfig, ipv6-ifconfig */
1067 struct push_list push_list = { 0 };
1068 struct gc_arena gc = gc_new();
1069
1071 if (send_push_reply(c, &push_list))
1072 {
1073 ret = PUSH_MSG_REQUEST;
1074 c->c2.sent_push_reply_expiry = now + 30;
1075 }
1076 gc_free(&gc);
1077 }
1078 }
1079 else
1080 {
1082 }
1083
1084 return ret;
1085}
1086
1087static void
1088push_update_digest(md_ctx_t *ctx, struct buffer *buf, const struct options *opt)
1089{
1090 char line[OPTION_PARM_SIZE];
1091 while (buf_parse(buf, ',', line, sizeof(line)))
1092 {
1093 /* peer-id and auth-token might change on restart and this should not
1094 * trigger reopening tun
1095 * Also other options that only affect the control channel should
1096 * not trigger a reopen of the tun device
1097 */
1098 if (strprefix(line, "peer-id ")
1099 || strprefix(line, "auth-token ")
1100 || strprefix(line, "auth-token-user")
1101 || strprefix(line, "protocol-flags ")
1102 || strprefix(line, "key-derivation ")
1103 || strprefix(line, "explicit-exit-notify ")
1104 || strprefix(line, "ping ")
1105 || strprefix(line, "ping-restart ")
1106 || strprefix(line, "ping-timer "))
1107 {
1108 continue;
1109 }
1110 /* tun reopen only needed if cipher change can change tun MTU */
1111 if (strprefix(line, "cipher ") && opt->ce.tun_mtu_defined)
1112 {
1113 continue;
1114 }
1115 md_ctx_update(ctx, (const uint8_t *)line, strlen(line) + 1);
1116 }
1117}
1118
1119static int
1120process_incoming_push_reply(struct context *c, uint64_t permission_mask,
1121 uint64_t *option_types_found, struct buffer *buf)
1122{
1123 int ret = PUSH_MSG_ERROR;
1124 const int ch = buf_read_u8(buf);
1125 if (ch == ',')
1126 {
1127 struct buffer buf_orig = (*buf);
1129 {
1131 md_ctx_init(c->c2.pulled_options_state, "SHA256");
1133 }
1134 if (apply_push_options(c, &c->options, buf, permission_mask, option_types_found, c->c2.es,
1135 false))
1136 {
1138 switch (c->options.push_continuation)
1139 {
1140 case 0:
1141 case 1:
1145 c->c2.pulled_options_state = NULL;
1147 ret = PUSH_MSG_REPLY;
1148 break;
1149
1150 case 2:
1152 break;
1153 }
1154 }
1155 else
1156 {
1157 throw_signal_soft(SIGUSR1, "Offending option received from server");
1158 }
1159 }
1160 else if (ch == '\0')
1161 {
1162 ret = PUSH_MSG_REPLY;
1163 }
1164 /* show_settings (&c->options); */
1165 return ret;
1166}
1167
1168int
1170 bool honor_received_options, uint64_t permission_mask,
1171 uint64_t *option_types_found)
1172{
1173 struct buffer buf = *buffer;
1174
1175 if (buf_string_compare_advance(&buf, "PUSH_REQUEST"))
1176 {
1177 c->c2.push_request_received = true;
1179 }
1180 else if (honor_received_options && buf_string_compare_advance(&buf, push_reply_cmd))
1181 {
1182 return process_incoming_push_reply(c, permission_mask, option_types_found, &buf);
1183 }
1184 else if (honor_received_options && buf_string_compare_advance(&buf, push_update_cmd))
1185 {
1186 if (dco_enabled(&c->options))
1187 {
1188 msg(M_WARN, "WARN: PUSH_UPDATE messages cannot currently be processed in client mode while DCO is enabled, ignoring."
1189 " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");
1190 return PUSH_MSG_ERROR;
1191 }
1192 return process_push_update(c, &c->options, permission_mask, option_types_found, &buf, false);
1193 }
1194 else
1195 {
1196 return PUSH_MSG_ERROR;
1197 }
1198}
1199
1200
1201/*
1202 * Remove iroutes from the push_list.
1203 */
1204void
1206{
1207 if (o && o->push_list.head && (o->iroutes || o->iroutes_ipv6))
1208 {
1209 struct gc_arena gc = gc_new();
1210 struct push_entry *e = o->push_list.head;
1211
1212 /* cycle through the push list */
1213 while (e)
1214 {
1215 char *p[MAX_PARMS + 1];
1216
1217 /* parse the push item */
1218 CLEAR(p);
1219 if (e->enable
1220 && parse_line(e->option, p, SIZE(p) - 1, "[PUSH_ROUTE_REMOVE]", 1, D_ROUTE_DEBUG,
1221 &gc))
1222 {
1223 bool enable = true;
1224
1225 /* is the push item a route directive? */
1226 if (p[0] && !strcmp(p[0], "route") && !p[3] && o->iroutes)
1227 {
1228 /* get route parameters */
1229 bool status1, status2;
1230 const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], 0, &status1, NULL);
1231 const in_addr_t netmask = getaddr(
1232 GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255.255", 0, &status2, NULL);
1233
1234 /* did route parameters parse correctly? */
1235 if (status1 && status2)
1236 {
1237 const struct iroute *ir;
1238
1239 /* does route match an iroute? */
1240 for (ir = o->iroutes; ir != NULL; ir = ir->next)
1241 {
1242 if (network == ir->network
1243 && netmask
1244 == netbits_to_netmask(ir->netbits >= 0 ? ir->netbits : 32))
1245 {
1246 enable = false;
1247 break;
1248 }
1249 }
1250 }
1251 }
1252 else if (p[0] && !strcmp(p[0], "route-ipv6") && !p[2] && o->iroutes_ipv6)
1253 {
1254 /* get route parameters */
1255 struct in6_addr network;
1256 unsigned int netbits;
1257
1258 /* parse route-ipv6 arguments */
1259 if (get_ipv6_addr(p[1], &network, &netbits, D_ROUTE_DEBUG))
1260 {
1261 const struct iroute_ipv6 *ir;
1262
1263 /* does this route-ipv6 match an iroute-ipv6? */
1264 for (ir = o->iroutes_ipv6; ir != NULL; ir = ir->next)
1265 {
1266 if (!memcmp(&network, &ir->network, sizeof(network))
1267 && netbits == ir->netbits)
1268 {
1269 enable = false;
1270 break;
1271 }
1272 }
1273 }
1274 }
1275
1276 /* should we copy the push item? */
1277 e->enable = enable;
1278 if (!enable)
1279 {
1280 msg(D_PUSH, "REMOVE PUSH ROUTE: '%s'", e->option);
1281 }
1282 }
1283
1284 e = e->next;
1285 }
1286
1287 gc_free(&gc);
1288 }
1289}
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:287
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:351
void notify_client_acc_protocols(struct tls_multi *multi)
Notifies a client via management interface of the negotiated app custom protocols.
Definition acc.c:436
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:721
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:226
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:968
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:660
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:757
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:601
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:710
#define CC_COMMA
comma
Definition buffer.h:1698
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:1677
#define streq(x, y)
helper to work around the semantics of the strcmp() return value
Definition buffer.h:1813
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:2123
static int buf_read_u8(struct buffer *buf)
Read and consume a uint8_t from the front of a buffer.
Definition buffer.h:1490
#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:1965
#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:1805
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1949
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:359
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
Definition crypto.h:375
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
Definition crypto.h:379
#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:371
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:82
#define M_VERB0
Definition errlevel.h:52
#define D_ROUTE_DEBUG
Definition errlevel.h:132
#define D_PUSH_DEBUG
Definition errlevel.h:149
#define D_STREAM_ERRORS
Definition errlevel.h:62
#define D_PUSH_ERRORS
Definition errlevel.h:66
#define D_TLS_DEBUG
Definition errlevel.h:164
void reschedule_multi_process(struct context *c)
Reschedule tls_multi_process.
Definition forward.c:402
bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
Definition forward.c:409
bool schedule_exit(struct context *c)
Definition forward.c:539
bool send_control_channel_string_dowork(struct tls_session *session, const char *str, msglvl_t msglevel)
Definition forward.c:381
#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:2472
uint64_t pull_permission_mask(const struct context *c)
Definition init.c:2525
bool do_up(struct context *c, bool pulled_options, uint64_t option_types_found)
Definition init.c:2337
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:3094
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:2941
void management_auth_failure(const struct management *man, const char *type, const char *reason)
Definition manage.c:3274
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:3151
void management_notify(const char *severity, const char *type, const char *text)
Definition manage.c:3088
#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:638
const char * sanitize_control_message(const char *src, struct gc_arena *gc)
Definition misc.c:668
#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:3318
int auth_retry_get(void)
Definition options.c:3388
#define MODE_SERVER
Definition options.h:265
#define AR_INTERACT
Definition options.h:966
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:987
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:965
#define AR_NOINTERACT
Definition options.h:967
#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:1044
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:393
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:490
void push_option(struct options *o, const char *opt, msglvl_t msglevel)
Definition push.c:954
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:550
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:1001
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:975
void send_auth_failed(struct context *c, const char *client_reason)
Definition push.c:450
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:692
void clone_push_list(struct options *o)
Definition push.c:960
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:662
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:925
bool send_push_request(struct context *c)
Definition push.c:627
void push_remove_option(struct options *o, const char *p)
Definition push.c:1007
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:1169
void incoming_push_message(struct context *c, const struct buffer *buffer)
Definition push.c:561
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:983
static int process_incoming_push_reply(struct context *c, uint64_t permission_mask, uint64_t *option_types_found, struct buffer *buf)
Definition push.c:1120
static void push_update_digest(md_ctx_t *ctx, struct buffer *buf, const struct options *opt)
Definition push.c:1088
static bool send_push_options(struct context *c, struct buffer *buf, struct push_list *push_list, int safe_cap, bool *push_sent, bool *multi_push)
Definition push.c:799
void remove_iroutes_from_push_route_list(struct options *o)
Definition push.c:1205
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:862
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:842
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:401
void ssl_put_auth_challenge(const char *cr_str)
Definition ssl.c:426
bool ssl_clean_auth_token(void)
Definition ssl.c:390
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:109
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:424
bool push_ifconfig_ipv6_defined
Definition openvpn.h:431
bool push_ifconfig_defined
Definition openvpn.h:425
md_ctx_t * pulled_options_state
Definition openvpn.h:441
bool pulled_options_digest_init_done
Definition openvpn.h:440
struct env_set * es
Definition openvpn.h:420
time_t push_request_timeout
Definition openvpn.h:437
struct event_timeout wait_for_connect
Definition openvpn.h:283
struct event_timeout push_request_interval
Definition openvpn.h:436
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:324
time_t sent_push_reply_expiry
Definition openvpn.h:426
struct in6_addr push_ifconfig_ipv6_remote
Definition openvpn.h:434
int push_ifconfig_ipv6_netbits
Definition openvpn.h:433
struct in6_addr push_ifconfig_ipv6_local
Definition openvpn.h:432
in_addr_t push_ifconfig_local_alias
Definition openvpn.h:429
in_addr_t push_ifconfig_remote_netmask
Definition openvpn.h:428
struct sha256_digest pulled_options_digest
Definition openvpn.h:442
in_addr_t push_ifconfig_local
Definition openvpn.h:427
Contains all state information for one tunnel.
Definition openvpn.h:471
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:500
struct context_2 c2
Level 2 context.
Definition openvpn.h:516
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:472
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:739
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:655
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:576
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:647
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:134
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