OpenVPN
ssl_verify.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 * Copyright (C) 2010-2026 Sentyron B.V. <openvpn@sentyron.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, see <https://www.gnu.org/licenses/>.
22 */
23
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include "syshead.h"
34#include <string.h>
35
36#include "base64.h"
37#include "manage.h"
38#include "otime.h"
39#include "run_command.h"
40#include "ssl_verify.h"
41#include "ssl_verify_backend.h"
42
43#ifdef ENABLE_CRYPTO_OPENSSL
44#include "ssl_verify_openssl.h"
45#endif
46#include "auth_token.h"
47#include "push.h"
48#include "ssl_util.h"
49
50static void
52{
53 string_mod(str, CC_PRINT, CC_CRLF, '_');
54}
55
56/*
57 * Export the untrusted IP address and port to the environment
58 */
59static void
61{
62 setenv_link_socket_actual(session->opt->es, "untrusted", &session->untrusted_addr, SA_IP_PORT);
63}
64
65/*
66 * Remove authenticated state from all sessions in the given tunnel
67 */
68static void
70{
71 if (multi)
72 {
73 wipe_auth_token(multi);
74 for (int i = 0; i < TM_SIZE; ++i)
75 {
76 for (int j = 0; j < KS_SIZE; ++j)
77 {
79 }
80 }
81 }
82}
83
84void
85set_common_name(struct tls_session *session, const char *common_name)
86{
87 if (session->common_name)
88 {
89 free(session->common_name);
90 session->common_name = NULL;
91 }
92 if (common_name)
93 {
94 /* FIXME: Last alloc will never be freed */
95 session->common_name = string_alloc(common_name, NULL);
96 }
97 /* update common name in env */
98 setenv_str(session->opt->es, "common_name", common_name);
99}
100
101/*
102 * Retrieve the common name for the given tunnel's active session. If the
103 * common name is NULL or empty, return NULL if null is true, or "UNDEF" if
104 * null is false.
105 */
106const char *
107tls_common_name(const struct tls_multi *multi, const bool null)
108{
109 const char *ret = NULL;
110 if (multi)
111 {
112 ret = multi->session[TM_ACTIVE].common_name;
113 }
114 if (ret && strlen(ret))
115 {
116 return ret;
117 }
118 else if (null)
119 {
120 return NULL;
121 }
122 else
123 {
124 return "UNDEF";
125 }
126}
127
128/*
129 * Lock the common name for the given tunnel.
130 */
131void
133{
134 const char *cn = multi->session[TM_ACTIVE].common_name;
135 if (cn && !multi->locked_cn)
136 {
137 multi->locked_cn = string_alloc(cn, NULL);
138 }
139}
140
141/*
142 * Lock the username for the given tunnel
143 */
144static bool
145tls_lock_username(struct tls_multi *multi, const char *username)
146{
147 if (multi->locked_username)
148 {
149 /* If the username has been overridden, we accept both the original
150 * username and the changed username */
151 if (strcmp(username, multi->locked_username) != 0
152 && (!multi->locked_original_username
153 || strcmp(username, multi->locked_original_username) != 0))
154 {
156 "TLS Auth Error: username attempted to change from '%s' to '%s' -- tunnel disabled",
157 multi->locked_username, username);
158
159 /* disable the tunnel */
160 tls_deauthenticate(multi);
161 return false;
162 }
163 }
164 else
165 {
166 multi->locked_username = string_alloc(username, NULL);
167 }
168 return true;
169}
170
171const char *
172tls_username(const struct tls_multi *multi, const bool null)
173{
174 const char *ret = NULL;
175 if (multi)
176 {
177 ret = multi->locked_username;
178 }
179 if (ret && strlen(ret))
180 {
181 return ret;
182 }
183 else if (null)
184 {
185 return NULL;
186 }
187 else
188 {
189 return "UNDEF";
190 }
191}
192
193void
194cert_hash_remember(struct tls_session *session, const int error_depth,
195 const struct buffer *cert_hash)
196{
197 if (error_depth >= 0 && error_depth < MAX_CERT_DEPTH)
198 {
199 if (!session->cert_hash_set)
200 {
201 ALLOC_OBJ_CLEAR(session->cert_hash_set, struct cert_hash_set);
202 }
203 if (!session->cert_hash_set->ch[error_depth])
204 {
205 ALLOC_OBJ(session->cert_hash_set->ch[error_depth], struct cert_hash);
206 }
207
208 struct cert_hash *ch = session->cert_hash_set->ch[error_depth];
209 ASSERT(sizeof(ch->sha256_hash) == BLEN(cert_hash));
210 memcpy(ch->sha256_hash, CBPTR(cert_hash), sizeof(ch->sha256_hash));
211 }
212}
213
214void
216{
217 if (chs)
218 {
219 int i;
220 for (i = 0; i < MAX_CERT_DEPTH; ++i)
221 {
222 free(chs->ch[i]);
223 }
224 free(chs);
225 }
226}
227
228bool
229cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_set *chs2)
230{
231 if (chs1 && chs2)
232 {
233 int i;
234 for (i = 0; i < MAX_CERT_DEPTH; ++i)
235 {
236 const struct cert_hash *ch1 = chs1->ch[i];
237 const struct cert_hash *ch2 = chs2->ch[i];
238
239 if (!ch1 && !ch2)
240 {
241 continue;
242 }
243 else if (ch1 && ch2
244 && !memcmp(ch1->sha256_hash, ch2->sha256_hash, sizeof(ch1->sha256_hash)))
245 {
246 continue;
247 }
248 else
249 {
250 return false;
251 }
252 }
253 return true;
254 }
255 else if (!chs1 && !chs2)
256 {
257 return true;
258 }
259 else
260 {
261 return false;
262 }
263}
264
265static struct cert_hash_set *
267{
268 struct cert_hash_set *dest = NULL;
269 if (chs)
270 {
271 int i;
272 ALLOC_OBJ_CLEAR(dest, struct cert_hash_set);
273 for (i = 0; i < MAX_CERT_DEPTH; ++i)
274 {
275 const struct cert_hash *ch = chs->ch[i];
276 if (ch)
277 {
278 ALLOC_OBJ(dest->ch[i], struct cert_hash);
279 memcpy(dest->ch[i]->sha256_hash, ch->sha256_hash, sizeof(dest->ch[i]->sha256_hash));
280 }
281 }
282 }
283 return dest;
284}
285void
287{
288 const struct cert_hash_set *chs = multi->session[TM_ACTIVE].cert_hash_set;
289 if (chs && !multi->locked_cert_hash_set)
290 {
292 }
293}
294
295/*
296 * Returns the string associated with the given certificate type.
297 */
298static const char *
300{
301 switch (type)
302 {
304 return "SERVER";
305
307 return "CLIENT";
308
309 default:
310 return "?";
311 }
312}
313
314/*
315 * Verify the peer's certificate fields.
316 *
317 * @param opt the tls options to verify against
318 * @param peer_cert the peer's certificate
319 * @param subject the peer's extracted subject name
320 * @param subject the peer's extracted common name
321 */
322static result_t
323verify_peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_cert, const char *subject,
324 const char *common_name)
325{
326 /* verify certificate nsCertType */
328 {
329 if (SUCCESS == x509_verify_ns_cert_type(peer_cert, opt->ns_cert_type))
330 {
331 msg(D_HANDSHAKE, "VERIFY OK: nsCertType=%s", print_nsCertType(opt->ns_cert_type));
332 }
333 else
334 {
335 msg(D_HANDSHAKE, "VERIFY nsCertType ERROR: %s, require nsCertType=%s", subject,
337 return FAILURE; /* Reject connection */
338 }
339 }
340
341 /* verify certificate ku */
342 if (opt->remote_cert_ku[0] != 0)
343 {
344 if (SUCCESS == x509_verify_cert_ku(peer_cert, opt->remote_cert_ku, MAX_PARMS))
345 {
346 msg(D_HANDSHAKE, "VERIFY KU OK");
347 }
348 else
349 {
350 msg(D_HANDSHAKE, "VERIFY KU ERROR");
351 return FAILURE; /* Reject connection */
352 }
353 }
354
355 /* verify certificate eku */
356 if (opt->remote_cert_eku != NULL)
357 {
358 if (SUCCESS == x509_verify_cert_eku(peer_cert, opt->remote_cert_eku))
359 {
360 msg(D_HANDSHAKE, "VERIFY EKU OK");
361 }
362 else
363 {
364 msg(D_HANDSHAKE, "VERIFY EKU ERROR");
365 return FAILURE; /* Reject connection */
366 }
367 }
368
369 /* verify X509 name or username against --verify-x509-[user]name */
371 {
372 const char *err_fmt = "VERIFY X509NAME ERROR: %s, must be %s";
373 const char *match_str = common_name;
374 bool verified = false;
375 switch (opt->verify_x509_type)
376 {
378 match_str = subject;
379 verified = !strcmp(opt->verify_x509_name, match_str);
380 break;
382 verified = !strcmp(opt->verify_x509_name, match_str);
383 break;
385 err_fmt = "VERIFY X509NAME ERROR: %s, must start with %s";
386 verified = !strncmp(opt->verify_x509_name, match_str, strlen(opt->verify_x509_name));
387 break;
388 default:
389 ASSERT(0); /* should not happen */
390 break;
391 }
392 if (!verified)
393 {
394 msg(D_HANDSHAKE, err_fmt, match_str, opt->verify_x509_name);
395 return FAILURE;
396 }
397 msg(D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject);
398 }
399
400 return SUCCESS;
401}
402
403#if defined(__GNUC__) || defined(__clang__)
404#pragma GCC diagnostic push
405#pragma GCC diagnostic ignored "-Wsign-conversion"
406#endif
407
408/*
409 * Export the subject, common_name, and raw certificate fields to the
410 * environment for later verification by scripts and plugins.
411 */
412static void
413verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert_depth,
414 const char *subject, const struct x509_track *x509_track)
415{
416 char envname[64];
417 const char *serial = NULL;
418 struct gc_arena gc = gc_new();
419
420 /* Save X509 fields in environment */
421 if (x509_track)
422 {
423 x509_setenv_track(x509_track, es, cert_depth, peer_cert);
424 }
425 else
426 {
427 x509_setenv(es, cert_depth, peer_cert);
428 }
429
430 /* export subject name string as environmental variable */
431 snprintf(envname, sizeof(envname), "tls_id_%d", cert_depth);
432 setenv_str(es, envname, subject);
433
434 /* export X509 cert fingerprints */
435 {
436 struct buffer sha1 = x509_get_sha1_fingerprint(peer_cert, &gc);
437 struct buffer sha256 = x509_get_sha256_fingerprint(peer_cert, &gc);
438
439 snprintf(envname, sizeof(envname), "tls_digest_%d", cert_depth);
440 setenv_str(es, envname, format_hex_ex(BPTR(&sha1), BLEN(&sha1), 0, 1, ":", &gc));
441
442 snprintf(envname, sizeof(envname), "tls_digest_sha256_%d", cert_depth);
443 setenv_str(es, envname, format_hex_ex(BPTR(&sha256), BLEN(&sha256), 0, 1, ":", &gc));
444 }
445
446 /* export serial number as environmental variable */
447 serial = backend_x509_get_serial(peer_cert, &gc);
448 snprintf(envname, sizeof(envname), "tls_serial_%d", cert_depth);
449 setenv_str(es, envname, serial);
450
451 /* export serial number in hex as environmental variable */
452 serial = backend_x509_get_serial_hex(peer_cert, &gc);
453 snprintf(envname, sizeof(envname), "tls_serial_hex_%d", cert_depth);
454 setenv_str(es, envname, serial);
455
456 gc_free(&gc);
457}
458
463static bool
465 const char *pem_export_fname)
466{
467 /* export the path to the current certificate in pem file format */
468 setenv_str(es, "peer_cert", pem_export_fname);
469
470 return backend_x509_write_pem(peer_cert, pem_export_fname) == SUCCESS;
471}
472
473static void
474verify_cert_cert_delete_env(struct env_set *es, const char *pem_export_fname)
475{
476 env_set_del(es, "peer_cert");
477 if (pem_export_fname)
478 {
479 unlink(pem_export_fname);
480 }
481}
482
483/*
484 * call --tls-verify plug-in(s)
485 */
486static result_t
487verify_cert_call_plugin(const struct plugin_list *plugins, struct env_set *es, int cert_depth,
488 openvpn_x509_cert_t *cert, char *subject)
489{
490 if (plugin_defined(plugins, OPENVPN_PLUGIN_TLS_VERIFY))
491 {
492 int ret;
493 struct argv argv = argv_new();
494
495 argv_printf(&argv, "%d %s", cert_depth, subject);
496
497 ret =
498 plugin_call_ssl(plugins, OPENVPN_PLUGIN_TLS_VERIFY, &argv, NULL, es, cert_depth, cert);
499
500 argv_free(&argv);
501
502 if (ret == OPENVPN_PLUGIN_FUNC_SUCCESS)
503 {
504 msg(D_HANDSHAKE, "VERIFY PLUGIN OK: depth=%d, %s", cert_depth, subject);
505 }
506 else
507 {
508 msg(D_HANDSHAKE, "VERIFY PLUGIN ERROR: depth=%d, %s", cert_depth, subject);
509 return FAILURE; /* Reject connection */
510 }
511 }
512 return SUCCESS;
513}
514
515/*
516 * run --tls-verify script
517 */
518static result_t
519verify_cert_call_command(const char *verify_command, struct env_set *es, int cert_depth,
520 char *subject)
521{
522 int ret;
523 struct argv argv = argv_new();
524
525 setenv_str(es, "script_type", "tls-verify");
526
527 argv_parse_cmd(&argv, verify_command);
528 argv_printf_cat(&argv, "%d %s", cert_depth, subject);
529
530 argv_msg_prefix(D_TLS_DEBUG, &argv, "TLS: executing verify command");
531 ret = openvpn_run_script(&argv, es, 0, "--tls-verify script");
532
533 argv_free(&argv);
534
535 if (ret)
536 {
537 msg(D_HANDSHAKE, "VERIFY SCRIPT OK: depth=%d, %s", cert_depth, subject);
538 return SUCCESS;
539 }
540
541 msg(D_HANDSHAKE, "VERIFY SCRIPT ERROR: depth=%d, %s", cert_depth, subject);
542 return FAILURE; /* Reject connection */
543}
544
545/*
546 * check peer cert against CRL directory
547 */
548static result_t
549verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert, const char *subject,
550 int cert_depth)
551{
552 result_t ret = FAILURE;
553 char fn[256];
554 int fd = -1;
555 struct gc_arena gc = gc_new();
556
557 char *serial = backend_x509_get_serial(cert, &gc);
558 if (!serial)
559 {
560 msg(D_HANDSHAKE, "VERIFY CRL: depth=%d, %s, serial number is not available", cert_depth,
561 subject);
562 goto cleanup;
563 }
564
565 if (!checked_snprintf(fn, sizeof(fn), "%s%c%s", crl_dir, PATH_SEPARATOR, serial))
566 {
567 msg(D_HANDSHAKE, "VERIFY CRL: filename overflow");
568 goto cleanup;
569 }
570 fd = platform_open(fn, O_RDONLY, 0);
571 if (fd >= 0)
572 {
573 msg(D_HANDSHAKE, "VERIFY CRL: depth=%d, %s, serial=%s is revoked", cert_depth, subject,
574 serial);
575 goto cleanup;
576 }
577
578 ret = SUCCESS;
579
580cleanup:
581
582 if (fd != -1)
583 {
584 close(fd);
585 }
586 gc_free(&gc);
587 return ret;
588}
589
591verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depth)
592{
593 /* need to define these variables here so goto cleanup will always have
594 * them defined */
595 result_t ret = FAILURE;
596 struct gc_arena gc = gc_new();
597 const char *pem_export_fname = NULL;
598
599 const struct tls_options *opt = session->opt;
600 ASSERT(opt);
601
602 session->verified = false;
603
604 /* get the X509 name */
605 char *subject = x509_get_subject(cert, &gc);
606 if (!subject)
607 {
609 "VERIFY ERROR: depth=%d, could not extract X509 "
610 "subject string from certificate",
611 cert_depth);
612 goto cleanup;
613 }
614
615 /* enforce character class restrictions in X509 name */
616 string_mod_remap_name(subject);
617 string_replace_leading(subject, '-', '_');
618
619 /* extract the username (default is CN) */
620 struct buffer buf = alloc_buf_gc(256, &gc);
621 for (int i = 0; opt->x509_username_field[i] != NULL; i++)
622 {
623 char username[TLS_USERNAME_LEN + 1] = { 0 }; /* null-terminated */
624
625 if (SUCCESS
626 != backend_x509_get_username(username, sizeof(username), opt->x509_username_field[i],
627 cert))
628 {
629 if (!cert_depth)
630 {
632 "VERIFY ERROR: could not extract %s from X509 "
633 "subject string ('%s') -- note that the field length is "
634 "limited to %d characters",
635 opt->x509_username_field[i], subject, TLS_USERNAME_LEN);
636 goto cleanup;
637 }
638 break;
639 }
640 if (!buf_printf(&buf, i ? "_%s" : "%s", username))
641 {
642 if (!cert_depth)
643 {
645 "VERIFY ERROR: could not append %s from X509 "
646 "certificate -- note that the username length is "
647 "limited to %d characters",
648 opt->x509_username_field[i], buf.capacity - 1);
649 goto cleanup;
650 }
651 break;
652 }
653 }
654
655 char *common_name = BSTR(&buf);
656 if (!common_name)
657 {
659 "VERIFY ERROR: depth=%d, could not extract X509 "
660 "username string from certificate",
661 cert_depth);
662 goto cleanup;
663 }
664
665 /* enforce character class restrictions in common name */
666 string_mod_remap_name(common_name);
667
668 /* warn if cert chain is too deep */
669 if (cert_depth >= MAX_CERT_DEPTH)
670 {
672 "TLS Error: Convoluted certificate chain detected with depth [%d] greater than %d",
673 cert_depth, MAX_CERT_DEPTH);
674 goto cleanup; /* Reject connection */
675 }
676
677 if (cert_depth == opt->verify_hash_depth && opt->verify_hash)
678 {
679 struct buffer cert_fp = { 0 };
680
681 switch (opt->verify_hash_algo)
682 {
683 case MD_SHA1:
684 cert_fp = x509_get_sha1_fingerprint(cert, &gc);
685 break;
686
687 case MD_SHA256:
688 cert_fp = x509_get_sha256_fingerprint(cert, &gc);
689 break;
690
691 default:
692 /* This should normally not happen at all; the algorithm used
693 * is parsed by add_option() [options.c] and set to a predefined
694 * value in an enumerated type. So if this unlikely scenario
695 * happens, consider this a failure
696 */
697 msg(M_WARN,
698 "Unexpected invalid algorithm used with "
699 "--verify-hash (%i)",
700 opt->verify_hash_algo);
701 ret = FAILURE;
702 goto cleanup;
703 }
704
705 if (BLEN(&cert_fp) == 0)
706 {
707 msg(D_TLS_ERRORS, "TLS Error: cannot compute the certificate fingerprint for "
708 "--verify-hash/--peer-fingerprint");
709 goto cleanup;
710 }
711
712 const struct verify_hash_list *current_hash = opt->verify_hash;
713
714 while (current_hash)
715 {
716 if (memcmp_constant_time(BPTR(&cert_fp), current_hash->hash, BLENZ(&cert_fp)) == 0)
717 {
718 break;
719 }
720 current_hash = current_hash->next;
721 }
722
723 if (!current_hash)
724 {
725 const char *hex_fp = format_hex_ex(BPTR(&cert_fp), BLEN(&cert_fp), 0, 1, ":", &gc);
727 "TLS Error: --tls-verify/--peer-fingerprint "
728 "certificate hash verification failed. (got certificate "
729 "fingerprint: %s)",
730 hex_fp);
731 goto cleanup;
732 }
733 }
734
735 /* save common name in session object */
736 if (cert_depth == 0)
737 {
738 set_common_name(session, common_name);
739 }
740
741 session->verify_maxlevel = max_int(session->verify_maxlevel, cert_depth);
742
743 if (opt->export_peer_cert_dir)
744 {
745 pem_export_fname = platform_create_temp_file(opt->export_peer_cert_dir, "pef", &gc);
746
747 if (!pem_export_fname || !verify_cert_cert_export_env(opt->es, cert, pem_export_fname))
748 {
750 "TLS Error: Failed to export certificate for "
751 "--tls-export-cert in %s",
753 goto cleanup;
754 }
755 }
756 /* export certificate values to the environment */
757 verify_cert_set_env(opt->es, cert, cert_depth, subject, opt->x509_track);
758
759 /* export current untrusted IP */
761
762 /* If this is the peer's own certificate, verify it */
763 if (cert_depth == 0 && SUCCESS != verify_peer_cert(opt, cert, subject, common_name))
764 {
765 goto cleanup;
766 }
767
768 /* call --tls-verify plug-in(s), if registered */
769 if (SUCCESS != verify_cert_call_plugin(opt->plugins, opt->es, cert_depth, cert, subject))
770 {
771 goto cleanup;
772 }
773
774 /* run --tls-verify script */
775 if (opt->verify_command
776 && SUCCESS != verify_cert_call_command(opt->verify_command, opt->es, cert_depth, subject))
777 {
778 goto cleanup;
779 }
780
781 /* check peer cert against CRL */
782 if (opt->crl_file)
783 {
785 {
786 if (SUCCESS != verify_check_crl_dir(opt->crl_file, cert, subject, cert_depth))
787 {
788 goto cleanup;
789 }
790 }
791 else
792 {
793 if (tls_verify_crl_missing(opt))
794 {
795 msg(D_TLS_ERRORS, "VERIFY ERROR: CRL not loaded");
796 goto cleanup;
797 }
798 }
799 }
800
801 msg(D_HANDSHAKE, "VERIFY OK: depth=%d, %s", cert_depth, subject);
802 session->verified = true;
803 ret = SUCCESS;
804
805cleanup:
806 verify_cert_cert_delete_env(opt->es, pem_export_fname);
807 if (ret != SUCCESS)
808 {
809 tls_clear_error(); /* always? */
810 session->verified = false; /* double sure? */
811 }
812
813 gc_free(&gc);
814
815 return ret;
816}
817
818#if defined(__GNUC__) || defined(__clang__)
819#pragma GCC diagnostic pop
820#endif
821
822/* ***************************************************************************
823 * Functions for the management of deferred authentication when using
824 * user/password authentication.
825 *************************************************************************** */
826
827void
828auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
829{
830 free(multi->client_reason);
831 multi->client_reason = NULL;
832
833 if (client_reason && strlen(client_reason))
834 {
835 multi->client_reason = string_alloc(client_reason, NULL);
836 }
837}
838
839#ifdef ENABLE_MANAGEMENT
840
841static inline enum auth_deferred_result
843{
845 {
846 return ks->mda_status;
847 }
848 else
849 {
850 return ACF_DISABLED;
851 }
852}
853#endif /* ifdef ENABLE_MANAGEMENT */
854
859static void
861{
862 if (ads && ads->auth_pending_file)
863 {
865 free(ads->auth_pending_file);
866 ads->auth_pending_file = NULL;
867 }
868}
869
873static bool
874check_auth_pending_method(const char *peer_info, const char *method)
875{
876 struct gc_arena gc = gc_new();
877
878 char *iv_sso = extract_var_peer_info(peer_info, "IV_SSO=", &gc);
879 if (!iv_sso)
880 {
881 gc_free(&gc);
882 return false;
883 }
884
885 char *lasts = NULL;
886 const char *client_method = strtok_r(iv_sso, ",", &lasts);
887 bool supported = false;
888
889 while (client_method)
890 {
891 if (0 == strcmp(client_method, method))
892 {
893 supported = true;
894 break;
895 }
896 client_method = strtok_r(NULL, ",", &lasts);
897 }
898
899 gc_free(&gc);
900 return supported;
901}
902
903#if defined(__GNUC__) || defined(__clang__)
904#pragma GCC diagnostic push
905#pragma GCC diagnostic ignored "-Wsign-conversion"
906#endif
907
916static bool
918 struct tls_multi *multi,
919 struct tls_session *session)
920{
921 bool ret = true;
922 if (ads->auth_pending_file)
923 {
924 struct buffer_list *lines = buffer_list_file(ads->auth_pending_file, 1024);
925 if (lines && lines->head)
926 {
927 /* Must have at least three lines. further lines are ignored for
928 * forward compatibility */
929 if (!lines->head->next || !lines->head->next->next)
930 {
931 msg(M_WARN, "auth pending control file is not at least "
932 "three lines long.");
933 buffer_list_free(lines);
934 return false;
935 }
936 struct buffer *timeout_buf = &lines->head->buf;
937 struct buffer *iv_buf = &lines->head->next->buf;
938 struct buffer *extra_buf = &lines->head->next->next->buf;
939
940 /* Remove newline chars at the end of the lines */
941 buf_chomp(timeout_buf);
942 buf_chomp(iv_buf);
943 buf_chomp(extra_buf);
944
945 errno = 0;
946 long timeout = strtol(BSTR(timeout_buf), NULL, 10);
947 // cppcheck-suppress compareValueOutOfTypeRangeError ; ULONG_MAX==UINT_MAX on Windows
948 if (timeout <= 0 || (unsigned long)timeout > UINT_MAX || errno)
949 {
950 msg(M_WARN, "could not parse auth pending file timeout");
951 buffer_list_free(lines);
952 return false;
953 }
954
955 const char *pending_method = BSTR(iv_buf);
956 if (!check_auth_pending_method(multi->peer_info, pending_method))
957 {
958 char buf[128];
959 snprintf(buf, sizeof(buf),
960 "Authentication failed, required pending auth "
961 "method '%s' not supported",
962 pending_method);
963 auth_set_client_reason(multi, buf);
964 msg(M_INFO,
965 "Client does not supported auth pending method '%s'",
966 pending_method);
967 ret = false;
968 }
969 else
970 {
971 send_auth_pending_messages(multi, session, BSTR(extra_buf),
972 (unsigned int)timeout);
973 }
974 }
975
976 buffer_list_free(lines);
977 }
979 return ret;
980}
981
982#if defined(__GNUC__) || defined(__clang__)
983#pragma GCC diagnostic pop
984#endif
985
990void
992{
993 if (ads->auth_control_file)
994 {
996 free(ads->auth_control_file);
997 ads->auth_control_file = NULL;
998 }
1000 {
1002 free(ads->auth_failed_reason_file);
1003 ads->auth_failed_reason_file = NULL;
1004 }
1006}
1007
1014static bool
1016{
1017 struct gc_arena gc = gc_new();
1018
1020 const char *acf = platform_create_temp_file(opt->tmp_dir, "acf", &gc);
1021 const char *apf = platform_create_temp_file(opt->tmp_dir, "apf", &gc);
1022 const char *afr = platform_create_temp_file(opt->tmp_dir, "afr", &gc);
1023
1024 if (acf && apf && afr)
1025 {
1026 ads->auth_control_file = string_alloc(acf, NULL);
1027 ads->auth_pending_file = string_alloc(apf, NULL);
1028 ads->auth_failed_reason_file = string_alloc(afr, NULL);
1029
1030 setenv_str(opt->es, "auth_control_file", ads->auth_control_file);
1031 setenv_str(opt->es, "auth_pending_file", ads->auth_pending_file);
1032 setenv_str(opt->es, "auth_failed_reason_file", ads->auth_failed_reason_file);
1033 }
1034
1035 gc_free(&gc);
1036 return (acf && apf && afr);
1037}
1038
1042static void
1044{
1045 if (ads->auth_failed_reason_file)
1046 {
1047 struct gc_arena gc = gc_new();
1049
1050 if (BLEN(&reason))
1051 {
1052 auth_set_client_reason(multi, BSTR(&reason));
1053 }
1054 gc_free(&gc);
1055 }
1056}
1057
1058
1069static enum auth_deferred_result
1071{
1072 if (ads->auth_control_file)
1073 {
1074 unsigned int ret = ads->auth_control_status;
1075 if (ret == ACF_PENDING && !cached)
1076 {
1077 FILE *fp = fopen(ads->auth_control_file, "r");
1078 if (fp)
1079 {
1080 const int c = fgetc(fp);
1081 if (c == '1')
1082 {
1083 ret = ACF_SUCCEEDED;
1084 }
1085 else if (c == '0')
1086 {
1087 ret = ACF_FAILED;
1088 }
1089 fclose(fp);
1090 ads->auth_control_status = ret;
1091 }
1092 }
1093 return ret;
1094 }
1095 return ACF_DISABLED;
1096}
1097
1105static void
1106update_key_auth_status(bool cached, struct key_state *ks)
1107{
1108 if (ks->authenticated == KS_AUTH_FALSE)
1109 {
1110 return;
1111 }
1112 else
1113 {
1114 enum auth_deferred_result auth_plugin = ACF_DISABLED;
1115 enum auth_deferred_result auth_script = ACF_DISABLED;
1116 enum auth_deferred_result auth_man = ACF_DISABLED;
1117 auth_plugin = key_state_test_auth_control_file(&ks->plugin_auth, cached);
1118 auth_script = key_state_test_auth_control_file(&ks->script_auth, cached);
1119#ifdef ENABLE_MANAGEMENT
1120 auth_man = man_def_auth_test(ks);
1121#endif
1122 ASSERT(auth_plugin < 4 && auth_script < 4 && auth_man < 4);
1123
1124 if (auth_plugin == ACF_FAILED || auth_script == ACF_FAILED || auth_man == ACF_FAILED)
1125 {
1127 return;
1128 }
1129 else if (auth_plugin == ACF_PENDING || auth_script == ACF_PENDING
1130 || auth_man == ACF_PENDING)
1131 {
1132 if (now >= ks->auth_deferred_expire)
1133 {
1134 /* Window to authenticate the key has expired, mark
1135 * the key as unauthenticated */
1137 }
1138 }
1139 else
1140 {
1141 /* all auth states (auth_plugin, auth_script, auth_man)
1142 * are either ACF_DISABLED or ACF_SUCCEDED now, which
1143 * translates to "not checked" or "auth succeeded"
1144 */
1146 }
1147 }
1148}
1149
1150
1157static time_t cache_intervals[] = { 0, 0, 0, 0, 0, 1, 1, 2, 2, 4, 8 };
1158
1163static bool
1165{
1166 unsigned int idx = min_uint(multi->tas_cache_num_updates, SIZE(cache_intervals) - 1);
1167 time_t latency = cache_intervals[idx];
1168 return multi->tas_cache_last_update + latency >= now;
1169}
1170
1171enum tls_auth_status
1173{
1174 bool deferred = false;
1175
1176 /* at least one valid key has successfully completed authentication */
1177 bool success = false;
1178
1179 /* at least one key is enabled for decryption */
1180 int active = 0;
1181
1182 /* at least one key already failed authentication */
1183 bool failed_auth = false;
1184
1185 bool cached = tls_authentication_status_use_cache(multi);
1186
1187 for (int i = 0; i < KEY_SCAN_SIZE; ++i)
1188 {
1189 struct key_state *ks = get_key_scan(multi, i);
1190 if (TLS_AUTHENTICATED(multi, ks))
1191 {
1192 active++;
1193 update_key_auth_status(cached, ks);
1194
1195 if (ks->authenticated == KS_AUTH_FALSE)
1196 {
1197 failed_auth = true;
1198 }
1199 else if (ks->authenticated == KS_AUTH_DEFERRED)
1200 {
1201 deferred = true;
1202 }
1203 else if (ks->authenticated == KS_AUTH_TRUE)
1204 {
1205 success = true;
1206 }
1207 }
1208 }
1209
1210 /* we did not rely on a cached result, remember the cache update time */
1211 if (!cached)
1212 {
1213 multi->tas_cache_last_update = now;
1214 multi->tas_cache_num_updates++;
1215 }
1216
1217#if 0
1218 dmsg(D_TLS_ERRORS, "TAS: a=%d s=%d d=%d f=%d", active, success, deferred, failed_auth);
1219#endif
1220 if (failed_auth)
1221 {
1222 const struct key_state *ks = get_primary_key(multi);
1225
1226 /* We have at least one session that failed authentication. There
1227 * might be still another session with valid keys.
1228 * Although our protocol allows keeping the VPN session alive
1229 * with the other session (and we actually did that in earlier
1230 * version, this behaviour is really strange from a user (admin)
1231 * experience */
1233 }
1234 else if (success)
1235 {
1237 }
1238 else if (active == 0 || deferred)
1239 {
1240 /* We have a deferred authentication and no currently active key
1241 * (first auth, no renegotiation) */
1243 }
1244 else
1245 {
1246 /* at least one key is active but none is fully authenticated (!success)
1247 * and all active are either failed authed or expired deferred auth */
1249 }
1250}
1251
1252#ifdef ENABLE_MANAGEMENT
1253/*
1254 * For deferred auth, this is where the management interface calls (on server)
1255 * to indicate auth failure/success.
1256 */
1257bool
1258tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth,
1259 const char *client_reason)
1260{
1261 struct key_state *ks = NULL;
1262 if (multi)
1263 {
1264 auth_set_client_reason(multi, client_reason);
1266
1267 if (ks)
1268 {
1269 ks->mda_status = auth ? ACF_SUCCEEDED : ACF_FAILED;
1270 }
1271 else
1272 {
1274 "%s: no key state found for management key id %u",
1275 __func__, mda_key_id);
1276 }
1277 }
1278 return (bool)ks;
1279}
1280#endif /* ifdef ENABLE_MANAGEMENT */
1281
1282
1283/* ****************************************************************************
1284 * Functions to verify username and password
1285 *
1286 * Authenticate a client using username/password.
1287 * Runs on server.
1288 *
1289 * If you want to add new authentication methods,
1290 * this is the place to start.
1291 *************************************************************************** */
1292
1293/*
1294 * Verify the user name and password using a script
1295 */
1296static int
1298 const struct user_pass *up)
1299{
1300 struct gc_arena gc = gc_new();
1301 struct argv argv = argv_new();
1302 const char *tmp_file = "";
1303 int retval = OPENVPN_PLUGIN_FUNC_ERROR;
1304 struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */
1305
1306 /* Set environmental variables prior to calling script */
1307 setenv_str(session->opt->es, "script_type", "user-pass-verify");
1308
1309 /* format command line */
1310 argv_parse_cmd(&argv, session->opt->auth_user_pass_verify_script);
1311
1312 if (session->opt->auth_user_pass_verify_script_via_file)
1313 {
1314 struct status_output *so;
1315
1316 tmp_file = platform_create_temp_file(session->opt->tmp_dir, "up", &gc);
1317 if (tmp_file)
1318 {
1319 so = status_open(tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
1320 status_printf(so, "%s", up->username);
1321 status_printf(so, "%s", up->password);
1322 if (!status_close(so))
1323 {
1324 msg(D_TLS_ERRORS, "TLS Auth Error: could not write username/password to file: %s",
1325 tmp_file);
1326 goto done;
1327 }
1328 /* pass temp file name to script */
1329 argv_printf_cat(&argv, "%s", tmp_file);
1330 }
1331 }
1332 else
1333 {
1334 /* username env is already set by set_verify_user_pass_env */
1335 setenv_str(session->opt->es, "password", up->password);
1336 }
1337
1338 /* pre-create files for deferred auth control */
1340 {
1342 "TLS Auth Error (%s): "
1343 "could not create deferred auth control file",
1344 __func__);
1345 retval = OPENVPN_PLUGIN_FUNC_ERROR;
1346 goto done;
1347 }
1348
1349 /* call command */
1350 int script_ret =
1351 openvpn_run_script(&argv, session->opt->es, S_EXITCODE, "--auth-user-pass-verify");
1352 switch (script_ret)
1353 {
1354 case 0:
1355 retval = OPENVPN_PLUGIN_FUNC_SUCCESS;
1356 break;
1357
1358 case 2:
1359 retval = OPENVPN_PLUGIN_FUNC_DEFERRED;
1360 break;
1361
1362 default:
1364 retval = OPENVPN_PLUGIN_FUNC_ERROR;
1365 break;
1366 }
1367 if (retval == OPENVPN_PLUGIN_FUNC_DEFERRED)
1368 {
1369 /* Check if we the plugin has written the pending auth control
1370 * file and send the pending auth to the client */
1372 {
1373 retval = OPENVPN_PLUGIN_FUNC_ERROR;
1375 }
1376 }
1377 else
1378 {
1379 /* purge auth control filename (and file itself) for non-deferred returns */
1381 }
1382
1383done:
1384 if (tmp_file && strlen(tmp_file) > 0)
1385 {
1386 platform_unlink(tmp_file);
1387 }
1388
1389 if (!session->opt->auth_user_pass_verify_script_via_file)
1390 {
1391 setenv_del(session->opt->es, "password");
1392 }
1393
1394 argv_free(&argv);
1395 gc_free(&gc);
1396 return retval;
1397}
1398
1399#ifdef ENABLE_PLUGIN
1400void
1401verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response)
1402{
1403 struct tls_session *session = &multi->session[TM_ACTIVE];
1404 setenv_str(session->opt->es, "crresponse", cr_response);
1405
1406 plugin_call(session->opt->plugins, OPENVPN_PLUGIN_CLIENT_CRRESPONSE, NULL, NULL,
1407 session->opt->es);
1408
1409 setenv_del(session->opt->es, "crresponse");
1410}
1411#endif
1412
1413void
1414verify_crresponse_script(struct tls_multi *multi, const char *cr_response)
1415{
1416 struct tls_session *session = &multi->session[TM_ACTIVE];
1417
1418 if (!session->opt->client_crresponse_script)
1419 {
1420 return;
1421 }
1422 struct argv argv = argv_new();
1423 struct gc_arena gc = gc_new();
1424
1425 setenv_str(session->opt->es, "script_type", "client-crresponse");
1426
1427 /* Since cr response might be sensitive, like a stupid way to query
1428 * a password via 2FA, we pass it via file instead environment */
1429 const char *tmp_file = platform_create_temp_file(session->opt->tmp_dir, "cr", &gc);
1430 static const char *openerrmsg = "TLS CR Response Error: could not write "
1431 "crtext challenge response to file: %s";
1432
1433 if (tmp_file)
1434 {
1435 struct status_output *so = status_open(tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
1436 status_printf(so, "%s", cr_response);
1437 if (!status_close(so))
1438 {
1439 msg(D_TLS_ERRORS, openerrmsg, tmp_file);
1440 tls_deauthenticate(multi);
1441 goto done;
1442 }
1443 }
1444 else
1445 {
1446 msg(D_TLS_ERRORS, openerrmsg, "creating file failed");
1447 tls_deauthenticate(multi);
1448 goto done;
1449 }
1450
1451 argv_parse_cmd(&argv, session->opt->client_crresponse_script);
1452 argv_printf_cat(&argv, "%s", tmp_file);
1453
1454
1455 if (!openvpn_run_script(&argv, session->opt->es, 0, "--client-crresponse"))
1456 {
1457 tls_deauthenticate(multi);
1458 }
1459done:
1460 if (tmp_file)
1461 {
1462 platform_unlink(tmp_file);
1463 }
1464 argv_free(&argv);
1465 gc_free(&gc);
1466}
1467
1468/*
1469 * Verify the username and password using a plugin
1470 */
1471static int
1473 const struct user_pass *up)
1474{
1475 int retval = OPENVPN_PLUGIN_FUNC_ERROR;
1476 struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */
1477
1478 /* set password in private env space */
1479 setenv_str(session->opt->es, "password", up->password);
1480
1481 /* generate filename for deferred auth control file */
1483 {
1485 "TLS Auth Error (%s): "
1486 "could not create deferred auth control file",
1487 __func__);
1488 return retval;
1489 }
1490
1491 /* call command */
1492 retval = plugin_call(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY, NULL, NULL,
1493 session->opt->es);
1494
1495 if (retval == OPENVPN_PLUGIN_FUNC_DEFERRED)
1496 {
1497 /* Check if the plugin has written the pending auth control
1498 * file and send the pending auth to the client */
1500 {
1501 retval = OPENVPN_PLUGIN_FUNC_ERROR;
1502 }
1503 }
1504
1505 if (retval == OPENVPN_PLUGIN_FUNC_ERROR)
1506 {
1508 }
1509
1510 if (retval != OPENVPN_PLUGIN_FUNC_DEFERRED)
1511 {
1512 /* purge auth control filename (and file itself) for non-deferred returns */
1514 }
1515
1516 setenv_del(session->opt->es, "password");
1517
1518 return retval;
1519}
1520
1521
1522#ifdef ENABLE_MANAGEMENT
1523static void
1525{
1526 const struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */
1527
1528 /* set username/password in private env space */
1529 setenv_str(session->opt->es, "password", up->password);
1530
1531 if (management)
1532 {
1534 session->opt->es);
1535 }
1536
1537 setenv_del(session->opt->es, "password");
1538}
1539#endif /* ifdef ENABLE_MANAGEMENT */
1540
1541static bool
1542set_verify_user_pass_env(const struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
1543{
1544 /* Is username defined? */
1545 if ((session->opt->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL) || strlen(up->username))
1546 {
1547 setenv_str(session->opt->es, "username", up->username);
1548
1549 /* setenv incoming cert common name for script */
1550 setenv_str(session->opt->es, "common_name", session->common_name);
1551
1552 /* setenv client real IP address */
1554
1555 /*
1556 * if we are using auth-gen-token, send also the session id of auth gen token to
1557 * allow the management to figure out if it is a new session or a continued one
1558 */
1559 add_session_token_env(session, multi, up);
1560 return true;
1561 }
1562 else
1563 {
1564 msg(D_TLS_ERRORS, "TLS Auth Error: peer provided a blank username");
1565 return false;
1566 }
1567}
1568
1569bool
1570ssl_verify_username_length(const struct tls_session *session, const char *username)
1571{
1572 if ((session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME)
1573 && strlen(username) > TLS_USERNAME_LEN)
1574 {
1576 "TLS Auth Error: --username-as-common name specified and "
1577 "username is longer than the maximum permitted Common Name "
1578 "length of %d characters",
1580 return false;
1581 }
1582 else
1583 {
1584 return true;
1585 }
1586}
1587
1594void
1595verify_user_pass(struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
1596{
1597 struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */
1598
1599 ASSERT(up && !up->protected);
1600
1601#ifdef ENABLE_MANAGEMENT
1602 const bool man_def_auth = management_enable_def_auth(management);
1603#endif
1604
1605 /* enforce character class restrictions in username/password */
1607 string_mod(up->password, CC_PRINT, CC_CRLF, '_');
1608
1609 /*
1610 * If auth token succeeds we skip the auth
1611 * methods unless otherwise specified
1612 */
1613 bool skip_auth = false;
1614
1615 /* Replace username early if override-username is in effect but only
1616 * if client is sending the original username */
1617 if (multi->locked_original_username
1618 && strncmp(up->username, multi->locked_original_username, sizeof(up->username)) == 0)
1619 {
1621 "TLS: Replacing client provided username '%s' with "
1622 "username from override-user '%s'",
1623 up->username, multi->locked_username);
1624 strlcpy(up->username, multi->locked_username, sizeof(up->username));
1625 }
1626
1627 /*
1628 * If server is configured with --auth-gen-token and the client sends
1629 * something that looks like an authentication token, this
1630 * round will be done internally using the token instead of
1631 * calling any external authentication modules.
1632 */
1633 if (session->opt->auth_token_generate && is_auth_token(up->password))
1634 {
1636
1637 /* If this is a valid token and the first time we see an auth-token
1638 * in this multi session, save it as initial auth token. This ensures
1639 * using the same session ID and initial timestamp in new tokens */
1641 {
1642 multi->auth_token_initial = string_alloc(up->password, NULL);
1643 }
1644
1645 if (session->opt->auth_token_call_auth)
1646 {
1647 /*
1648 * we do not care about the result here because it is
1649 * the responsibility of the external authentication to
1650 * decide what to do with the result
1651 */
1652 }
1654 {
1655 /*
1656 * We do not want the EXPIRED or EMPTY USER flags here so check
1657 * for equality with AUTH_TOKEN_HMAC_OK
1658 */
1659 msg(M_WARN,
1660 "TLS: Username/auth-token authentication "
1661 "succeeded for username '%s'",
1662 up->username);
1663 skip_auth = true;
1664 }
1665 else
1666 {
1667 wipe_auth_token(multi);
1669 msg(M_WARN,
1670 "TLS: Username/auth-token authentication "
1671 "failed for username '%s'",
1672 up->username);
1673 return;
1674 }
1675 }
1676
1677 int plugin_status = OPENVPN_PLUGIN_FUNC_SUCCESS;
1678 int script_status = OPENVPN_PLUGIN_FUNC_SUCCESS;
1679 /* Set the environment variables used by all auth variants */
1680 if (!set_verify_user_pass_env(up, multi, session))
1681 {
1682 skip_auth = true;
1683 plugin_status = OPENVPN_PLUGIN_FUNC_ERROR;
1684 }
1685
1686 /* call plugin(s) and/or script */
1687 if (!skip_auth)
1688 {
1689#ifdef ENABLE_MANAGEMENT
1690 if (man_def_auth)
1691 {
1693 }
1694#endif
1695 if (plugin_defined(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY))
1696 {
1697 plugin_status = verify_user_pass_plugin(session, multi, up);
1698 }
1699
1700 if (session->opt->auth_user_pass_verify_script)
1701 {
1702 script_status = verify_user_pass_script(session, multi, up);
1703 }
1704 }
1705
1706 /* check sizing of username if it will become our common name */
1708 {
1709 plugin_status = OPENVPN_PLUGIN_FUNC_ERROR;
1710 script_status = OPENVPN_PLUGIN_FUNC_ERROR;
1711 }
1712
1713 /* auth succeeded? */
1714 bool plugin_ok = plugin_status == OPENVPN_PLUGIN_FUNC_SUCCESS
1715 || plugin_status == OPENVPN_PLUGIN_FUNC_DEFERRED;
1716
1717 bool script_ok = script_status == OPENVPN_PLUGIN_FUNC_SUCCESS
1718 || script_status == OPENVPN_PLUGIN_FUNC_DEFERRED;
1719
1720 if (script_ok && plugin_ok && tls_lock_username(multi, up->username))
1721 {
1723 if (plugin_status == OPENVPN_PLUGIN_FUNC_DEFERRED
1724 || script_status == OPENVPN_PLUGIN_FUNC_DEFERRED)
1725 {
1727 }
1728#ifdef ENABLE_MANAGEMENT
1729 if (man_def_auth)
1730 {
1731 if (skip_auth)
1732 {
1734 }
1735 else
1736 {
1738 }
1739 }
1740#endif
1741 if ((session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME))
1742 {
1744 }
1745
1746 if ((session->opt->auth_token_generate))
1747 {
1748 /*
1749 * If we accepted a (not expired) token, i.e.
1750 * initial auth via token on new connection, we need
1751 * to store the auth-token in multi->auth_token, so
1752 * the initial timestamp and session id can be extracted from it
1753 */
1756 {
1757 multi->auth_token = string_alloc(up->password, NULL);
1758 }
1759
1760 /*
1761 * Server is configured with --auth-gen-token. Generate or renew
1762 * the token.
1763 */
1764 generate_auth_token(up, multi);
1765 }
1766
1767 msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
1768 (ks->authenticated == KS_AUTH_DEFERRED) ? "deferred" : "succeeded", up->username,
1769 (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
1770 }
1771 else
1772 {
1774 msg(D_TLS_ERRORS, "TLS Auth Error: Auth Username/Password verification failed for peer");
1775 }
1776}
1777
1778void
1780{
1781 struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */
1782
1783 /* While it shouldn't really happen, don't allow the common name to be NULL */
1784 if (!session->common_name)
1785 {
1787 }
1788
1789 /* Don't allow the CN to change once it's been locked */
1790 if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cn)
1791 {
1792 const char *cn = session->common_name;
1793 if (cn && strcmp(cn, multi->locked_cn))
1794 {
1796 "TLS Auth Error: TLS object CN attempted to change from '%s' to '%s' -- tunnel disabled",
1797 multi->locked_cn, cn);
1798
1799 /* change the common name back to its original value and disable the tunnel */
1801 tls_deauthenticate(multi);
1802 }
1803 }
1804
1805 /* Don't allow the cert hashes to change once they have been locked */
1807 {
1808 const struct cert_hash_set *chs = session->cert_hash_set;
1809 if (chs && !cert_hash_compare(chs, multi->locked_cert_hash_set))
1810 {
1812 "TLS Auth Error: TLS object CN=%s client-provided SSL certs unexpectedly changed during mid-session reauth",
1813 session->common_name);
1814
1815 /* disable the tunnel */
1816 tls_deauthenticate(multi);
1817 }
1818 }
1819
1820 /* verify --client-config-dir based authentication */
1821 if (ks->authenticated > KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
1822 {
1823 struct gc_arena gc = gc_new();
1824
1825 const char *cn = session->common_name;
1826 const char *path = platform_gen_path(session->opt->client_config_dir_exclusive, cn, &gc);
1827 if (!cn || !strcmp(cn, CCD_DEFAULT) || !platform_test_file(path))
1828 {
1830 wipe_auth_token(multi);
1832 "TLS Auth Error: --client-config-dir authentication failed for common name '%s' file='%s'",
1833 session->common_name, path ? path : "UNDEF");
1834 }
1835
1836 gc_free(&gc);
1837 }
1838}
1839
1840void
1842{
1843 struct env_item *item = es->list;
1844 while (item)
1845 {
1846 struct env_item *next = item->next;
1847 if (item->string && 0 == strncmp("X509_", item->string, strlen("X509_")))
1848 {
1849 env_set_del(es, item->string);
1850 }
1851 item = next;
1852 }
1853}
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:490
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
void argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix)
Similar to argv_msg() but prefixes the messages being written with a given string.
Definition argv.c:259
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:447
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
Definition argv.c:471
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
void generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
Generate an auth token based on username and timestamp.
Definition auth_token.c:182
unsigned int verify_auth_token(struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
Verifies the auth token to be in the format that generate_auth_token create and checks if the token i...
Definition auth_token.c:311
void add_session_token_env(struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
Put the session id, and auth token status into the environment if auth-token is enabled.
Definition auth_token.c:57
void wipe_auth_token(struct tls_multi *multi)
Wipes the authentication token out of the memory, frees and cleans up related buffers and flags.
Definition auth_token.c:417
bool is_auth_token(const char *password)
Return if the password string has the format of an auth token.
Definition auth_token.c:40
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:231
void string_replace_leading(char *str, const char match, const char replace)
Replace all leading occurrences of a character in a string.
Definition buffer.c:1088
struct buffer_list * buffer_list_file(const char *fn, int max_line_len)
Read a file into a buffer list, one buffer per line.
Definition buffer.c:1376
void buffer_list_free(struct buffer_list *ol)
Frees a buffer list and all the buffers in it.
Definition buffer.c:1194
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
char * format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
Format a binary buffer as a hex string.
Definition buffer.c:460
bool string_mod(char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
Modifies a string in place by replacing certain classes of characters of it with a specified characte...
Definition buffer.c:1021
struct buffer buffer_read_from_file(const char *filename, struct gc_arena *gc)
buffer_read_from_file - copy the content of a file into a buffer
Definition buffer.c:1399
bool checked_snprintf(char *str, size_t size, const char *format,...)
Like snprintf() but returns an boolean.
Definition buffer.c:1150
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
void buf_chomp(struct buffer *buf)
Remove trailing newline and carriage-return characters from a buffer.
Definition buffer.c:530
#define ALLOC_OBJ(dptr, type)
Allocate memory for a single object of the given type.
Definition buffer.h:2025
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define BPTR(buf)
Return a pointer to the start of the buffer content.
Definition buffer.h:139
#define CC_CRLF
carriage return or newline
Definition buffer.h:1723
#define CBPTR(buf)
Return a const pointer to the start of the buffer content.
Definition buffer.h:141
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
#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 CC_PRINT
printable (>= 32, != 127)
Definition buffer.h:1694
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
Definition buffer.h:2036
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
#define CCD_DEFAULT
Definition common.h:63
size_t strlcpy(char *dest, const char *src, size_t maxlen)
char * strtok_r(char *s, const char *delim, char **last)
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
@ MD_SHA256
@ MD_SHA1
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:305
bool env_set_del(struct env_set *es, const char *str)
Definition env_set.c:182
void setenv_del(struct env_set *es, const char *name)
Definition env_set.c:350
#define D_TLS_DEBUG_LOW
Definition errlevel.h:75
#define D_HANDSHAKE
Definition errlevel.h:70
#define D_MULTI_LOW
Definition errlevel.h:84
#define D_TLS_ERRORS
Definition errlevel.h:58
#define M_INFO
Definition errlevel.h:54
#define D_TLS_DEBUG
Definition errlevel.h:161
#define KS_SIZE
Size of the tls_session.key array.
Definition ssl_common.h:476
#define KS_PRIMARY
Primary key state index.
Definition ssl_common.h:472
#define TM_SIZE
Size of the tls_multi.session \ array.
Definition ssl_common.h:557
#define TM_ACTIVE
Active tls_session.
Definition ssl_common.h:552
#define TLS_AUTHENTICATED(multi, ks)
Check whether the ks key_state has finished the key exchange part of the OpenVPN hand shake.
Definition ssl_verify.h:113
static unsigned int min_uint(unsigned int x, unsigned int y)
Definition integer.h:66
static int max_int(int x, int y)
Definition integer.h:92
void management_notify_client_needing_auth(struct management *man, const unsigned int mda_key_id, struct man_def_auth_context *mdac, const struct env_set *es)
Definition manage.c:3117
static bool management_enable_def_auth(const struct management *man)
Definition manage.h:449
#define SIZE(x)
Definition basic.h:29
#define dmsg(flags,...)
Definition error.h:164
#define msg(flags,...)
Definition error.h:152
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
#define MAX_PARMS
Definition options.h:51
time_t now
Definition otime.c:33
bool platform_test_file(const char *filename)
Return true if filename can be opened for read.
Definition platform.c:690
const char * platform_create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc)
Create a temporary file in directory, returns the filename of the created file.
Definition platform.c:545
const char * platform_gen_path(const char *directory, const char *filename, struct gc_arena *gc)
Put a directory and filename together.
Definition platform.c:622
bool platform_unlink(const char *filename)
Definition platform.c:492
int platform_open(const char *path, int flags, int mode)
Definition platform.c:518
int plugin_call_ssl(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es, int certdepth, openvpn_x509_cert_t *current_cert)
Definition plugin.c:797
bool plugin_defined(const struct plugin_list *pl, const int type)
Definition plugin.c:919
static int plugin_call(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es)
Definition plugin.h:195
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
#define S_EXITCODE
Instead of returning 1/0 for success/fail, return exit code when between 0 and 255 and -1 otherwise.
Definition run_command.h:53
static int openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook)
Will run a script and return the exit code of the script if between 0 and 255, -1 otherwise.
Definition run_command.h:89
void setenv_link_socket_actual(struct env_set *es, const char *name_prefix, const struct link_socket_actual *act, const unsigned int flags)
#define SA_IP_PORT
Definition socket_util.h:99
void tls_clear_error(void)
Clear the underlying SSL library's error state.
#define AUTH_TOKEN_HMAC_OK
Auth-token sent from client has valid hmac.
Definition ssl_common.h:694
#define KEY_SCAN_SIZE
Definition ssl_common.h:574
auth_deferred_result
Definition ssl_common.h:175
@ ACF_PENDING
deferred auth still pending
Definition ssl_common.h:176
@ ACF_SUCCEEDED
deferred auth has suceeded
Definition ssl_common.h:177
@ ACF_FAILED
deferred auth has failed
Definition ssl_common.h:179
@ ACF_DISABLED
deferred auth is not used
Definition ssl_common.h:178
#define AUTH_TOKEN_EXPIRED
Auth-token sent from client has expired.
Definition ssl_common.h:696
static struct key_state * get_key_scan(struct tls_multi *multi, int index)
gets an item of key_state objects in the order they should be scanned by data channel modules.
Definition ssl_common.h:748
#define SSLF_AUTH_USER_PASS_OPTIONAL
Definition ssl_common.h:431
@ KS_AUTH_TRUE
Key state is authenticated.
Definition ssl_common.h:157
@ KS_AUTH_FALSE
Key state is not authenticated.
Definition ssl_common.h:154
@ KS_AUTH_DEFERRED
Key state authentication is being deferred, by async auth.
Definition ssl_common.h:155
#define SSLF_CRL_VERIFY_DIR
Definition ssl_common.h:433
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
#define SSLF_USERNAME_AS_COMMON_NAME
Definition ssl_common.h:430
static struct key_state * get_key_by_management_key_id(struct tls_multi *multi, unsigned int mda_key_id)
Gets the key_state object that belongs to the management key id or return NULL if not found.
Definition ssl_common.h:782
char * extract_var_peer_info(const char *peer_info, const char *var, struct gc_arena *gc)
Extracts a variable from peer info, the returned string will be allocated using the supplied gc_arena...
Definition ssl_util.c:63
SSL utility functions.
static result_t verify_cert_call_command(const char *verify_command, struct env_set *es, int cert_depth, char *subject)
Definition ssl_verify.c:519
static void verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert_depth, const char *subject, const struct x509_track *x509_track)
Definition ssl_verify.c:413
void key_state_rm_auth_control_files(struct auth_deferred_status *ads)
Removes auth_pending and auth_control files from file system and key_state structure.
Definition ssl_verify.c:991
static bool key_state_gen_auth_control_files(struct auth_deferred_status *ads, const struct tls_options *opt)
Generates and creates the control files used for deferred authentification in the temporary directory...
static struct cert_hash_set * cert_hash_copy(const struct cert_hash_set *chs)
Definition ssl_verify.c:266
static void key_state_rm_auth_pending_file(struct auth_deferred_status *ads)
Removes auth_pending file from the file system and key_state structure.
Definition ssl_verify.c:860
static result_t verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert, const char *subject, int cert_depth)
Definition ssl_verify.c:549
bool ssl_verify_username_length(const struct tls_session *session, const char *username)
Checks if the username length is valid to use.
bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason)
static void verify_cert_cert_delete_env(struct env_set *es, const char *pem_export_fname)
Definition ssl_verify.c:474
static void tls_deauthenticate(struct tls_multi *multi)
Definition ssl_verify.c:69
void verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response)
Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE.
bool cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_set *chs2)
Compares certificates hashes, returns true if hashes are equal.
Definition ssl_verify.c:229
void tls_x509_clear_env(struct env_set *es)
Remove any X509_ env variables from env_set es.
static void update_key_auth_status(bool cached, struct key_state *ks)
This method takes a key_state and if updates the state of the key if it is deferred.
void tls_lock_cert_hash_set(struct tls_multi *multi)
Locks the certificate hash set used in the given tunnel.
Definition ssl_verify.c:286
static bool tls_authentication_status_use_cache(const struct tls_multi *multi)
uses cache_intervals times to determine if we should update the cache.
static result_t verify_peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_cert, const char *subject, const char *common_name)
Definition ssl_verify.c:323
result_t verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depth)
Definition ssl_verify.c:591
void tls_lock_common_name(struct tls_multi *multi)
Locks the common name field for the given tunnel.
Definition ssl_verify.c:132
static enum auth_deferred_result man_def_auth_test(const struct key_state *ks)
Definition ssl_verify.c:842
void verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
Perform final authentication checks, including locking of the cn, the allowed certificate hashes,...
static bool tls_lock_username(struct tls_multi *multi, const char *username)
Definition ssl_verify.c:145
static int verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
static bool key_state_check_auth_pending_file(struct auth_deferred_status *ads, struct tls_multi *multi, struct tls_session *session)
Checks if the deferred state should also send auth pending request to the client.
Definition ssl_verify.c:917
const char * tls_username(const struct tls_multi *multi, const bool null)
Returns the username field for the given tunnel.
Definition ssl_verify.c:172
void set_common_name(struct tls_session *session, const char *common_name)
Sets the common name field for the given tunnel.
Definition ssl_verify.c:85
void auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
Sets the reason why authentication of a client failed.
Definition ssl_verify.c:828
static result_t verify_cert_call_plugin(const struct plugin_list *plugins, struct env_set *es, int cert_depth, openvpn_x509_cert_t *cert, char *subject)
Definition ssl_verify.c:487
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_user_pass(struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
Main username/password verification entry point.
static bool set_verify_user_pass_env(const struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
static const char * print_nsCertType(int type)
Definition ssl_verify.c:299
void verify_crresponse_script(struct tls_multi *multi, const char *cr_response)
Runs the –client-crresponse script if one is defined.
static time_t cache_intervals[]
The minimum times to have passed to update the cache.
static int verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
static enum auth_deferred_result key_state_test_auth_control_file(struct auth_deferred_status *ads, bool cached)
Checks the auth control status from a file.
static void string_mod_remap_name(char *str)
Definition ssl_verify.c:51
void cert_hash_remember(struct tls_session *session, const int error_depth, const struct buffer *cert_hash)
Definition ssl_verify.c:194
static void setenv_untrusted(struct tls_session *session)
Definition ssl_verify.c:60
static void verify_user_pass_management(struct tls_session *session, const struct user_pass *up)
const char * tls_common_name(const struct tls_multi *multi, const bool null)
Returns the common name field for the given tunnel.
Definition ssl_verify.c:107
static bool verify_cert_cert_export_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, const char *pem_export_fname)
Exports the certificate in peer_cert into the environment and adds the filname.
Definition ssl_verify.c:464
void cert_hash_free(struct cert_hash_set *chs)
Frees the given set of certificate hashes.
Definition ssl_verify.c:215
static bool check_auth_pending_method(const char *peer_info, const char *method)
Check peer_info if the client supports the requested pending auth method.
Definition ssl_verify.c:874
static void check_for_client_reason(struct tls_multi *multi, const struct auth_deferred_status *ads)
Check if the script/plugin left a message in the auth failed message file and relay it to the user.
Control Channel Verification Module.
tls_auth_status
Definition ssl_verify.h:74
@ TLS_AUTHENTICATION_DEFERRED
Definition ssl_verify.h:77
@ TLS_AUTHENTICATION_SUCCEEDED
Definition ssl_verify.h:75
@ TLS_AUTHENTICATION_FAILED
Definition ssl_verify.h:76
#define VERIFY_X509_SUBJECT_DN
Definition ssl_verify.h:69
#define VERIFY_X509_SUBJECT_RDN
Definition ssl_verify.h:70
#define NS_CERT_CHECK_CLIENT
Do not perform Netscape certificate type verification.
Definition ssl_verify.h:254
#define VERIFY_X509_NONE
Definition ssl_verify.h:68
#define TLS_USERNAME_LEN
Maximum length of common name.
Definition ssl_verify.h:54
#define VERIFY_X509_SUBJECT_RDN_PREFIX
Definition ssl_verify.h:71
#define MAX_CERT_DEPTH
Maximum certificate depth we will allow.
Definition ssl_verify.h:51
#define NS_CERT_CHECK_NONE
Do not perform Netscape certificate type verification.
Definition ssl_verify.h:250
#define NS_CERT_CHECK_SERVER
Do not perform Netscape certificate type verification.
Definition ssl_verify.h:252
Control Channel Verification Module library-specific backend interface.
struct buffer x509_get_sha256_fingerprint(openvpn_x509_cert_t *cert, struct gc_arena *gc)
Retrieve the certificate's SHA256 fingerprint.
void x509_setenv_track(const struct x509_track *xt, struct env_set *es, const int depth, openvpn_x509_cert_t *x509)
void x509_setenv(struct env_set *es, int cert_depth, openvpn_x509_cert_t *cert)
bool tls_verify_crl_missing(const struct tls_options *opt)
Return true iff a CRL is configured, but is not loaded.
result_t backend_x509_write_pem(openvpn_x509_cert_t *cert, const char *filename)
result_t x509_verify_ns_cert_type(openvpn_x509_cert_t *cert, const int cert_type)
char * backend_x509_get_serial_hex(openvpn_x509_cert_t *cert, struct gc_arena *gc)
struct buffer x509_get_sha1_fingerprint(openvpn_x509_cert_t *cert, struct gc_arena *gc)
Retrieve the certificate's SHA1 fingerprint.
result_t x509_verify_cert_ku(openvpn_x509_cert_t *x509, const unsigned *const expected_ku, size_t expected_len)
char * x509_get_subject(openvpn_x509_cert_t *cert, struct gc_arena *gc)
Definition test_pkcs11.c:70
char * backend_x509_get_serial(openvpn_x509_cert_t *cert, struct gc_arena *gc)
result_t backend_x509_get_username(char *common_name, size_t cn_len, char *x509_username_field, openvpn_x509_cert_t *peer_cert)
result_t
Result of verification function.
@ FAILURE
@ SUCCESS
result_t x509_verify_cert_eku(openvpn_x509_cert_t *x509, const char *const expected_oid)
mbedtls_x509_crt openvpn_x509_cert_t
Control Channel Verification Module OpenSSL backend.
void status_printf(struct status_output *so, const char *format,...)
Definition status.c:221
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
Definition status.c:64
bool status_close(struct status_output *so)
Definition status.c:187
#define STATUS_OUTPUT_WRITE
Definition status.h:51
Definition argv.h:35
char * auth_failed_reason_file
Definition ssl_common.h:168
unsigned int auth_control_status
Definition ssl_common.h:169
struct buffer_entry * next
Pointer to the next node, or NULL.
Definition buffer.h:2163
struct buffer buf
The buffer stored in this list node.
Definition buffer.h:2162
A singly-linked list of buffers, with head/tail pointers for O(1) push.
Definition buffer.h:2168
struct buffer_entry * head
Next item to pop/peek.
Definition buffer.h:2169
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int capacity
Size in bytes of memory allocated by malloc().
Definition buffer.h:72
Structure containing the hashes for a full certificate chain.
Definition ssl_verify.h:64
struct cert_hash * ch[MAX_CERT_DEPTH]
Array of certificate hashes.
Definition ssl_verify.h:65
Structure containing the hash for a single certificate.
Definition ssl_verify.h:58
unsigned char sha256_hash[256/8]
Definition ssl_verify.h:59
char * string
Definition env_set.h:38
struct env_item * next
Definition env_set.h:39
struct env_item * list
Definition env_set.h:45
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Security parameter state of one TLS and data channel key session.
Definition ssl_common.h:208
unsigned int auth_token_state_flags
The state of the auth-token sent from the client.
Definition ssl_common.h:211
struct auth_deferred_status plugin_auth
Definition ssl_common.h:268
unsigned int mda_key_id
Definition ssl_common.h:263
struct auth_deferred_status script_auth
Definition ssl_common.h:269
enum auth_deferred_result mda_status
Definition ssl_common.h:264
enum ks_auth_state authenticated
Definition ssl_common.h:259
time_t auth_deferred_expire
Definition ssl_common.h:260
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:619
char * auth_token_initial
The first auth-token we sent to a client.
Definition ssl_common.h:691
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
unsigned int tas_cache_num_updates
The number of times we updated the cache.
Definition ssl_common.h:671
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
Definition ssl_common.h:721
struct cert_hash_set * locked_cert_hash_set
Definition ssl_common.h:663
time_t tas_cache_last_update
Time of last when we updated the cached state of tls_authentication_status deferred files.
Definition ssl_common.h:668
char * locked_cn
Our locked common name, username, and cert hashes (cannot change during the life of this tls_multi ob...
Definition ssl_common.h:652
char * client_reason
An error message to send to client on AUTH_FAILED.
Definition ssl_common.h:674
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
char * locked_original_username
The username that client initially used before being overridden by –override-user.
Definition ssl_common.h:661
struct env_set * es
Definition ssl_common.h:418
unsigned remote_cert_ku[MAX_PARMS]
Definition ssl_common.h:363
const char * tmp_dir
Definition ssl_common.h:399
int verify_hash_depth
Definition ssl_common.h:366
const struct plugin_list * plugins
Definition ssl_common.h:420
const char * export_peer_cert_dir
Definition ssl_common.h:400
char * x509_username_field[MAX_PARMS]
Definition ssl_common.h:369
const char * verify_command
Definition ssl_common.h:357
struct verify_hash_list * verify_hash
Definition ssl_common.h:365
int verify_x509_type
Definition ssl_common.h:358
const char * verify_x509_name
Definition ssl_common.h:359
const struct x509_track * x509_track
Definition ssl_common.h:445
unsigned int ssl_flags
Definition ssl_common.h:439
hash_algo_type verify_hash_algo
Definition ssl_common.h:368
const char * crl_file
Definition ssl_common.h:360
const char * remote_cert_eku
Definition ssl_common.h:364
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:497
struct key_state key[KS_SIZE]
Definition ssl_common.h:532
struct cert_hash_set * cert_hash_set
Definition ssl_common.h:525
char * common_name
Definition ssl_common.h:523
bool protected
Definition misc.h:61
char password[USER_PASS_LEN]
Definition misc.h:71
char username[USER_PASS_LEN]
Definition misc.h:70
struct verify_hash_list * next
Definition options.h:252
uint8_t hash[SHA256_DIGEST_LENGTH]
Definition options.h:251
#define PATH_SEPARATOR
Definition syshead.h:428
static int cleanup(void **state)
struct gc_arena gc
Definition test_ssl.c:138