26 RCSIDH(session_h,
"$Id: 4b1802f45a969e61cfb2497a33906139f27a79cd $")
28 #include "openssl_user_macros.h"
30 #include <openssl/ssl.h>
31 #include <openssl/err.h>
33 typedef struct fr_tls_session_s fr_tls_session_t;
35 #include <freeradius-devel/server/request.h>
60 #define FR_TLS_MAX_RECORD_SIZE 16384
72 TLS_INFO_ORIGIN_RECORD_RECEIVED,
73 TLS_INFO_ORIGIN_RECORD_SENT
74 } fr_tls_info_origin_t;
84 char info_description[256];
94 FR_TLS_RESULT_IN_PROGRESS = 0x00,
95 FR_TLS_RESULT_ERROR = 0x01,
96 FR_TLS_RESULT_SUCCESS = 0x02
106 struct fr_tls_session_s {
109 SSL_SESSION *session;
110 fr_tls_result_t result;
115 fr_tls_record_t clean_in;
116 fr_tls_record_t clean_out;
117 fr_tls_record_t dirty_in;
118 fr_tls_record_t dirty_out;
121 void (*record_init)(fr_tls_record_t *buf);
122 void (*record_close)(fr_tls_record_t *buf);
123 unsigned int (*record_from_buff)(fr_tls_record_t *buf,
void const *ptr,
unsigned int size);
124 unsigned int (*record_to_buff)(fr_tls_record_t *buf,
void *ptr,
unsigned int size);
130 fr_tls_cache_t *cache;
131 bool allow_session_resumption;
132 bool verify_client_cert;
134 fr_tls_verify_t validate;
145 uint8_t pending_alert_description;
156 static inline fr_tls_conf_t *fr_tls_session_conf(SSL *ssl)
158 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_CONF), fr_tls_conf_t);
166 static inline fr_tls_session_t *fr_tls_session(SSL *ssl)
168 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_TLS_SESSION), fr_tls_session_t);
178 static inline CC_HINT(
nonnull)
bool fr_tls_session_request_bound(SSL *ssl)
180 return (SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST) != NULL);
188 static inline request_t *fr_tls_session_request(SSL
const *ssl)
190 return talloc_get_type_abort(SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST),
request_t);
193 static inline CC_HINT(
nonnull)
void _fr_tls_session_request_bind(
char const *
file,
int line,
198 RDEBUG3(
"%s[%u] - Binding SSL * (%p) to request (%p)",
file,
line, ssl, request);
203 old = SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST);
205 (void)talloc_get_type_abort(ssl,
request_t);
210 ret = SSL_set_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST, request);
223 #define fr_tls_session_request_bind(_ssl, _request) _fr_tls_session_request_bind(__FILE__, __LINE__, _ssl, _request)
225 static inline CC_HINT(
nonnull)
void _fr_tls_session_request_unbind(
char const *
file,
int line, SSL *ssl)
227 request_t *request = fr_tls_session_request(ssl);
231 (void)talloc_get_type_abort(request,
request_t);
234 RDEBUG3(
"%s[%u] - Unbinding SSL * (%p) from request (%p)",
file,
line, ssl, request);
235 ret = SSL_set_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST, NULL);
247 #define fr_tls_session_request_unbind(_ssl) _fr_tls_session_request_unbind(__FILE__, __LINE__, _ssl)
255 void fr_tls_session_extra_pairs_copy_to_child(
request_t *child, fr_tls_session_t *tls_session)
258 MEM(
fr_pair_list_copy(child->request_ctx, &child->request_pairs, &tls_session->extra_pairs) >= 0);
268 void fr_tls_session_extra_pair_add(fr_tls_session_t *tls_session,
fr_pair_t *
vp)
282 void fr_tls_session_extra_pair_add_shallow(fr_tls_session_t *tls_session,
fr_pair_t *
vp)
289 int fr_tls_session_password_cb(
char *buf,
int num,
int rwflag,
void *userdata);
291 unsigned int fr_tls_session_psk_client_cb(SSL *ssl,
UNUSED char const *hint,
292 char *identity,
unsigned int max_identity_len,
293 unsigned char *psk,
unsigned int max_psk_len);
295 unsigned int fr_tls_session_psk_server_cb(SSL *ssl,
const char *identity,
296 unsigned char *psk,
unsigned int max_psk_len);
298 void fr_tls_session_info_cb(SSL
const *s,
int where,
int ret);
300 void fr_tls_session_msg_cb(
int write_p,
int msg_version,
int content_type,
301 void const *buf,
size_t len, SSL *ssl,
void *arg);
303 void fr_tls_session_keylog_cb(
const SSL *ssl,
const char *
line);
308 int fr_tls_session_recv(
request_t *request, fr_tls_session_t *tls_session);
310 int fr_tls_session_send(
request_t *request, fr_tls_session_t *tls_session);
312 int fr_tls_session_alert(
request_t *request, fr_tls_session_t *tls_session,
uint8_t level,
uint8_t description);
316 fr_tls_session_t *fr_tls_session_alloc_client(TALLOC_CTX *ctx, SSL_CTX *ssl_ctx);
318 fr_tls_session_t *fr_tls_session_alloc_server(TALLOC_CTX *ctx, SSL_CTX *ssl_ctx,
request_t *request,
size_t dynamic_mtu,
bool client_cert);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
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.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
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.