27RCSIDH(session_h,
"$Id: ee1042d64b3026e0fd14ae089dd1104398ca435c $")
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
117static inline void fr_tls_record_init(
fr_dbuff_t *record)
134static inline void fr_tls_record_drain(
fr_dbuff_t *record)
142 TLS_INFO_ORIGIN_RECORD_RECEIVED,
143 TLS_INFO_ORIGIN_RECORD_SENT
144} fr_tls_info_origin_t;
157 char info_description[256];
165 FR_TLS_RESULT_IN_PROGRESS = 0x00,
166 FR_TLS_RESULT_ERROR = 0x01,
167 FR_TLS_RESULT_SUCCESS = 0x02
170#ifdef PSK_MAX_IDENTITY_LEN
176 FR_TLS_PSK_REQUESTED,
186 fr_tls_psk_state_t state;
187 unsigned int max_psk_len;
206typedef enum CC_HINT(flag_enum) : uint64_t {
207 FR_TLS_PENDING_STATEFUL_TICKET = 0x01,
209 FR_TLS_PENDING_STATELESS_TICKET = 0x02,
211 FR_TLS_PENDING_PSK = 0x04,
212 FR_TLS_PENDING_VERIFY = 0x08
219#define TLS_PENDING_SET(_tls_session, _bit) ((_tls_session)->pending |= (_bit))
223#define TLS_PENDING_CLEAR(_tls_session, _bit) ((_tls_session)->pending &= ~(_bit))
233struct fr_tls_session_s {
241 SSL_SESSION *session;
242 fr_tls_result_t result;
247 fr_tls_bio_dbuff_t *into_ssl;
248 fr_tls_bio_dbuff_t *from_ssl;
280 fr_tls_ticket_stateful_t *cache;
281 bool allow_session_resumption;
282 bool verify_peer_cert;
285 fr_tls_pending_t pending;
288 fr_tls_verify_t validate;
290 fr_tls_ticket_stateless_state_t ticket;
293#ifdef PSK_MAX_IDENTITY_LEN
300 bool write_encrypted;
304 bool seen_application_data;
307 bool session_ticket_supported;
309 bool session_ticket_created;
312 bool session_ticket_received;
318 bool sent_commitment;
323 uint8_t pending_alert_description;
334static inline fr_tls_conf_t *fr_tls_session_conf(SSL *ssl)
336 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_CONF), fr_tls_conf_t);
344static inline fr_tls_session_t *fr_tls_session(SSL *ssl)
346 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_TLS_SESSION), fr_tls_session_t);
356static inline CC_HINT(
nonnull)
bool fr_tls_session_request_bound(SSL *ssl)
358 return (SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST) != NULL);
366static inline request_t *fr_tls_session_request(SSL
const *ssl)
372 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST),
request_t);
375static inline CC_HINT(
nonnull)
void _fr_tls_session_request_bind(
char const *file,
int line,
380 RDEBUG3(
"(TLS) %s[%d] - Binding SSL * (%p) to request (%p)", file,
line, ssl,
request);
385 old = SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST);
387 (void)talloc_get_type_abort(old,
request_t);
392 ret = SSL_set_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST,
request);
405 #define fr_tls_session_request_bind(_ssl, _request) _fr_tls_session_request_bind(__FILE__, __LINE__, _ssl, _request)
407static inline CC_HINT(
nonnull)
void _fr_tls_session_request_unbind(
char const *file,
int line, SSL *ssl)
418 RDEBUG3(
"(TLS) %s[%d] - Unbinding SSL * (%p) from request (%p)", file,
line, ssl,
request);
419 ret = SSL_set_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST, NULL);
431#define fr_tls_session_request_unbind(_ssl) _fr_tls_session_request_unbind(__FILE__, __LINE__, _ssl)
439void fr_tls_session_extra_pairs_copy_to_child(
request_t *child, fr_tls_session_t *tls_session)
442 MEM(
fr_pair_list_copy(child->request_ctx, &child->request_pairs, &tls_session->extra_pairs) >= 0);
452void fr_tls_session_extra_pair_add(fr_tls_session_t *tls_session,
fr_pair_t *
vp)
466void fr_tls_session_extra_pair_add_shallow(fr_tls_session_t *tls_session,
fr_pair_t *
vp)
482static inline CC_HINT(
nonnull)
size_t fr_tls_session_datagram_len(fr_tls_session_t *tls_session)
484 return fr_tls_bio_dbuff_datagram_len(tls_session->from_ssl);
494static inline CC_HINT(
nonnull)
void fr_tls_session_datagram_sent(fr_tls_session_t *tls_session)
496 fr_tls_bio_dbuff_datagram_sent(tls_session->from_ssl);
499int fr_tls_session_password_cb(
char *buf,
int num,
int rwflag,
void *userdata);
501unsigned int fr_tls_session_psk_client_cb(SSL *ssl,
UNUSED char const *hint,
502 char *identity,
unsigned int max_identity_len,
503 unsigned char *psk,
unsigned int max_psk_len);
505unsigned int fr_tls_session_psk_server_cb(SSL *ssl,
const char *identity,
506 unsigned char *psk,
unsigned int max_psk_len);
508#ifdef PSK_MAX_IDENTITY_LEN
512void fr_tls_session_info_cb(SSL
const *s,
int where,
int ret);
514void fr_tls_session_msg_cb(
int write_p,
int msg_version,
int content_type,
515 void const *buf,
size_t len, SSL *ssl,
void *arg);
517void fr_tls_session_keylog_cb(
const SSL *ssl,
const char *
line);
521 bool der_decode) CC_HINT(
nonnull(1,2,3,4));
525bool fr_tls_session_is_init_finished(fr_tls_session_t *tls_session);
533void fr_tls_session_error_alert(
request_t *
request, fr_tls_session_t *session,
536void fr_tls_session_close_send(
request_t *
request, fr_tls_session_t *session);
541fr_tls_session_t *fr_tls_session_alloc_client(TALLOC_CTX *ctx, SSL_CTX *ssl_ctx,
request_t *
request);
543fr_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