The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
ticket.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17#ifdef WITH_TLS
18/**
19 * $Id: a0ada249ea67c7970c652e15b04e544955772ddf $
20 *
21 * @file lib/tls/ticket.h
22 * @brief Session resumption, stateful and stateless
23 *
24 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 * @copyright 2026 Network RADIUS SAS (legal@networkradius.com)
26 */
27RCSIDH(ticket_h, "$Id: a0ada249ea67c7970c652e15b04e544955772ddf $")
28
29#include "openssl_user_macros.h"
30
31#include <openssl/ssl.h>
32#include <openssl/err.h>
33
34#include "ticket_stateful.h"
35#include "ticket_stateless.h"
36
37#ifdef _TLS_PRIVATE
38/** Is any cache operation still waiting to run?
39 *
40 * The TLS library pushes one cache operation per call, but pushing a
41 * clear will (eventually) cancel any pending load or store. Return
42 * whether there is a pending operation queued.
43 *
44 * @param[in] tls_cache to check, which may be NULL when caching is disabled.
45 * @return
46 * - true if at least one operation is queued.
47 * - false if there is nothing left to do.
48 */
49static inline bool fr_tls_ticket_stateful_pending(fr_tls_ticket_stateful_t const *tls_cache)
50{
51 if (!tls_cache) return false;
52
53 return (tls_cache->load.state == FR_TLS_TICKET_STATEFUL_REQUESTED) ||
54 (tls_cache->clear.state == FR_TLS_TICKET_STATEFUL_REQUESTED) ||
55 (tls_cache->store.state == FR_TLS_TICKET_STATEFUL_REQUESTED);
56}
57#endif
58
59/*
60 * The types above are what session.h needs. The prototypes below need
61 * the types that conf.h and session.h define.
62 */
63#include "conf.h"
64#include "session.h"
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/** Cache the session now that the application has decided it's OK.
71 *
72 * Just finishing the TLS handshake is not always enough. EAP runs
73 * inner methods inside of the TLS tunnel, and those methods can fail.
74 * The cache operations are marked as pending during the handshake.
75 * Calling this function tells the TLS state machine to actually store
76 * the session.
77 *
78 * All queued cache operations run before this returns. An
79 * application MUST either call this function, or
80 * fr_tls_session_fail_session(). Skipping these functions means that
81 * either a good session isn't cached, or a bad session isn't cleared.
82 * The TLS peer might then be able to resume the session.
83 *
84 * We don't allow applications to call any cache fail function. That
85 * is instead handled by fr_tls_session_fail_session(). That function
86 * both calls `fail session`, and then (if needed) `clear session`.
87 */
88unlang_action_t fr_tls_ticket_stateful_store_session(request_t *request, fr_tls_session_t *tls_session);
89
90unlang_action_t fr_tls_ticket_issue(request_t *request, fr_tls_session_t *tls_session);
91
92unlang_action_t fr_tls_ticket_stateless_issue(unlang_result_t *p_result, request_t *request, fr_tls_session_t *tls_session,
93 unlang_function_with_result_t resume, void *uctx);
94
95/*
96 * The only public function is fr_tls_ticket_stateful_store_session(),
97 * which is needed for EAP. Other applications MUST instead call
98 * the various fr_session_*() functions.
99 */
100#ifdef _TLS_PRIVATE
101/*
102 * ticket.c, shared by both kinds of resumption.
103 */
104void tls_session_id_cache(fr_tls_session_t *tls_session, SSL_SESSION *sess);
105
106request_t *tls_subrequest_alloc(request_t *parent, uint32_t packet_type, fr_value_box_t const *id);
107
108int tls_ticket_id_to_box(TALLOC_CTX *ctx, fr_value_box_t *out, SSL_SESSION *sess);
109
110int tls_ticket_app_data_set(request_t *request, SSL_SESSION *sess, fr_value_box_t const *session_id);
111
112int tls_ticket_app_data_get(request_t *request, SSL_SESSION *sess, fr_value_box_t const *session_id);
113
114fr_time_delta_t tls_ticket_session_lifetime(request_t *request, fr_value_box_t const *session_id,
115 fr_tls_conf_t const *conf, SSL_SESSION *sess);
116
117bool tls_ticket_session_resumable(request_t *request, fr_value_box_t const *session_id,
118 fr_tls_conf_t const *conf, SSL_SESSION *sess);
119
120int fr_tls_ticket_disable_cb(SSL *ssl, int is_forward_secure);
121
122int fr_tls_ticket_ctx_init(SSL_CTX *ctx, fr_tls_ticket_conf_t const *cache_conf, bool client);
123
124/*
125 * ticket_stateful.c
126 */
127unlang_action_t fr_tls_ticket_stateful_clear_session(request_t *request, fr_tls_session_t *tls_session);
128
129unlang_action_t fr_tls_ticket_stateful_discard_session(request_t *request, fr_tls_session_t *tls_session);
130
131void fr_tls_ticket_stateful_session_alloc(fr_tls_session_t *tls_session);
132
133unlang_action_t fr_tls_ticket_stateful_load_client_push(request_t *request, fr_tls_session_t *tls_session);
134
135unlang_action_t fr_tls_ticket_stateful_pending_push(request_t *request, fr_tls_session_t *tls_session);
136
137void fr_tls_ticket_stateful_disable(SSL_CTX *ctx);
138
139void fr_tls_ticket_stateful_ctx_init(SSL_CTX *ctx, fr_tls_ticket_conf_t const *cache_conf, bool client);
140
141/*
142 * ticket_stateless.c
143 */
144unlang_action_t fr_tls_ticket_stateless_pending_push(request_t *request, fr_tls_session_t *tls_session);
145
146unlang_action_t tls_ticket_stateless_issue_push(request_t *request, fr_tls_session_t *tls_session,
147 unlang_function_with_result_t resume, void *uctx);
148
149void fr_tls_ticket_stateless_disable(SSL_CTX *ctx, bool stateful);
150
151int fr_tls_ticket_stateless_ctx_init(SSL_CTX *ctx, fr_tls_ticket_conf_t const *cache_conf);
152#endif
153
154#ifdef __cplusplus
155}
156#endif
157#endif /* WITH_TLS */
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
static uint8_t request[4]
#define RCSIDH(h, id)
Definition build.h:604
unlang_action_t(* unlang_function_with_result_t)(unlang_result_t *p_result, request_t *request, void *uctx)
A generic function pushed by a module or xlat to functions deeper in the C call stack to create resum...
Definition function.h:55
unsigned int uint32_t
static rs_t * conf
Definition radsniff.c:52
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
static fr_slen_t parent
Definition pair.h:864
static fr_sbuff_err_t char ** out
Definition value.h:1061