The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
pairs.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: 710308f4f8ce0ba960f153cd5ab66abeaf5a5387 $
19 *
20 * @file tls/pairs.c
21 * @brief Functions to convert certificate OIDs to attribute pairs
22 *
23 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 */
25RCSID("$Id: 710308f4f8ce0ba960f153cd5ab66abeaf5a5387 $")
26USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */
27
28#ifdef WITH_TLS
29#define LOG_PREFIX "tls"
30
31#include <freeradius-devel/tls/openssl_user_macros.h>
32#include <freeradius-devel/util/pair.h>
33#include <freeradius-devel/server/request.h>
34#include <freeradius-devel/server/pair.h>
35#include <freeradius-devel/der/der.h>
36
37#include "attrs.h"
38#include "bio.h"
39#include "log.h"
40#include "session.h"
41#include "utils.h"
42
43#include <openssl/x509v3.h>
44#include <openssl/ssl.h>
45#include <openssl/ocsp.h>
46
47DIAG_OFF_OPTIONAL(used-but-marked-unused) /* fix spurious warnings for sk macros */
48/** Extract session pairs from the Subject Alternate Name extension
49 *
50 */
51static bool tls_session_pairs_from_san(fr_pair_list_t *pair_list, TALLOC_CTX *ctx, request_t *request, X509_EXTENSION *ext)
52{
53 GENERAL_NAMES *names = NULL;
54 int i;
56
57 if (!(names = X509V3_EXT_d2i(ext))) return false;
58
59 for (i = 0; i < sk_GENERAL_NAME_num(names); i++) {
60 GENERAL_NAME *name = sk_GENERAL_NAME_value(names, i);
61
62 switch (name->type) {
63#ifdef GEN_EMAIL
64 case GEN_EMAIL:
68 (char const *)ASN1_STRING_get0_data(name->d.rfc822Name),
69 ASN1_STRING_length(name->d.rfc822Name), true) == 0);
70 break;
71#endif /* GEN_EMAIL */
72#ifdef GEN_DNS
73 case GEN_DNS:
77 (char const *)ASN1_STRING_get0_data(name->d.dNSName),
78 ASN1_STRING_length(name->d.dNSName), true) == 0);
79 break;
80#endif /* GEN_DNS */
81#ifdef GEN_OTHERNAME
82 case GEN_OTHERNAME:
83 /* look for a MS UPN */
84 if (NID_ms_upn != OBJ_obj2nid(name->d.otherName->type_id)) break;
85
86 /* we've got a UPN - Must be ASN1-encoded UTF8 string */
87 if (name->d.otherName->value->type == V_ASN1_UTF8STRING) {
91 (char const *)ASN1_STRING_get0_data(name->d.otherName->value->value.utf8string),
92 ASN1_STRING_length(name->d.otherName->value->value.utf8string),
93 true) == 0);
94 break;
95 }
96 RWARN("Invalid UPN in Subject Alt Name (should be UTF-8)");
97 break;
98#endif /* GEN_OTHERNAME */
99 default:
100 /* XXX TODO handle other SAN types */
101 break;
102 }
103 }
104 if (names != NULL) GENERAL_NAMES_free(names);
105
106 return true;
107}
108
109/** Extract session pairs from the X509v3-CRL-Distribution-Points extension
110 *
111 */
112static bool tls_session_pairs_from_crl(fr_pair_list_t *pair_list, TALLOC_CTX *ctx, UNUSED request_t *request, X509_EXTENSION *ext)
113{
114 ASN1_STRING *s = X509_EXTENSION_get_data(ext);
115 char unsigned const *data = ASN1_STRING_get0_data(s);
116 STACK_OF(DIST_POINT) *dps;
117 DIST_POINT *dp;
118 STACK_OF(GENERAL_NAME) *names;
119 GENERAL_NAME *name;
120 fr_pair_t *vp;
121 int i, j;
122
123 if (!(dps = d2i_CRL_DIST_POINTS(NULL, &data, ASN1_STRING_length(s)))) return false;
124
125 for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
126 dp = sk_DIST_POINT_value(dps, i);
127
128 /*
129 * RFC 5280 Section 4.2.1.13 says that the distpoint is optional.
130 */
131 if (!dp->distpoint) {
132 CRL_DIST_POINTS_free(dps);
133 return false;
134 }
135
136 names = dp->distpoint->name.fullname;
137
138 /*
139 * We only want CRL distribution points that cover all reasons,
140 * so ignore any where reasons are set.
141 */
142 if (dp->reasons) continue;
143
144 for (j = 0; j < sk_GENERAL_NAME_num(names); j++) {
145 name = sk_GENERAL_NAME_value(names, j);
146
147 if (name->type != GEN_URI) continue;
151 (char const *)ASN1_STRING_get0_data(name->d.uniformResourceIdentifier),
152 true) == 0);
153 }
154 }
155
156 CRL_DIST_POINTS_free(dps);
157
158 return true;
159}
160
161/** Extract session pairs from the Authority Key Identifier extension - specifically OCSP URI
162 *
163 */
164static bool tls_session_pairs_from_aia(fr_pair_list_t *pair_list, TALLOC_CTX *ctx, UNUSED request_t *request, X509_EXTENSION *ext)
165{
166 ASN1_STRING *s = X509_EXTENSION_get_data(ext);
167 char unsigned const *data = ASN1_STRING_get0_data(s);
168 fr_pair_t *vp;
169 AUTHORITY_INFO_ACCESS *aia;
170 ACCESS_DESCRIPTION *ad;
171 char *host = NULL, *path = NULL;
172 int i, port, is_https;
173
174 if (!(aia = d2i_AUTHORITY_INFO_ACCESS(NULL, &data, ASN1_STRING_length(s)))) return false;
175
176 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(aia); i++) {
177 ad = sk_ACCESS_DESCRIPTION_value(aia, i);
178 if (OBJ_obj2nid(ad->method) != NID_ad_OCSP) continue;
179 if (ad->location->type != GEN_URI) continue;
180
181 /*
182 * Use OpenSSL URL parsing to check that the URL is valid
183 */
184 if (OSSL_HTTP_parse_url((char *) ad->location->d.ia5->data, &is_https, NULL, &host,
185 NULL, &port, &path, NULL, NULL)){
186 OPENSSL_free(host);
187 OPENSSL_free(path);
191 (char const *)ad->location->d.ia5->data,
192 true) == 0);
193 }
194 }
195 AUTHORITY_INFO_ACCESS_free(aia);
196
197 return true;
198}
199
200/** Extract attributes from an X509 certificate
201 *
202 * @param[out] pair_list to copy attributes to.
203 * @param[in] ctx to allocate attributes in.
204 * @param[in] request the current request.
205 * @param[in] cert to validate.
206 * @param[in] issuer of the certificate.
207 * @param[in] der_decode should the certificate be parsed with the DER decoder.
208 * @return
209 * - 1 already exists.
210 * - 0 on success.
211 * - < 0 on failure.
212 */
213int fr_tls_session_pairs_from_x509_cert(fr_pair_list_t *pair_list, TALLOC_CTX *ctx, request_t *request, X509 *cert,
214 X509 *issuer,
215#if OPENSSL_VERSION_NUMBER >= 0x30400000L
216 bool der_decode
217#else
218 UNUSED bool der_decode
219#endif
220 )
221{
222 int loc;
223 char buff[1024];
224
225 ASN1_TIME const *asn_time;
226 time_t time;
227
228 STACK_OF(X509_EXTENSION) const *ext_list = NULL;
229
230 fr_pair_t *vp = NULL;
231 ssize_t slen;
232 bool san_found = false, crl_found = false, aia_found = false;
233
234 /*
235 * We require OpenSSL >= 3.4 to call the DER decoder due to the stack size
236 * needed to handle the recursive calls involved in certificate decoding.
237 */
238#if OPENSSL_VERSION_NUMBER >= 0x30400000L
239 if (der_decode) {
240 uint8_t *cert_der;
241 uint8_t *cd;
242 int der_len;
243 fr_der_decode_ctx_t der_ctx;
244 fr_pair_list_t tmp_list;
245
246 der_len = i2d_X509(cert, NULL);
247 if (der_len < 0) {
248 fr_tls_log_perror(request, "Failed retrieving certificate");
249 return -1;
250 }
251 der_ctx = (fr_der_decode_ctx_t) {
252 .tmp_ctx = talloc_new(ctx),
253 .root = attr_der_certificate,
254 };
255 cert_der = cd = talloc_array(der_ctx.tmp_ctx, uint8_t, der_len);
256 i2d_X509(cert, &cd);
257 fr_pair_list_init(&tmp_list);
258 slen = fr_der_decode_pair_dbuff(request->session_state_ctx, &tmp_list,
259 attr_der_certificate, &FR_DBUFF_TMP(cert_der, (size_t)der_len), &der_ctx);
260 talloc_free(der_ctx.tmp_ctx);
261 if (slen < 0) {
262 fr_tls_log_perror(request, "Failed decoding certificate");
263 fr_pair_list_free(&tmp_list);
264 return -1;
265 }
266 /*
267 * Certificates are decoded in CA .. intermediate .. client sequence
268 * so, prepend each decoded one to get the client cert first.
269 */
270 fr_pair_list_prepend(&request->session_state_pairs, &tmp_list);
271 }
272#endif
273
274 /*
275 * Subject
276 */
278 if (unlikely(X509_NAME_print_ex(fr_tls_bio_dbuff_thread_local(vp, 256, 0),
279 X509_get_subject_name(cert), 0, XN_FLAG_ONELINE) < 0)) {
280 fr_tls_bio_dbuff_thread_local_clear();
281 fr_tls_log_perror(request, "Failed retrieving certificate subject");
282 error:
284 return -1;
285 }
286 fr_pair_value_bstrdup_buffer_shallow(vp, fr_tls_bio_dbuff_thread_local_finalise_bstr(), true);
287
288 RDEBUG3("(TLS) Creating attributes for \"%pV\":", fr_box_strvalue_buffer(vp->vp_strvalue));
289
290 /*
291 * Common name
292 */
293 slen = X509_NAME_get_text_by_NID(X509_get_subject_name(cert),
294 NID_commonName, NULL, 0);
295 if (slen > 0) {
296 char *cn;
297
299 MEM(fr_pair_value_bstr_alloc(vp, &cn, (size_t)slen, true) == 0); /* Allocs \0 byte in addition to len */
300
301 slen = X509_NAME_get_text_by_NID(X509_get_subject_name(cert), NID_commonName, cn, (size_t)slen + 1);
302 if (slen < 0) {
303 fr_tls_log_perror(request, "Failed retrieving certificate common name");
304 goto error;
305 }
306 }
307
308 /*
309 * Signature
310 */
311 {
312 ASN1_BIT_STRING const *sig;
313 X509_ALGOR const *alg;
314
315 X509_get0_signature(&sig, &alg, cert);
316
319 (uint8_t const *)ASN1_STRING_get0_data(sig),
320 ASN1_STRING_length(sig), true) == 0);
321
322 OBJ_obj2txt(buff, sizeof(buff), alg->algorithm, 0);
325 }
326
327 /*
328 * Issuer
329 */
331 if (unlikely(X509_NAME_print_ex(fr_tls_bio_dbuff_thread_local(vp, 256, 0),
332 X509_get_issuer_name(cert), 0, XN_FLAG_ONELINE) < 0)) {
333 fr_tls_bio_dbuff_thread_local_clear();
334 fr_tls_log_perror(request, "Failed retrieving certificate issuer");
335 goto error;
336 }
337 fr_pair_value_bstrdup_buffer_shallow(vp, fr_tls_bio_dbuff_thread_local_finalise_bstr(), true);
338
339 /*
340 * Serial number
341 */
342 {
343 ASN1_INTEGER const *serial = NULL;
344 unsigned char *der;
345 int len;
346
347 serial = X509_get0_serialNumber(cert);
348 if (!serial) {
349 fr_tls_log_perror(request, "Failed retrieving certificate serial");
350 goto error;
351 }
352
353 len = i2d_ASN1_INTEGER(serial, NULL); /* get length */
355 MEM(fr_pair_value_mem_alloc(vp, &der, len, false) == 0);
356 i2d_ASN1_INTEGER(serial, &der);
357 }
358
359 /*
360 * Not valid before
361 */
362 asn_time = X509_get0_notBefore(cert);
363
364 if (fr_tls_utils_asn1time_to_epoch(&time, asn_time) < 0) {
365 RPWDEBUG("(TLS) Failed parsing certificate not-before");
366 goto error;
367 }
368
370 vp->vp_date = fr_unix_time_from_time(time);
371
372 /*
373 * Not valid after
374 */
375 asn_time = X509_get0_notAfter(cert);
376
377 if (fr_tls_utils_asn1time_to_epoch(&time, asn_time) < 0) {
378 RPWDEBUG("(TLS) Failed parsing certificate not-after");
379 goto error;
380 }
381
383 vp->vp_date = fr_unix_time_from_time(time);
384
385 /*
386 * Get the RFC822 Subject Alternative Name
387 */
388 loc = X509_get_ext_by_NID(cert, NID_subject_alt_name, 0);
389 if (loc >= 0) {
390 X509_EXTENSION *ext = X509_get_ext(cert, loc);
391 if (ext) san_found = tls_session_pairs_from_san(pair_list, ctx, request, ext);
392 }
393
394 loc = X509_get_ext_by_NID(cert, NID_crl_distribution_points, 0);
395 if (loc >= 0) {
396 X509_EXTENSION *ext = X509_get_ext(cert, loc);
397 if (ext) crl_found = tls_session_pairs_from_crl(pair_list, ctx, request, ext);
398 }
399
400 if (issuer) {
401 OCSP_CERTID *certid;
402 int len;
403 uint8_t *ocsp_certid = NULL;
404
405 certid = OCSP_cert_to_id(NULL, cert, issuer);
406 if (unlikely(!certid)) goto error;
407 len = i2d_OCSP_CERTID(certid, &ocsp_certid);
408 if (len < 0) goto error;
409 if (ocsp_certid != NULL) {
411 fr_value_box_memdup(vp, &vp->data, NULL, ocsp_certid, len, false);
412 OPENSSL_free(ocsp_certid);
413 }
414 OCSP_CERTID_free(certid);
415 }
416
417 /*
418 * Only add extensions for the actual client certificate
419 */
420 ext_list = X509_get0_extensions(cert);
421 if (unlikely(!ext_list)) {
422 RWDEBUG("(TLS) Failed retrieving extensions");
423 goto done;
424 }
425
426 /*
427 * Grab the X509 extensions, and create attributes out of them.
428 * For laziness, we reuse the OpenSSL names
429 */
430 if (sk_X509_EXTENSION_num(ext_list) > 0) {
431 int i;
432 BIO *bio;
433 fr_tls_bio_dbuff_t *bd;
434 fr_dbuff_t *in, *out;
435
436 bio = fr_tls_bio_dbuff_alloc(&bd, NULL, NULL, 257, 4097, true);
437 in = fr_tls_bio_dbuff_in(bd);
438 out = fr_tls_bio_dbuff_out(bd);
439
440 for (i = 0; i < sk_X509_EXTENSION_num(ext_list); i++) {
441 ASN1_OBJECT *obj;
442 X509_EXTENSION *ext;
443 fr_dict_attr_t const *da;
444 char *p;
445
446 ext = sk_X509_EXTENSION_value(ext_list, i);
447
448 obj = X509_EXTENSION_get_object(ext);
449
450 /*
451 * If this is extension is Subject Alternate Name have we already
452 * handled it? If not, do that now.
453 *
454 * Some certificate encodings have been observed where the SAN extension
455 * was not found by X509_get_ext_by_NID() but then seen when the list
456 * of extensions is handled here.
457 */
458 if (OBJ_obj2nid(obj) == NID_subject_alt_name) {
459 if (!san_found) san_found = tls_session_pairs_from_san(pair_list, ctx, request, ext);
460 goto again;
461 }
462
463 if (OBJ_obj2nid(obj) == NID_crl_distribution_points) {
464 if (!crl_found) crl_found = tls_session_pairs_from_crl(pair_list, ctx, request, ext);
465 goto again;
466 }
467
468 if (OBJ_obj2nid(obj) == NID_info_access) {
469 if (!aia_found) aia_found = tls_session_pairs_from_aia(pair_list, ctx, request, ext);
470 goto again;
471 }
472
473 if (i2a_ASN1_OBJECT(bio, obj) <= 0) {
474 RPWDEBUG("(TLS) Skipping X509 Extension (%i) conversion to attribute. "
475 "Conversion from ASN1 failed...", i);
476 again:
477 fr_tls_bio_dbuff_reset(bd);
478 continue;
479 }
480
481 if (fr_dbuff_remaining(out) == 0) goto again; /* Nothing written ? */
482
483 /*
484 * All disallowed chars get mashed to '-'
485 */
486 for (p = (char *)fr_dbuff_current(out);
487 p < (char *)fr_dbuff_end(out);
488 p++) if (!fr_dict_attr_allowed_chars[(uint8_t)*p]) *p = '-';
489
490 /*
491 * Terminate the buffer (after char replacement,
492 * so we do don't replace the \0)
493 */
494 if (unlikely(fr_dbuff_in_bytes(in, (uint8_t)'\0') <= 0)) {
495 RWDEBUG("(TLS) Attribute name too long");
496 goto again;
497 }
498
500
501 fr_dbuff_set(in, fr_dbuff_current(in) - 1); /* Ensure the \0 isn't counted in remaining */
502
503 if (!da) {
504 RWDEBUG3("(TLS) Skipping attribute \"%pV\": "
505 "Add a dictionary definition if you want to access it",
508 fr_strerror_clear(); /* Don't leave spurious errors from failed resolution */
509 goto again;
510 }
511
512 fr_tls_bio_dbuff_reset(bd); /* 'free' any data used */
513
514 if (X509V3_EXT_print(bio, ext, X509V3_EXT_PARSE_UNKNOWN, 0) != 1) {
515 REDEBUG("(TLS) Failed extracting data for \"%s\"", da->name);
516 goto again;
517 }
518
519 MEM(vp = fr_pair_afrom_da(ctx, da));
521 NULL, true) < 0) {
522 RPWDEBUG3("Skipping: %s += \"%pV\"",
523 da->name, fr_box_strvalue_len((char *)fr_dbuff_current(out),
526 goto again;
527 }
528 fr_tls_bio_dbuff_reset(bd); /* 'free' any data used */
529
531 }
532 talloc_free(bd);
533 }
534
535done:
536 return 0;
537}
538
539/** Extract values from ClientHello extensions into pairs
540 *
541 * @param request being processed.
542 * @param container List to put pairs in.
543 * @param extension data to parse.
544 * @param hlen Length of "length" header in extension.
545 * @param dlen Length of each data entry in extension.
546 * @param total_len of extension.
547 * @param da Attribute to create using extension values.
548 * @return
549 * - 0 on success
550 * - -1 on failure
551 */
552static int fr_tls_extension_decode(request_t *request, fr_pair_t *container, uint8_t const *extension,
553 size_t hlen, size_t dlen, size_t total_len, fr_dict_attr_t const *da)
554{
555 size_t i,extension_len;
556 uint8_t const *data;
557
558 fr_assert((hlen == 1) || (hlen == 2));
559 fr_assert((dlen == 1) || (dlen == 2));
560
561 if (total_len < hlen) {
562 REDEBUG("(TLS) Missing length in %s extension", da->name);
563 return -1;
564 }
565
566 if (hlen == 1) {
567 extension_len = extension[0];
568 } else {
569 extension_len = (extension[0] << 8) + extension[1];
570 }
571 fr_assert(da->type == ((dlen == 1) ? FR_TYPE_UINT8 : FR_TYPE_UINT16));
572
573 if (extension_len + hlen > total_len) {
574 REDEBUG("(TLS) Invalid length %zu in %s extension", extension_len, da->name);
575 return -1;
576 }
577
578 data = extension + hlen;
579
580 for (i = 0; i < extension_len; i += dlen) {
581 fr_pair_t *vp;
582
583 MEM(fr_pair_append_by_da(container, &vp, &container->vp_group, da) >= 0);
584
585 switch (dlen) {
586 case 1:
587 vp->vp_uint8= data[0];
588 break;
589
590 case 2:
591 vp->vp_uint16 = (data[0] << 8) + data[1];
592 break;
593 }
594
595 data += dlen;
596 }
597
598 return 0;
599}
600
601/** Callback to extract pairs from a Client Hello
602 *
603 */
604int fr_tls_session_client_hello_pairs(SSL *ssl, request_t *request)
605{
606 request_t *parent = request->parent;
607 uint8_t const *ciphers, *extension;
608 int i, *extensions = NULL;
609 size_t data_size, j;
610 STACK_OF(SSL_CIPHER) *sk;
611 SSL_CIPHER const *cipher;
612 STACK_OF(SSL_CIPHER) *scsvs;
613 fr_pair_t *container, *vp;
614
616
617 container = fr_pair_find_by_da(&parent->session_state_pairs, NULL, attr_tls_client_hello);
618 if (container) return SSL_CLIENT_HELLO_SUCCESS;
619
620 MEM(container = fr_pair_afrom_da(parent->session_state_ctx, attr_tls_client_hello));
621
622 data_size = SSL_client_hello_get0_ciphers(ssl, &ciphers);
623 if (SSL_bytes_to_cipher_list(ssl, ciphers, data_size, SSL_client_hello_isv2(ssl), &sk, &scsvs) == 0) {
624 RPEDEBUG("(TLS) Failed to decode cipher list");
625 fail:
626 if (extensions) OPENSSL_free(extensions);
627 talloc_free(container);
628 return SSL_CLIENT_HELLO_ERROR;
629 }
630
631 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
632 fr_pair_append_by_da(container, &vp, &container->vp_group, attr_tls_client_hello_cipher);
633 cipher = sk_SSL_CIPHER_value(sk, i);
634 fr_value_box_strdup(vp, &vp->data, NULL, SSL_CIPHER_get_name(cipher), false);
635 }
636
637 sk_SSL_CIPHER_free(sk);
638 sk_SSL_CIPHER_free(scsvs);
639
640 /*
641 * Fetch the extensions and decode the ones we know about
642 * These are the ones which are returned as simple lists
643 * of values of known length which map to enum attributes.
644 */
645 if (SSL_client_hello_get1_extensions_present(ssl, &extensions, &data_size) == 0) {
646 RPEDEBUG("(TLS) Failed to fetch client hello extensions");
647 goto fail;
648 }
649
650 for (j = 0; j < data_size; j++) {
651 size_t total_len;
652
653 if (SSL_client_hello_get0_ext(ssl, extensions[j], &extension, &total_len) == 0) {
654 RPDEBUG("Failed getting client hello extension %d", extensions[j]);
655 goto fail;
656 }
657
658 switch (extensions[j]) {
659 case TLSEXT_TYPE_supported_groups: /* length[2] + 2*data */
660 if (fr_tls_extension_decode(request, container, extension, 2, 2, total_len,
662 break;
663
664 case TLSEXT_TYPE_ec_point_formats: /* length[1] + data */
665 if (fr_tls_extension_decode(request, container, extension, 1, 1, total_len,
667 break;
668
669 case TLSEXT_TYPE_signature_algorithms: /* length[2] + 2*data */
670 if (fr_tls_extension_decode(request, container, extension, 2, 2, total_len,
671 attr_tls_client_hello_sig_algo) < 0) goto fail;
672 break;
673
674 case TLSEXT_TYPE_supported_versions: /* length[1] + 2*data */
675 if (fr_tls_extension_decode(request, container, extension, 1, 2, total_len,
676 attr_tls_client_hello_tls_version) < 0) goto fail;
677 break;
678
679 case TLSEXT_TYPE_psk_kex_modes: /* length[1] + data */
680 if (fr_tls_extension_decode(request, container, extension, 1, 1, total_len,
682 break;
683 }
684 }
685
686 if (extensions) OPENSSL_free(extensions);
687
688 /*
689 * This is the version being negotiated by the client, but tops at 1.2.
690 * After that the supported_versions extension is where the real value is.
691 */
692 fr_pair_append_by_da(container, &vp, &container->vp_group, attr_tls_client_hello_tls_version);
693 vp->vp_uint16 = SSL_client_hello_get0_legacy_version(ssl);
694
695 fr_pair_append(&parent->session_state_pairs, container);
696
697 return SSL_CLIENT_HELLO_SUCCESS;
698}
699DIAG_ON_OPTIONAL(used-but-marked-unused)
700#endif
static uint8_t request[4]
#define USES_APPLE_DEPRECATED_API
Definition build.h:590
#define RCSID(id)
Definition build.h:603
#define DIAG_OFF_OPTIONAL(_x)
Definition build.h:577
#define unlikely(_x)
Definition build.h:486
#define UNUSED
Definition build.h:415
#define DIAG_ON_OPTIONAL(_x)
Definition build.h:578
#define fr_dbuff_current(_dbuff_or_marker)
Return the 'current' position of a dbuff or marker.
Definition dbuff.h:963
#define fr_dbuff_set(_dst, _src)
Set the 'current' position in a dbuff or marker using another dbuff or marker, a char pointer,...
Definition dbuff.h:1056
#define fr_dbuff_end(_dbuff_or_marker)
Return the current 'end' position of a dbuff or marker.
Definition dbuff.h:990
#define fr_dbuff_remaining(_dbuff_or_marker)
Return the number of bytes remaining between the dbuff or marker and the end of the buffer.
Definition dbuff.h:795
#define fr_dbuff_in_bytes(_dbuff_or_marker,...)
Copy a byte sequence into a dbuff or marker.
Definition dbuff.h:1518
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
Definition dbuff.h:556
#define MEM(x)
Definition debug.h:38
TALLOC_CTX * tmp_ctx
ctx under which temporary data will be allocated
Definition der.h:143
bool const fr_dict_attr_allowed_chars[SBUFF_CHAR_CLASS]
Characters allowed in a single dictionary attribute name.
Definition dict_util.c:54
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
Definition dict_util.c:3600
talloc_free(hp)
HIDDEN fr_dict_attr_t const * attr_tls_certificate
Attribute definitions for lib curl.
Definition base.c:36
#define RWDEBUG(fmt,...)
Definition log.h:378
#define RDEBUG3(fmt,...)
Definition log.h:360
#define RWARN(fmt,...)
Definition log.h:314
#define RPDEBUG(fmt,...)
Definition log.h:363
#define RPEDEBUG(fmt,...)
Definition log.h:393
#define RPWDEBUG3(fmt,...)
Definition log.h:385
#define RPWDEBUG(fmt,...)
Definition log.h:383
#define RWDEBUG3(fmt,...)
Definition log.h:380
HIDDEN fr_dict_attr_t const * attr_tls_certificate_subject
HIDDEN fr_dict_attr_t const * attr_tls_client_hello
HIDDEN fr_dict_attr_t const * attr_tls_client_hello_psk_key_mode
HIDDEN fr_dict_attr_t const * attr_tls_certificate_serial
HIDDEN fr_dict_attr_t const * attr_tls_certificate_subject_alt_name_dns
HIDDEN fr_dict_attr_t const * attr_tls_client_hello_supported_group
HIDDEN fr_dict_attr_t const * attr_tls_certificate_not_after
HIDDEN fr_dict_attr_t const * attr_tls_certificate_not_before
HIDDEN fr_dict_attr_t const * attr_tls_certificate_signature_algorithm
HIDDEN fr_dict_attr_t const * attr_tls_certificate_subject_alt_name_upn
HIDDEN fr_dict_attr_t const * attr_tls_client_hello_sig_algo
HIDDEN fr_dict_attr_t const * attr_tls_certificate_ocsp_uri
HIDDEN fr_dict_attr_t const * attr_tls_certificate_common_name
HIDDEN fr_dict_attr_t const * attr_tls_certificate_ocsp_cert_id
HIDDEN fr_dict_attr_t const * attr_tls_certificate_issuer
HIDDEN fr_dict_attr_t const * attr_tls_certificate_x509v3_crl_distribution_points
HIDDEN fr_dict_attr_t const * attr_tls_client_hello_ec_point_format
HIDDEN fr_dict_attr_t const * attr_der_certificate
HIDDEN fr_dict_attr_t const * attr_tls_certificate_signature
HIDDEN fr_dict_attr_t const * attr_tls_client_hello_tls_version
HIDDEN fr_dict_attr_t const * attr_tls_client_hello_cipher
HIDDEN fr_dict_attr_t const * attr_tls_certificate_subject_alt_name_email
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
long int ssize_t
unsigned char uint8_t
static size_t used
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and append)
Definition pair.c:1416
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
Definition pair.c:2897
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition pair.c:2598
int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a string to a "string" type value pair.
Definition pair.c:2818
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
Definition pair.c:2552
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:707
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:1297
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
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:47
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
Definition pair.c:2747
int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "string" type value pair.
Definition pair.c:2694
int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "octets" type value pair.
Definition pair.c:2846
ssize_t fr_der_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, fr_dbuff_t *in, fr_der_decode_ctx_t *decode_ctx)
Definition decode.c:2649
#define fr_assert(_expr)
Definition rad_assert.h:37
#define REDEBUG(fmt,...)
static bool done
Definition radclient.c:80
static char const * name
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:37
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
static const char * names[8]
Definition time.c:614
static fr_unix_time_t fr_unix_time_from_time(time_t time)
Convert a time_t into out internal fr_unix_time_t.
Definition time.h:536
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src)
Move a list of fr_pair_t from a temporary list to the head of a destination list.
static fr_slen_t parent
Definition pair.h:864
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
Definition strerror.c:581
int fr_tls_utils_asn1time_to_epoch(time_t *out, ASN1_TIME const *asn1)
Convert OpenSSL's ASN1_TIME to an epoch time.
Definition utils.c:115
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
Definition value.c:4702
int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted)
Copy a buffer to a fr_value_box_t.
Definition value.c:5194
static fr_sbuff_err_t char size_t fr_sbuff_t * in
Definition value.h:1061
#define fr_box_strvalue_buffer(_val)
Definition value.h:343
static fr_slen_t data
Definition value.h:1366
#define fr_box_strvalue_len(_val, _len)
Definition value.h:340
static fr_sbuff_err_t char ** out
Definition value.h:1061
static fr_sbuff_err_t char size_t * len
Definition value.h:1061