27RCSIDH(session_h,
"$Id: d15db050994c341c706ed6bec4c6db285fad7c3a $")
29#include "openssl_user_macros.h"
31#include <openssl/ssl.h>
32#include <openssl/err.h>
34typedef struct fr_tls_session_s fr_tls_session_t;
36#include <freeradius-devel/server/request.h>
37#include <freeradius-devel/util/dbuff.h>
74#define FR_TLS_MAX_PACKET_SIZE ((SSL3_RT_MAX_PACKET_SIZE + 255) & ~255)
89#define FR_TLS_MAX_ROUNDS 50U
118static inline void fr_tls_record_init(
fr_dbuff_t *record)
137static inline void fr_tls_record_drain(
fr_dbuff_t *record)
145 TLS_INFO_ORIGIN_RECORD_RECEIVED,
146 TLS_INFO_ORIGIN_RECORD_SENT
147} fr_tls_info_origin_t;
160 char info_description[256];
168 FR_TLS_RESULT_IN_PROGRESS = 0x00,
169 FR_TLS_RESULT_ERROR = 0x01,
170 FR_TLS_RESULT_SUCCESS = 0x02
173#ifdef PSK_MAX_IDENTITY_LEN
179 FR_TLS_PSK_REQUESTED,
189 fr_tls_psk_state_t state;
190 unsigned int max_psk_len;
209typedef enum CC_HINT(flag_enum) : uint64_t {
210 FR_TLS_PENDING_STATEFUL_TICKET = 0x01,
212 FR_TLS_PENDING_STATELESS_TICKET = 0x02,
214 FR_TLS_PENDING_PSK = 0x04,
215 FR_TLS_PENDING_VERIFY = 0x08
222#define TLS_PENDING_SET(_tls_session, _bit) ((_tls_session)->pending |= (_bit))
226#define TLS_PENDING_CLEAR(_tls_session, _bit) ((_tls_session)->pending &= ~(_bit))
236struct fr_tls_session_s {
244 SSL_SESSION *session;
245 fr_tls_result_t result;
250 fr_tls_bio_dbuff_t *into_ssl;
251 fr_tls_bio_dbuff_t *from_ssl;
294 fr_tls_ticket_stateful_t *cache;
296 fr_tls_pending_t pending;
299 fr_tls_verify_t validate;
301 fr_tls_ticket_stateless_state_t ticket;
304#ifdef PSK_MAX_IDENTITY_LEN
309 bool disallow_stateless_tickets;
312 bool allow_session_resumption;
313 bool verify_peer_cert;
318 bool write_encrypted;
322 bool seen_application_data;
325 bool init_finished_processed;
331 bool session_ticket_supported;
333 bool session_ticket_created;
342 bool session_ticket_received;
348 bool sent_commitment;
353 uint8_t pending_alert_description;
364static inline fr_tls_conf_t *fr_tls_session_conf(SSL *ssl)
366 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_CONF), fr_tls_conf_t);
374static inline fr_tls_session_t *fr_tls_session(SSL *ssl)
376 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_TLS_SESSION), fr_tls_session_t);
386static inline CC_HINT(
nonnull)
bool fr_tls_session_request_bound(SSL *ssl)
388 return (SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST) != NULL);
396static inline request_t *fr_tls_session_request(SSL
const *ssl)
402 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST),
request_t);
405static inline CC_HINT(
nonnull)
void _fr_tls_session_request_bind(
char const *file,
int line,
410 RDEBUG3(
"(TLS) %s[%d] - Binding SSL * (%p) to request (%p)", file,
line, ssl,
request);
415 old = SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST);
417 (void)talloc_get_type_abort(old,
request_t);
422 ret = SSL_set_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST,
request);
435 #define fr_tls_session_request_bind(_ssl, _request) _fr_tls_session_request_bind(__FILE__, __LINE__, _ssl, _request)
437static inline CC_HINT(
nonnull)
void _fr_tls_session_request_unbind(
char const *file,
int line, SSL *ssl)
448 RDEBUG3(
"(TLS) %s[%d] - Unbinding SSL * (%p) from request (%p)", file,
line, ssl,
request);
449 ret = SSL_set_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST, NULL);
461#define fr_tls_session_request_unbind(_ssl) _fr_tls_session_request_unbind(__FILE__, __LINE__, _ssl)
469void fr_tls_session_extra_pairs_copy_to_child(
request_t *child, fr_tls_session_t *tls_session)
472 MEM(
fr_pair_list_copy(child->request_ctx, &child->request_pairs, &tls_session->extra_pairs) >= 0);
482void fr_tls_session_extra_pair_add(fr_tls_session_t *tls_session,
fr_pair_t *
vp)
496void fr_tls_session_extra_pair_add_shallow(fr_tls_session_t *tls_session,
fr_pair_t *
vp)
512static inline CC_HINT(
nonnull)
size_t fr_tls_session_datagram_len(fr_tls_session_t *tls_session)
514 return fr_tls_bio_dbuff_datagram_len(tls_session->from_ssl);
524static inline CC_HINT(
nonnull)
void fr_tls_session_datagram_sent(fr_tls_session_t *tls_session)
526 fr_tls_bio_dbuff_datagram_sent(tls_session->from_ssl);
529int fr_tls_session_password_cb(
char *buf,
int num,
int rwflag,
void *userdata);
531unsigned int fr_tls_session_psk_client_cb(SSL *ssl,
UNUSED char const *hint,
532 char *identity,
unsigned int max_identity_len,
533 unsigned char *psk,
unsigned int max_psk_len);
535unsigned int fr_tls_session_psk_server_cb(SSL *ssl,
const char *identity,
536 unsigned char *psk,
unsigned int max_psk_len);
538#ifdef PSK_MAX_IDENTITY_LEN
542void fr_tls_session_info_cb(SSL
const *s,
int where,
int ret);
544void fr_tls_session_msg_cb(
int write_p,
int msg_version,
int content_type,
545 void const *buf,
size_t len, SSL *ssl,
void *arg);
547void fr_tls_session_keylog_cb(
const SSL *ssl,
const char *
line);
551 bool der_decode) CC_HINT(
nonnull(1,2,3,4));
555bool fr_tls_session_is_init_finished(fr_tls_session_t *tls_session);
561int fr_tls_session_ticket_write(
request_t *
request, fr_tls_session_t *tls_session);
565void fr_tls_session_error_alert(
request_t *
request, fr_tls_session_t *session,
568void fr_tls_session_close_send(
request_t *
request, fr_tls_session_t *session);
573fr_tls_session_t *fr_tls_session_alloc_client(TALLOC_CTX *ctx, SSL_CTX *ssl_ctx,
request_t *
request);
575fr_tls_session_t *fr_tls_session_alloc_server(TALLOC_CTX *ctx, SSL_CTX *ssl_ctx,
request_t *
request,
bool client_cert);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
static uint8_t request[4]
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
#define fr_dbuff_init(_out, _start, _len_or_end)
Initialise an dbuff for encoding or decoding.
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Stores an attribute, a value and various bits of other data.
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
Holds information necessary for binding or connecting to a socket.
static fr_sbuff_err_t char size_t * len