The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
verify.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 9226f9cb0ecd45a58e29e6d6cc035fbf3d10db40 $
19 *
20 * @file tls/verify.c
21 * @brief Expose certificate OIDs as attributes, and call validation virtual
22 * server to check cert is valid.
23 *
24 * @copyright 2003 Alan DeKok (aland@freeradius.org)
25 * @copyright 2006-2016 The FreeRADIUS server project
26 */
27#ifdef WITH_TLS
28#define LOG_PREFIX "tls"
29
30#define _TLS_PRIVATE 1
31
32#include <freeradius-devel/server/exec.h>
33#include <freeradius-devel/server/pair.h>
34#include <freeradius-devel/tls/log.h>
35#include <freeradius-devel/unlang/function.h>
36#include <freeradius-devel/unlang/subrequest.h>
37#include <freeradius-devel/util/debug.h>
38#include <freeradius-devel/util/strerror.h>
39#include <freeradius-devel/util/syserror.h>
40
41#include <freeradius-devel/protocol/tls/freeradius.h>
42
43#include <openssl/x509v3.h>
44
45#include "attrs.h"
46#include "base.h"
47
48/** Check to see if a verification operation should apply to a certificate
49 *
50 * @param[in] depth starting at 0.
51 * Certificate 0 is the leaf cert (i.e. the client or server cert);
52 * @param[in] untrusted The number of untrusted certificates.
53 * @param[in] mode to check
54 * @return
55 * - true if a given validation check should apply.
56 ** - false if a validation check should not apply.
57 */
58static inline CC_HINT(always_inline)
59bool verify_applies(fr_tls_verify_mode_t mode, int depth, int untrusted)
60{
61 if (mode == FR_TLS_VERIFY_MODE_ALL) return true;
62 if (mode == FR_TLS_VERIFY_MODE_DISABLED) return false;
63
64 if ((mode & FR_TLS_VERIFY_MODE_LEAF) && (depth == 0)) return true;
65 if ((mode & FR_TLS_VERIFY_MODE_ISSUER) && (depth == 1)) return true;
66 if ((mode & FR_TLS_VERIFY_MODE_UNTRUSTED) && (depth < untrusted)) return true;
67
68 return false;
69}
70
71DIAG_OFF_OPTIONAL(used-but-marked-unused) /* fix spurious warnings for sk macros */
72
73/** Print verbose humanly readable messages about why certificate validation failed
74 *
75 */
76static void tls_verify_error_detail(request_t *request, SSL_CTX *ctx, int err)
77{
78 X509_STORE *store = SSL_CTX_get_ex_data(ctx, FR_TLS_EX_CTX_INDEX_VERIFY_STORE);
79
80 /*
81 * store is NULL if we're configured with PSK only. i.e. no certs.
82 */
83 if (!store) return;
84
85 switch (err) {
86 /*
87 * We linked the provided cert to at least one
88 * other in a chain, but the chain doesn't terminate
89 * in a root CA.
90 */
91 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
93
94 /*
95 * We failed to link the provided cert to any
96 * other local certificates in the chain.
97 */
98 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
99 RDEBUG2("(TLS) Static certificates in verification store are");
100 if (RDEBUG_ENABLED2) {
101#if OPENSSL_VERSION_NUMBER >= 0x30300000L
102 STACK_OF(X509_OBJECT) *objects = X509_STORE_get1_objects(store);
103
104 if (objects) {
105 RINDENT();
106 fr_tls_x509_objects_log(request, L_DBG, objects);
107 REXDENT();
108 sk_X509_OBJECT_pop_free(objects, X509_OBJECT_free);
109 }
110#else
111 RINDENT();
112 fr_tls_x509_objects_log(request, L_DBG, X509_STORE_get0_objects(store));
113 REXDENT();
114#endif
115 }
116 break;
117
118 default:
119 break;
120 }
121}
122
123/** Validates a certificate using custom logic
124 *
125 * Before trusting a certificate, we make sure that the certificate is
126 * 'valid'. There are several checks we perform to verify its validity.
127 *
128 * 1. Verify the certificate's signature, and verifying that the certificate has
129 * been issued by a trusted Certificate Authority (this is done for us by OpenSSL).
130 *
131 * 2. Verify that the certificate is valid for the present date (i.e. it is being
132 * presented within its validity dates).
133 *
134 * 3. Verify that the certificate has not been revoked by its issuing Certificate
135 * Authority, by checking with respect to a Certificate Revocation List (CRL).
136 *
137 * @note This callback will be called multiple times based on the depth of the root
138 * certificate chain.
139 *
140 * @note OpenSSL runs the handshake (including this callback) on a fibre with a
141 * limited stack (32 KB on OpenSSL releases without ASYNC_set_mem_functions()).
142 * Because of that limited stack, we need to perform all certificate decoding
143 * outside of the fibre on the main stack, i.e. after OpenSSL has yielded and
144 * the handshake has paused. See fr_tls_verify_cert_pending_push().
145 *
146 * @param ok preverify ok. 1 if true, 0 if false.
147 * @param x509_ctx containing certs to verify.
148 * @return
149 * - 0 if not valid.
150 * - 1 if valid.
151 */
152int fr_tls_verify_cert_cb(int ok, X509_STORE_CTX *x509_ctx)
153{
154 X509 *cert;
155
156 SSL_CTX *ssl_ctx;
157 SSL *ssl;
158 fr_tls_session_t *tls_session;
159 int err, depth;
160 fr_tls_conf_t *conf;
161 int my_ok = ok;
162 int untrusted;
163
165 fr_pair_t *depth_pair;
166
167 cert = X509_STORE_CTX_get_current_cert(x509_ctx);
168 err = X509_STORE_CTX_get_error(x509_ctx);
169 depth = X509_STORE_CTX_get_error_depth(x509_ctx);
170 untrusted = X509_STORE_CTX_get_num_untrusted(x509_ctx);
171
172 /*
173 * Retrieve the pointer to the SSL of the connection currently treated
174 * and the application specific data stored into the SSL object.
175 */
176 ssl = X509_STORE_CTX_get_ex_data(x509_ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
177 ssl_ctx = SSL_get_SSL_CTX(ssl);
178 conf = fr_tls_session_conf(ssl);
179 tls_session = talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_TLS_SESSION), fr_tls_session_t);
180 request = fr_tls_session_request(tls_session->ssl);
181
182 /*
183 * If this error appears it suggests
184 * that OpenSSL is trying to perform post-handshake
185 * certificate validation which we don't support.
186 */
187 if (!tls_session->can_pause) {
188 fr_assert_msg("Unexpected call to %s. "
189 "tls_session_async_handshake_cont must be in call stack", __FUNCTION__);
190 return 0;
191 }
192
193 /*
194 * Bail out as quickly as possible, producing
195 * as few errors as possible.
196 */
198 X509_STORE_CTX_set_error(x509_ctx, 0);
199 return 1;
200 }
201
202 /*
203 * Find or add the chain depth attribute and record the greatest depth we see + 1,
204 * as depth is zero based.
205 */
206 if (unlikely(fr_pair_find_or_append_by_da(request->session_state_ctx, &depth_pair, &request->session_state_pairs,
208 REDEBUG("(TLS) Failed to add certificate chain depth pair");
209 return 0;
210 }
211 if (depth_pair->vp_uint32 < ((uint32_t)depth) + 1) depth_pair->vp_uint32 = (uint32_t)depth + 1;
212
213 if (RDEBUG_ENABLED3) {
214 char subject[2048];
215 STACK_OF(X509) *our_chain;
216 int i;
217
218 our_chain = X509_STORE_CTX_get0_chain(x509_ctx);
219 RDEBUG3("(TLS) Certificate chain - %i cert(s) untrusted", untrusted);
220 for (i = sk_X509_num(our_chain); i > 0 ; i--) {
221 X509 *this_cert = sk_X509_value(our_chain, i - 1);
222
223 X509_NAME_oneline(X509_get_subject_name(this_cert), subject, sizeof(subject));
224 subject[sizeof(subject) - 1] = '\0';
225
226 RDEBUG3("(TLS) %s [%i] %s", this_cert == cert ? ">" : " ", i - 1, subject);
227 }
228 }
229
230 /*
231 * See if the user has disabled verification for
232 * this certificate. If they have, force verification
233 * to succeed.
234 */
235 if (!my_ok) {
236 char const *p = X509_verify_cert_error_string(err);
237 if (!verify_applies(conf->verify.mode, depth, untrusted)) {
238 RDEBUG2("(TLS) Ignoring verification error - %s (%i)", p, err);
239 tls_verify_error_detail(request, ssl_ctx, err);
240
241 my_ok = 1;
242 X509_STORE_CTX_set_error(x509_ctx, 0);
243 } else {
244 REDEBUG("(TLS) Verification error - %s (%i)", p, err);
245 fr_tls_session_error_add(request, FR_ERROR_VALUE_CERTIFICATE_VERIFY_FAILED);
246 tls_verify_error_detail(request, ssl_ctx, err);
247 goto done;
248 }
249 }
250
251done:
252 /*
253 * The chain is complete once OpenSSL reaches depth 0. Pause the handshake
254 * here so that fr_tls_verify_cert_pending_push() can decode the chain and run
255 * the `verify certificate` section on the main stack. Execution continues
256 * after the ASYNC_pause_job() call below once the section has run.
257 */
258 if (my_ok && (depth == 0)) {
259 bool want_pairs = conf->verify.attribute_mode != FR_TLS_VERIFY_MODE_DISABLED;
260 bool want_verify = conf->verify_certificate && tls_session->verify_peer_cert;
261
262 if (want_pairs || want_verify) {
263 fr_tls_verify_cert_request(tls_session, x509_ctx);
264
265 /*
266 * Be aware that if the request is cancelled
267 * whatever was meant to be done during the
268 * time we yielded may not have been completed.
269 */
270 ASYNC_pause_job();
271
272 /*
273 * Just try and bail out as quickly as possible.
274 */
276 X509_STORE_CTX_set_error(x509_ctx, 0);
277 fr_tls_verify_cert_reset(tls_session);
278 return 1;
279 }
280
281 /*
282 * If we couldn't decode the chain, or the
283 * `verify certificate` section rejected it,
284 * then validation overall fails.
285 */
286 if (!fr_tls_verify_cert_result(tls_session)) {
287 REDEBUG("(TLS) Certificate validation failed");
288 my_ok = 0;
289 X509_STORE_CTX_set_error(x509_ctx, X509_V_ERR_APPLICATION_VERIFICATION);
290 }
291 }
292 }
293
294 tls_session->peer_cert_ok = (my_ok > 0);
295 RDEBUG2("(TLS) [verify] = %s", my_ok ? "ok" : "invalid");
296
297 return my_ok;
298}
299DIAG_ON_OPTIONAL(used-but-marked-unused)
300
301/** Revalidates the client's certificate chain
302 *
303 * Wraps the fr_tls_verify_cert_cb callback, allowing us to use the same
304 * validation logic whenever we need to.
305 *
306 * @note Only use so far is forcing the chain to be re-validated on session
307 * resumption.
308 *
309 * @return
310 * - 1 if the chain could be validated.
311 * - 0 if the chain failed validation.
312 */
313int fr_tls_verify_cert_chain(request_t *request, SSL *ssl)
314{
315 int err;
316 int verify;
317 int ret = 1;
318
319 SSL_CTX *ssl_ctx;
320 STACK_OF(X509) *chain;
321 X509 *cert;
322 X509_STORE *store;
323 X509_STORE_CTX *store_ctx;
324
325 /*
326 * If there's no client certificate, we just return OK.
327 */
328 cert = SSL_get0_peer_certificate(ssl); /* Does not increase ref count */
329 if (!cert) return 1;
330
331 ssl_ctx = SSL_get_SSL_CTX(ssl);
332 store_ctx = X509_STORE_CTX_new();
333 if (unlikely(store_ctx == NULL)) {
334 REDEBUG("(TLS) Failed allocating X509_STORE_CTX");
335 return 0;
336 }
337
338 chain = SSL_get_peer_cert_chain(ssl); /* Does not increase ref count */
339 store = SSL_CTX_get_ex_data(ssl_ctx, FR_TLS_EX_CTX_INDEX_VERIFY_STORE); /* Gets the verification store */
340
341 /*
342 * This sets up a store_ctx for doing peer certificate verification.
343 *
344 * store_ctx - Is the ctx to initialise
345 * store - Is an X509_STORE of implicitly
346 * trusted certificates. Here we're using
347 * the verify store that was created when we
348 * allocated the SSL_CTX.
349 * cert - Is the certificate to validate.
350 * chain - Is any other certificates the peer provided
351 * us in order to build a chain from a trusted
352 * root or intermediary to its leaf (cert).
353 *
354 * Note: SSL_CTX_get_cert_store() returns the ctx->cert_store, which
355 * is not the same as the verification cert store.
356 */
357 if (unlikely(X509_STORE_CTX_init(store_ctx, store, cert, chain) != 1)) {
358 REDEBUG("(TLS) Failed initialising X509_STORE_CTX");
359 X509_STORE_CTX_free(store_ctx);
360 return 0;
361 }
362
363 X509_STORE_CTX_set_ex_data(store_ctx, SSL_get_ex_data_X509_STORE_CTX_idx(), ssl);
364 X509_STORE_CTX_set_verify_cb(store_ctx, fr_tls_verify_cert_cb);
365
366 verify = X509_verify_cert(store_ctx);
367 if (verify != 1) {
368 err = X509_STORE_CTX_get_error(store_ctx);
369
370 if (err != X509_V_OK) {
371 REDEBUG("(TLS) Failed re-validating resumed session: %s", X509_verify_cert_error_string(err));
372 fr_tls_session_error_add(request, FR_ERROR_VALUE_CERTIFICATE_REVALIDATION_FAILED);
373 ret = 0;
374 }
375 }
376
377 X509_STORE_CTX_free(store_ctx);
378
379 return ret;
380}
381
382/** Process the result of `verify certificate { ... }`
383 *
384 */
385static unlang_action_t tls_verify_peer_cert_result(request_t *request, void *uctx)
386{
387 fr_tls_session_t *tls_session = talloc_get_type_abort(uctx, fr_tls_session_t);
388 fr_pair_t *vp, *next;
389
390 fr_assert(tls_session->validate.state == FR_TLS_VALIDATION_REQUESTED);
391
392 vp = fr_pair_find_by_da(&request->reply_pairs, NULL, attr_tls_packet_type);
393 if (!vp || (vp->vp_uint32 != enum_tls_packet_type_success->vb_uint32)) {
394 REDEBUG("(TLS) Failed (re-)validating certificates");
395 fr_tls_session_error_add(request->parent, FR_ERROR_VALUE_VERIFY_CERTIFICATE_FAILED);
396
397 /*
398 * Hoist any instances of Module-Failure-Message from the subrequest
399 * so they can be used for logging failures.
400 */
402 while (vp && request->parent) {
404 fr_pair_remove(&request->request_pairs, vp);
405 fr_pair_steal_append(request->parent->request_ctx, &request->parent->request_pairs, vp);
406 vp = next;
407 }
408
409 tls_session->validate.state = FR_TLS_VALIDATION_FAILED;
411 }
412
413 tls_session->validate.state = FR_TLS_VALIDATION_SUCCESS;
414
415 RDEBUG2("(TLS) Certificates (re-)validated");
416
418}
419
420/** Push a `verify certificate { ... }` call into the current request, using a subrequest
421 *
422 * @param[in] request The current request.
423 * @param[in] tls_session The current TLS session.
424 * @return
425 * - UNLANG_ACTION_CALCULATE_RESULT on noop.
426 * - UNLANG_ACTION_PUSHED_CHILD on success.
427 * - UNLANG_ACTION_FAIL on failure.
428 */
429static unlang_action_t tls_verify_peer_cert_push(request_t *request, fr_tls_session_t *tls_session)
430{
431 fr_tls_conf_t *conf = tls_session->conf;
432 request_t *child;
433 fr_pair_t *vp;
435
436 fr_assert(conf->virtual_server);
437
438 MEM(child = tls_subrequest_alloc(request, enum_tls_packet_type_verify_certificate->vb_uint32,
439 &tls_session->session_id));
440 request = child;
441
442 /*
443 * Add extra pairs to the subrequest
444 */
445 fr_tls_session_extra_pairs_copy_to_child(child, tls_session);
446
447 /*
448 * Copy certificate pairs to the child session state
449 */
450 vp = NULL;
451 while ((vp = fr_pair_find_by_da(&request->parent->session_state_pairs, vp, attr_tls_certificate))) {
452 fr_pair_append(&request->session_state_pairs, fr_pair_copy(request->session_state_ctx, vp));
453 }
454 if (conf->verify.der_decode) {
455 while ((vp = fr_pair_find_by_da(&request->parent->session_state_pairs, vp, attr_der_certificate))) {
456 fr_pair_append(&request->session_state_pairs, fr_pair_copy(request->session_state_ctx, vp));
457 }
458 }
459
461 vp->vp_bool = tls_session->validate.resumed;
462
463 /*
464 * Allocate a child, and set it up to call
465 * the TLS virtual server.
466 */
467 ua = fr_tls_call_push(child, tls_verify_peer_cert_result, conf, tls_session, false);
468 if (ua == UNLANG_ACTION_FAIL) {
469 REDEBUG("(TLS) Failed calling TLS virtual server");
470 talloc_free(child);
471 return UNLANG_ACTION_FAIL;
472 }
473
474 return ua;
475}
476
477/** Clear any previous validation result
478 *
479 * Should be called by the validation requestor to get the result and reset
480 * the validation state.
481 *
482 * @return
483 * - true if the certificate chain was validated.
484 * - false if the certificate chain failed validation.
485 */
486bool fr_tls_verify_cert_result(fr_tls_session_t *tls_session)
487{
488 bool result;
489
490 fr_assert(tls_session->validate.state != FR_TLS_VALIDATION_INIT);
491
492 result = tls_session->validate.state == FR_TLS_VALIDATION_SUCCESS;
493
494 tls_session->validate.state = FR_TLS_VALIDATION_INIT;
495 tls_session->validate.resumed = false;
496
497 return result;
498}
499
500/** Reset the verification state
501 *
502 */
503void fr_tls_verify_cert_reset(fr_tls_session_t *tls_session)
504{
505 tls_session->validate.state = FR_TLS_VALIDATION_INIT;
506 tls_session->validate.resumed = false;
507 tls_session->validate.x509_ctx = NULL;
508}
509
510/** Request validation of the chain OpenSSL is verifying
511 *
512 * Called by fr_tls_verify_cert_cb() before it pauses the handshake.
513 *
514 * @param[in] tls_session The current TLS session.
515 * @param[in] x509_ctx holding the chain. Only valid while the
516 * handshake is paused inside the callback.
517 */
518void fr_tls_verify_cert_request(fr_tls_session_t *tls_session, X509_STORE_CTX *x509_ctx)
519{
520 fr_assert(tls_session->validate.state == FR_TLS_VALIDATION_INIT);
521
522 tls_session->validate.state = FR_TLS_VALIDATION_REQUESTED;
523 TLS_PENDING_SET(tls_session, FR_TLS_PENDING_VERIFY);
524 tls_session->validate.resumed = false;
525 tls_session->validate.x509_ctx = x509_ctx;
526}
527
528/** Request re-validation of the certificate pairs restored with a resumed session
529 *
530 * Called by the session cache code before it pauses the handshake. A resumed
531 * session has no chain to decode, the `TLS-Certificate` pairs came back with
532 * the session.
533 *
534 * @param[in] tls_session The current TLS session.
535 */
536void fr_tls_verify_resumed_request(fr_tls_session_t *tls_session)
537{
538 fr_assert(tls_session->validate.state == FR_TLS_VALIDATION_INIT);
539
540 tls_session->validate.state = FR_TLS_VALIDATION_REQUESTED;
541 TLS_PENDING_SET(tls_session, FR_TLS_PENDING_VERIFY);
542 tls_session->validate.resumed = true;
543 tls_session->validate.x509_ctx = NULL;
544}
545
546DIAG_OFF_OPTIONAL(used-but-marked-unused) /* fix spurious warnings for sk macros */
547/** Decode the chain OpenSSL is verifying into `session-state.TLS-Certificate` pairs
548 *
549 * Runs on the request's own stack while the handshake is paused in
550 * fr_tls_verify_cert_cb(). The certificate at depth 0 is the peer's, and
551 * `TLS-Certificate[n]` holds the certificate at depth n.
552 *
553 * @param[in] request The current request.
554 * @param[in] tls_session The current TLS session.
555 * @param[in] conf The TLS configuration.
556 * @return
557 * - 0 on success.
558 * - -1 if a certificate could not be decoded. No `TLS-Certificate`
559 * pairs remain in the session-state list.
560 */
561static int tls_verify_chain_pairs_add(request_t *request, fr_tls_session_t *tls_session, fr_tls_conf_t const *conf)
562{
563 X509_STORE_CTX *x509_ctx = tls_session->validate.x509_ctx;
564 STACK_OF(X509) *chain = X509_STORE_CTX_get0_chain(x509_ctx);
565 int untrusted = X509_STORE_CTX_get_num_untrusted(x509_ctx);
566 int num = sk_X509_num(chain);
567 int depth;
568
569 /*
570 * Deepest first, so each DER decoded certificate is prepended ahead
571 * of its issuer and `DER-Certificate[0]` is the peer's.
572 */
573 for (depth = num - 1; depth >= 0; depth--) {
574 X509 *cert = sk_X509_value(chain, depth);
575 X509 *issuer;
576 fr_pair_t *container;
577 unsigned int i;
578
579 if (!verify_applies(conf->verify.attribute_mode, depth, untrusted)) continue;
580
581 /*
582 * Already decoded, the pairs came back with a resumed session.
583 */
584 container = fr_pair_find_by_da_idx(&request->session_state_pairs, attr_tls_certificate, depth);
585 if (container && !fr_pair_list_empty(&container->vp_group)) continue;
586
587 /*
588 * Build out sufficient TLS-Certificate containers so the
589 * TLS-Certificate indexes match the chain depth.
590 */
591 for (i = fr_pair_count_by_da(&request->session_state_pairs, attr_tls_certificate);
592 i <= (unsigned int)depth;
593 i++) {
594 MEM(container = fr_pair_afrom_da(request->session_state_ctx, attr_tls_certificate));
595 fr_pair_append(&request->session_state_pairs, container);
596 }
597
598#ifdef STATIC_ANALYZER
599 /*
600 * Container can never be NULL, because if container
601 * was previously NULL, i will be <= depth.
602 */
603 if (!fr_cond_assert(container)) return -1;
604#endif
605
606 /*
607 * The issuer is the next certificate up the chain. The last
608 * certificate is its own issuer when it is self-issued, which
609 * is what OpenSSL reports as the current issuer when it calls
610 * the verify callback for that certificate.
611 */
612 if ((depth + 1) < num) {
613 issuer = sk_X509_value(chain, depth + 1);
614 } else if (X509_check_issued(cert, cert) == X509_V_OK) {
615 issuer = cert;
616 } else {
617 issuer = NULL;
618 }
619
620 /*
621 * If we fail to populate the cert attributes,
622 * trash all instances in the session-state list
623 * and cause validation to fail.
624 */
625 if (fr_tls_session_pairs_from_x509_cert(&container->vp_group, container,
626 request, cert, issuer, conf->verify.der_decode) < 0) {
627 fr_pair_delete_by_da(&request->session_state_pairs, attr_tls_certificate);
628 if (conf->verify.der_decode) {
629 fr_pair_delete_by_da(&request->session_state_pairs, attr_der_certificate);
630 }
631 fr_tls_session_error_add(request, FR_ERROR_VALUE_CERTIFICATE_ATTRIBUTES_FAILED);
632 return -1;
633 }
634
635 log_request_pair(L_DBG_LVL_2, request, NULL, container, "session-state.");
636 }
637
638 return 0;
639}
640DIAG_ON_OPTIONAL(used-but-marked-unused)
641
642/** Decode the chain, then push a `verify certificate { ... }` section
643 *
644 * tls_session_async_handshake_cont() calls the function once the handshake
645 * has paused, after the pushes for the session cache and `load psk` sections.
646 *
647 * @param[in] request The current request.
648 * @param[in] tls_session The current TLS session.
649 * @return
650 * - UNLANG_ACTION_CALCULATE_RESULT - Nothing to push, resume the handshake.
651 * - UNLANG_ACTION_PUSHED_CHILD - The section is running.
652 * - UNLANG_ACTION_FAIL - The section could not be pushed.
653 */
654unlang_action_t fr_tls_verify_cert_pending_push(request_t *request, fr_tls_session_t *tls_session)
655{
656 fr_tls_conf_t *conf = tls_session->conf;
657
658 if (tls_session->validate.state != FR_TLS_VALIDATION_REQUESTED) return UNLANG_ACTION_CALCULATE_RESULT;
659
660 /*
661 * A resumed session has no chain, its pairs came back with the session.
662 */
663 if (!tls_session->validate.resumed) {
664 RDEBUG2("(TLS) Decoding certificate chain");
665 if (tls_verify_chain_pairs_add(request, tls_session, conf) < 0) {
666 tls_session->validate.state = FR_TLS_VALIDATION_FAILED;
668 }
669 }
670
671 /*
672 * Pairs were all that was wanted.
673 */
674 if (!conf->verify_certificate || !tls_session->verify_peer_cert) {
675 tls_session->validate.state = FR_TLS_VALIDATION_SUCCESS;
677 }
678
679 RDEBUG2("(TLS) Requesting certificate validation");
680
681 return tls_verify_peer_cert_push(request, tls_session);
682}
683#endif /* WITH_TLS */
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:38
#define store(_store, _var)
static uint8_t request[4]
#define DIAG_OFF_OPTIONAL(_x)
Definition build.h:583
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:422
#define unlikely(_x)
Definition build.h:492
#define DIAG_ON_OPTIONAL(_x)
Definition build.h:584
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:177
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
Definition debug.h:248
#define MEM(x)
Definition debug.h:38
talloc_free(hp)
bool unlang_request_is_cancelled(request_t const *request)
Return whether a request has been cancelled.
Definition interpret.c:1997
HIDDEN fr_dict_attr_t const * attr_tls_certificate
Attribute definitions for lib curl.
Definition base.c:36
static fr_dict_attr_t const * attr_module_failure_message
Definition log.c:206
void log_request_pair(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_t const *vp, char const *prefix)
Print a fr_pair_t.
Definition log.c:790
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:460
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
Definition log.h:352
#define RDEBUG3(fmt,...)
Definition log.h:360
#define RINDENT()
Indent R* messages by one level.
Definition log.h:447
HIDDEN fr_dict_attr_t const * attr_tls_packet_type
HIDDEN fr_dict_attr_t const * attr_tls_session_resumed
fr_value_box_t const * enum_tls_packet_type_success
HIDDEN fr_dict_attr_t const * attr_der_certificate
fr_value_box_t const * enum_tls_packet_type_verify_certificate
HIDDEN fr_dict_attr_t const * attr_tls_certificate_chain_depth
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:68
@ L_DBG
Only displayed when debugging is enabled.
Definition log.h:56
unsigned int uint32_t
static size_t used
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Return the number of instances of a given da in the specified list.
Definition pair.c:693
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:716
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1306
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
Definition pair.c:1650
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
Definition pair.c:763
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:284
int fr_pair_steal_append(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *vp)
Change a vp's talloc ctx and insert it into a new list.
Definition pair.c:571
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:509
#define fr_assert(_expr)
Definition rad_assert.h:37
static bool done
Definition radclient.c:80
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG_ENABLED2()
Definition radclient.h:50
#define RDEBUG2(fmt,...)
Definition radclient.h:54
static rs_t * conf
Definition radsniff.c:52
#define pair_append_request(_attr, _da)
Allocate and append a fr_pair_t to the request list.
Definition pair.h:37
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
Definition pair_inline.c:93
static int fr_pair_find_or_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Definition pair.h:541