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: 4782712d1ff100ee32fd4b859e25a5461b03b2e5 $
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 switch (err) {
81 /*
82 * We linked the provided cert to at least one
83 * other in a chain, but the chain doesn't terminate
84 * in a root CA.
85 */
86 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
88
89 /*
90 * We failed to link the provided cert to any
91 * other local certificates in the chain.
92 */
93 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
94 RDEBUG2("(TLS) Static certificates in verification store are");
95 if (RDEBUG_ENABLED2) {
96#if OPENSSL_VERSION_NUMBER >= 0x30300000L
97 STACK_OF(X509_OBJECT) *objects = X509_STORE_get1_objects(store);
98
99 if (objects) {
100 RINDENT();
101 fr_tls_x509_objects_log(request, L_DBG, objects);
102 REXDENT();
103 sk_X509_OBJECT_pop_free(objects, X509_OBJECT_free);
104 }
105#else
106 RINDENT();
107 fr_tls_x509_objects_log(request, L_DBG, X509_STORE_get0_objects(store));
108 REXDENT();
109#endif
110 }
111 break;
112
113 default:
114 break;
115 }
116}
117
118/** Validates a certificate using custom logic
119 *
120 * Before trusting a certificate, we make sure that the certificate is
121 * 'valid'. There are several checks we perform to verify its validity.
122 *
123 * 1. Verify the certificate's signature, and verifying that the certificate has
124 * been issued by a trusted Certificate Authority (this is done for us by OpenSSL).
125 *
126 * 2. Verify that the certificate is valid for the present date (i.e. it is being
127 * presented within its validity dates).
128 *
129 * 3. Verify that the certificate has not been revoked by its issuing Certificate
130 * Authority, by checking with respect to a Certificate Revocation List (CRL).
131 *
132 * @note This callback will be called multiple times based on the depth of the root
133 * certificate chain.
134 *
135 * @note OpenSSL runs the handshake (including this callback) on a fibre with a
136 * limited stack (32 KB on OpenSSL releases without ASYNC_set_mem_functions()).
137 * Because of that limited stack, we need to perform all certificate decoding
138 * outside of the fibre on the main stack, i.e. after OpenSSL has yielded and
139 * the handshake has paused. See fr_tls_verify_cert_pending_push().
140 *
141 * @param ok preverify ok. 1 if true, 0 if false.
142 * @param x509_ctx containing certs to verify.
143 * @return
144 * - 0 if not valid.
145 * - 1 if valid.
146 */
147int fr_tls_verify_cert_cb(int ok, X509_STORE_CTX *x509_ctx)
148{
149 X509 *cert;
150
151 SSL_CTX *ssl_ctx;
152 SSL *ssl;
153 fr_tls_session_t *tls_session;
154 int err, depth;
155 fr_tls_conf_t *conf;
156 int my_ok = ok;
157 int untrusted;
158
160 fr_pair_t *depth_pair;
161
162 cert = X509_STORE_CTX_get_current_cert(x509_ctx);
163 err = X509_STORE_CTX_get_error(x509_ctx);
164 depth = X509_STORE_CTX_get_error_depth(x509_ctx);
165 untrusted = X509_STORE_CTX_get_num_untrusted(x509_ctx);
166
167 /*
168 * Retrieve the pointer to the SSL of the connection currently treated
169 * and the application specific data stored into the SSL object.
170 */
171 ssl = X509_STORE_CTX_get_ex_data(x509_ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
172 ssl_ctx = SSL_get_SSL_CTX(ssl);
173 conf = fr_tls_session_conf(ssl);
174 tls_session = talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_TLS_SESSION), fr_tls_session_t);
175 request = fr_tls_session_request(tls_session->ssl);
176
177 /*
178 * If this error appears it suggests
179 * that OpenSSL is trying to perform post-handshake
180 * certificate validation which we don't support.
181 */
182 if (!tls_session->can_pause) {
183 fr_assert_msg("Unexpected call to %s. "
184 "tls_session_async_handshake_cont must be in call stack", __FUNCTION__);
185 return 0;
186 }
187
188 /*
189 * Bail out as quickly as possible, producing
190 * as few errors as possible.
191 */
193 X509_STORE_CTX_set_error(x509_ctx, 0);
194 return 1;
195 }
196
197 /*
198 * Find or add the chain depth attribute and record the greatest depth we see + 1,
199 * as depth is zero based.
200 */
201 if (unlikely(fr_pair_find_or_append_by_da(request->session_state_ctx, &depth_pair, &request->session_state_pairs,
203 REDEBUG("(TLS) Failed to add certificate chain depth pair");
204 return 0;
205 }
206 if (depth_pair->vp_uint32 < ((uint32_t)depth) + 1) depth_pair->vp_uint32 = (uint32_t)depth + 1;
207
208 if (RDEBUG_ENABLED3) {
209 char subject[2048];
210 STACK_OF(X509) *our_chain;
211 int i;
212
213 our_chain = X509_STORE_CTX_get0_chain(x509_ctx);
214 RDEBUG3("(TLS) Certificate chain - %i cert(s) untrusted", untrusted);
215 for (i = sk_X509_num(our_chain); i > 0 ; i--) {
216 X509 *this_cert = sk_X509_value(our_chain, i - 1);
217
218 X509_NAME_oneline(X509_get_subject_name(this_cert), subject, sizeof(subject));
219 subject[sizeof(subject) - 1] = '\0';
220
221 RDEBUG3("(TLS) %s [%i] %s", this_cert == cert ? ">" : " ", i - 1, subject);
222 }
223 }
224
225 /*
226 * See if the user has disabled verification for
227 * this certificate. If they have, force verification
228 * to succeed.
229 */
230 if (!my_ok) {
231 char const *p = X509_verify_cert_error_string(err);
232 if (!verify_applies(conf->verify.mode, depth, untrusted)) {
233 RDEBUG2("(TLS) Ignoring verification error - %s (%i)", p, err);
234 tls_verify_error_detail(request, ssl_ctx, err);
235
236 my_ok = 1;
237 X509_STORE_CTX_set_error(x509_ctx, 0);
238 } else {
239 REDEBUG("(TLS) Verification error - %s (%i)", p, err);
240 fr_tls_session_error_add(request, FR_ERROR_VALUE_CERTIFICATE_VERIFY_FAILED);
241 tls_verify_error_detail(request, ssl_ctx, err);
242 goto done;
243 }
244 }
245
246done:
247 /*
248 * The chain is complete once OpenSSL reaches depth 0. Pause the handshake
249 * here so that fr_tls_verify_cert_pending_push() can decode the chain and run
250 * the `verify certificate` section on the main stack. Execution continues
251 * after the ASYNC_pause_job() call below once the section has run.
252 */
253 if (my_ok && (depth == 0)) {
254 bool want_pairs = conf->verify.attribute_mode != FR_TLS_VERIFY_MODE_DISABLED;
255 bool want_verify = conf->verify_certificate && tls_session->verify_peer_cert;
256
257 if (want_pairs || want_verify) {
258 fr_tls_verify_cert_request(tls_session, x509_ctx);
259
260 /*
261 * Be aware that if the request is cancelled
262 * whatever was meant to be done during the
263 * time we yielded may not have been completed.
264 */
265 ASYNC_pause_job();
266
267 /*
268 * Just try and bail out as quickly as possible.
269 */
271 X509_STORE_CTX_set_error(x509_ctx, 0);
272 fr_tls_verify_cert_reset(tls_session);
273 return 1;
274 }
275
276 /*
277 * If we couldn't decode the chain, or the
278 * `verify certificate` section rejected it,
279 * then validation overall fails.
280 */
281 if (!fr_tls_verify_cert_result(tls_session)) {
282 REDEBUG("(TLS) Certificate validation failed");
283 my_ok = 0;
284 X509_STORE_CTX_set_error(x509_ctx, X509_V_ERR_APPLICATION_VERIFICATION);
285 }
286 }
287 }
288
289 tls_session->peer_cert_ok = (my_ok > 0);
290 RDEBUG2("(TLS) [verify] = %s", my_ok ? "ok" : "invalid");
291
292 return my_ok;
293}
294DIAG_ON_OPTIONAL(used-but-marked-unused)
295
296/** Revalidates the client's certificate chain
297 *
298 * Wraps the fr_tls_verify_cert_cb callback, allowing us to use the same
299 * validation logic whenever we need to.
300 *
301 * @note Only use so far is forcing the chain to be re-validated on session
302 * resumption.
303 *
304 * @return
305 * - 1 if the chain could be validated.
306 * - 0 if the chain failed validation.
307 */
308int fr_tls_verify_cert_chain(request_t *request, SSL *ssl)
309{
310 int err;
311 int verify;
312 int ret = 1;
313
314 SSL_CTX *ssl_ctx;
315 STACK_OF(X509) *chain;
316 X509 *cert;
317 X509_STORE *store;
318 X509_STORE_CTX *store_ctx;
319
320 /*
321 * If there's no client certificate, we just return OK.
322 */
323 cert = SSL_get0_peer_certificate(ssl); /* Does not increase ref count */
324 if (!cert) return 1;
325
326 ssl_ctx = SSL_get_SSL_CTX(ssl);
327 store_ctx = X509_STORE_CTX_new();
328 if (unlikely(store_ctx == NULL)) {
329 REDEBUG("(TLS) Failed allocating X509_STORE_CTX");
330 return 0;
331 }
332
333 chain = SSL_get_peer_cert_chain(ssl); /* Does not increase ref count */
334 store = SSL_CTX_get_ex_data(ssl_ctx, FR_TLS_EX_CTX_INDEX_VERIFY_STORE); /* Gets the verification store */
335
336 /*
337 * This sets up a store_ctx for doing peer certificate verification.
338 *
339 * store_ctx - Is the ctx to initialise
340 * store - Is an X509_STORE of implicitly
341 * trusted certificates. Here we're using
342 * the verify store that was created when we
343 * allocated the SSL_CTX.
344 * cert - Is the certificate to validate.
345 * chain - Is any other certificates the peer provided
346 * us in order to build a chain from a trusted
347 * root or intermediary to its leaf (cert).
348 *
349 * Note: SSL_CTX_get_cert_store() returns the ctx->cert_store, which
350 * is not the same as the verification cert store.
351 */
352 if (unlikely(X509_STORE_CTX_init(store_ctx, store, cert, chain) != 1)) {
353 REDEBUG("(TLS) Failed initialising X509_STORE_CTX");
354 X509_STORE_CTX_free(store_ctx);
355 return 0;
356 }
357
358 X509_STORE_CTX_set_ex_data(store_ctx, SSL_get_ex_data_X509_STORE_CTX_idx(), ssl);
359 X509_STORE_CTX_set_verify_cb(store_ctx, fr_tls_verify_cert_cb);
360
361 verify = X509_verify_cert(store_ctx);
362 if (verify != 1) {
363 err = X509_STORE_CTX_get_error(store_ctx);
364
365 if (err != X509_V_OK) {
366 REDEBUG("(TLS) Failed re-validating resumed session: %s", X509_verify_cert_error_string(err));
367 fr_tls_session_error_add(request, FR_ERROR_VALUE_CERTIFICATE_REVALIDATION_FAILED);
368 ret = 0;
369 }
370 }
371
372 X509_STORE_CTX_free(store_ctx);
373
374 return ret;
375}
376
377/** Process the result of `verify certificate { ... }`
378 *
379 */
380static unlang_action_t tls_verify_peer_cert_result(request_t *request, void *uctx)
381{
382 fr_tls_session_t *tls_session = talloc_get_type_abort(uctx, fr_tls_session_t);
383 fr_pair_t *vp, *next;
384
385 fr_assert(tls_session->validate.state == FR_TLS_VALIDATION_REQUESTED);
386
387 vp = fr_pair_find_by_da(&request->reply_pairs, NULL, attr_tls_packet_type);
388 if (!vp || (vp->vp_uint32 != enum_tls_packet_type_success->vb_uint32)) {
389 REDEBUG("(TLS) Failed (re-)validating certificates");
390 fr_tls_session_error_add(request->parent, FR_ERROR_VALUE_VERIFY_CERTIFICATE_FAILED);
391
392 /*
393 * Hoist any instances of Module-Failure-Message from the subrequest
394 * so they can be used for logging failures.
395 */
397 while (vp && request->parent) {
399 fr_pair_remove(&request->request_pairs, vp);
400 fr_pair_steal_append(request->parent->request_ctx, &request->parent->request_pairs, vp);
401 vp = next;
402 }
403
404 tls_session->validate.state = FR_TLS_VALIDATION_FAILED;
406 }
407
408 tls_session->validate.state = FR_TLS_VALIDATION_SUCCESS;
409
410 RDEBUG2("(TLS) Certificates (re-)validated");
411
413}
414
415/** Push a `verify certificate { ... }` call into the current request, using a subrequest
416 *
417 * @param[in] request The current request.
418 * @param[in] tls_session The current TLS session.
419 * @return
420 * - UNLANG_ACTION_CALCULATE_RESULT on noop.
421 * - UNLANG_ACTION_PUSHED_CHILD on success.
422 * - UNLANG_ACTION_FAIL on failure.
423 */
424static unlang_action_t tls_verify_peer_cert_push(request_t *request, fr_tls_session_t *tls_session)
425{
426 fr_tls_conf_t *conf = tls_session->conf;
427 request_t *child;
428 fr_pair_t *vp;
430
431 fr_assert(conf->virtual_server);
432
433 MEM(child = tls_subrequest_alloc(request, enum_tls_packet_type_verify_certificate->vb_uint32,
434 &tls_session->session_id));
435 request = child;
436
437 /*
438 * Add extra pairs to the subrequest
439 */
440 fr_tls_session_extra_pairs_copy_to_child(child, tls_session);
441
442 /*
443 * Copy certificate pairs to the child session state
444 */
445 vp = NULL;
446 while ((vp = fr_pair_find_by_da(&request->parent->session_state_pairs, vp, attr_tls_certificate))) {
447 fr_pair_append(&request->session_state_pairs, fr_pair_copy(request->session_state_ctx, vp));
448 }
449 if (conf->verify.der_decode) {
450 while ((vp = fr_pair_find_by_da(&request->parent->session_state_pairs, vp, attr_der_certificate))) {
451 fr_pair_append(&request->session_state_pairs, fr_pair_copy(request->session_state_ctx, vp));
452 }
453 }
454
456 vp->vp_bool = tls_session->validate.resumed;
457
458 /*
459 * Allocate a child, and set it up to call
460 * the TLS virtual server.
461 */
462 ua = fr_tls_call_push(child, tls_verify_peer_cert_result, conf, tls_session, false);
463 if (ua == UNLANG_ACTION_FAIL) {
464 REDEBUG("(TLS) Failed calling TLS virtual server");
465 talloc_free(child);
466 return UNLANG_ACTION_FAIL;
467 }
468
469 return ua;
470}
471
472/** Clear any previous validation result
473 *
474 * Should be called by the validation requestor to get the result and reset
475 * the validation state.
476 *
477 * @return
478 * - true if the certificate chain was validated.
479 * - false if the certificate chain failed validation.
480 */
481bool fr_tls_verify_cert_result(fr_tls_session_t *tls_session)
482{
483 bool result;
484
485 fr_assert(tls_session->validate.state != FR_TLS_VALIDATION_INIT);
486
487 result = tls_session->validate.state == FR_TLS_VALIDATION_SUCCESS;
488
489 tls_session->validate.state = FR_TLS_VALIDATION_INIT;
490 tls_session->validate.resumed = false;
491
492 return result;
493}
494
495/** Reset the verification state
496 *
497 */
498void fr_tls_verify_cert_reset(fr_tls_session_t *tls_session)
499{
500 tls_session->validate.state = FR_TLS_VALIDATION_INIT;
501 tls_session->validate.resumed = false;
502 tls_session->validate.x509_ctx = NULL;
503}
504
505/** Request validation of the chain OpenSSL is verifying
506 *
507 * Called by fr_tls_verify_cert_cb() before it pauses the handshake.
508 *
509 * @param[in] tls_session The current TLS session.
510 * @param[in] x509_ctx holding the chain. Only valid while the
511 * handshake is paused inside the callback.
512 */
513void fr_tls_verify_cert_request(fr_tls_session_t *tls_session, X509_STORE_CTX *x509_ctx)
514{
515 fr_assert(tls_session->validate.state == FR_TLS_VALIDATION_INIT);
516
517 tls_session->validate.state = FR_TLS_VALIDATION_REQUESTED;
518 TLS_PENDING_SET(tls_session, FR_TLS_PENDING_VERIFY);
519 tls_session->validate.resumed = false;
520 tls_session->validate.x509_ctx = x509_ctx;
521}
522
523/** Request re-validation of the certificate pairs restored with a resumed session
524 *
525 * Called by the session cache code before it pauses the handshake. A resumed
526 * session has no chain to decode, the `TLS-Certificate` pairs came back with
527 * the session.
528 *
529 * @param[in] tls_session The current TLS session.
530 */
531void fr_tls_verify_resumed_request(fr_tls_session_t *tls_session)
532{
533 fr_assert(tls_session->validate.state == FR_TLS_VALIDATION_INIT);
534
535 tls_session->validate.state = FR_TLS_VALIDATION_REQUESTED;
536 TLS_PENDING_SET(tls_session, FR_TLS_PENDING_VERIFY);
537 tls_session->validate.resumed = true;
538 tls_session->validate.x509_ctx = NULL;
539}
540
541DIAG_OFF_OPTIONAL(used-but-marked-unused) /* fix spurious warnings for sk macros */
542/** Decode the chain OpenSSL is verifying into `session-state.TLS-Certificate` pairs
543 *
544 * Runs on the request's own stack while the handshake is paused in
545 * fr_tls_verify_cert_cb(). The certificate at depth 0 is the peer's, and
546 * `TLS-Certificate[n]` holds the certificate at depth n.
547 *
548 * @param[in] request The current request.
549 * @param[in] tls_session The current TLS session.
550 * @param[in] conf The TLS configuration.
551 * @return
552 * - 0 on success.
553 * - -1 if a certificate could not be decoded. No `TLS-Certificate`
554 * pairs remain in the session-state list.
555 */
556static int tls_verify_chain_pairs_add(request_t *request, fr_tls_session_t *tls_session, fr_tls_conf_t const *conf)
557{
558 X509_STORE_CTX *x509_ctx = tls_session->validate.x509_ctx;
559 STACK_OF(X509) *chain = X509_STORE_CTX_get0_chain(x509_ctx);
560 int untrusted = X509_STORE_CTX_get_num_untrusted(x509_ctx);
561 int num = sk_X509_num(chain);
562 int depth;
563
564 /*
565 * Deepest first, so each DER decoded certificate is prepended ahead
566 * of its issuer and `DER-Certificate[0]` is the peer's.
567 */
568 for (depth = num - 1; depth >= 0; depth--) {
569 X509 *cert = sk_X509_value(chain, depth);
570 X509 *issuer;
571 fr_pair_t *container;
572 unsigned int i;
573
574 if (!verify_applies(conf->verify.attribute_mode, depth, untrusted)) continue;
575
576 /*
577 * Already decoded, the pairs came back with a resumed session.
578 */
579 container = fr_pair_find_by_da_idx(&request->session_state_pairs, attr_tls_certificate, depth);
580 if (container && !fr_pair_list_empty(&container->vp_group)) continue;
581
582 /*
583 * Build out sufficient TLS-Certificate containers so the
584 * TLS-Certificate indexes match the chain depth.
585 */
586 for (i = fr_pair_count_by_da(&request->session_state_pairs, attr_tls_certificate);
587 i <= (unsigned int)depth;
588 i++) {
589 MEM(container = fr_pair_afrom_da(request->session_state_ctx, attr_tls_certificate));
590 fr_pair_append(&request->session_state_pairs, container);
591 }
592
593#ifdef STATIC_ANALYZER
594 /*
595 * Container can never be NULL, because if container
596 * was previously NULL, i will be <= depth.
597 */
598 if (!fr_cond_assert(container)) return -1;
599#endif
600
601 /*
602 * The issuer is the next certificate up the chain. The last
603 * certificate is its own issuer when it is self-issued, which
604 * is what OpenSSL reports as the current issuer when it calls
605 * the verify callback for that certificate.
606 */
607 if ((depth + 1) < num) {
608 issuer = sk_X509_value(chain, depth + 1);
609 } else if (X509_check_issued(cert, cert) == X509_V_OK) {
610 issuer = cert;
611 } else {
612 issuer = NULL;
613 }
614
615 /*
616 * If we fail to populate the cert attributes,
617 * trash all instances in the session-state list
618 * and cause validation to fail.
619 */
620 if (fr_tls_session_pairs_from_x509_cert(&container->vp_group, container,
621 request, cert, issuer, conf->verify.der_decode) < 0) {
622 fr_pair_delete_by_da(&request->session_state_pairs, attr_tls_certificate);
623 if (conf->verify.der_decode) {
624 fr_pair_delete_by_da(&request->session_state_pairs, attr_der_certificate);
625 }
626 fr_tls_session_error_add(request, FR_ERROR_VALUE_CERTIFICATE_ATTRIBUTES_FAILED);
627 return -1;
628 }
629
630 log_request_pair(L_DBG_LVL_2, request, NULL, container, "session-state.");
631 }
632
633 return 0;
634}
635DIAG_ON_OPTIONAL(used-but-marked-unused)
636
637/** Decode the chain, then push a `verify certificate { ... }` section
638 *
639 * tls_session_async_handshake_cont() calls the function once the handshake
640 * has paused, after the pushes for the session cache and `load psk` sections.
641 *
642 * @param[in] request The current request.
643 * @param[in] tls_session The current TLS session.
644 * @return
645 * - UNLANG_ACTION_CALCULATE_RESULT - Nothing to push, resume the handshake.
646 * - UNLANG_ACTION_PUSHED_CHILD - The section is running.
647 * - UNLANG_ACTION_FAIL - The section could not be pushed.
648 */
649unlang_action_t fr_tls_verify_cert_pending_push(request_t *request, fr_tls_session_t *tls_session)
650{
651 fr_tls_conf_t *conf = tls_session->conf;
652
653 if (tls_session->validate.state != FR_TLS_VALIDATION_REQUESTED) return UNLANG_ACTION_CALCULATE_RESULT;
654
655 /*
656 * A resumed session has no chain, its pairs came back with the session.
657 */
658 if (!tls_session->validate.resumed) {
659 RDEBUG2("(TLS) Decoding certificate chain");
660 if (tls_verify_chain_pairs_add(request, tls_session, conf) < 0) {
661 tls_session->validate.state = FR_TLS_VALIDATION_FAILED;
663 }
664 }
665
666 /*
667 * Pairs were all that was wanted.
668 */
669 if (!conf->verify_certificate || !tls_session->verify_peer_cert) {
670 tls_session->validate.state = FR_TLS_VALIDATION_SUCCESS;
672 }
673
674 RDEBUG2("(TLS) Requesting certificate validation");
675
676 return tls_verify_peer_cert_push(request, tls_session);
677}
678#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:577
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:422
#define unlikely(_x)
Definition build.h:486
#define DIAG_ON_OPTIONAL(_x)
Definition build.h:578
#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:1985
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
#define REDEBUG(fmt,...)
#define RDEBUG_ENABLED2()
#define RDEBUG2(fmt,...)
static bool done
Definition radclient.c:80
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