Coverage Report

Created: 2026-05-20 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/ssl/statem/extensions_cust.c
Line
Count
Source
1
/*
2
 * Copyright 2014-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/* Custom extension utility functions */
11
12
#include <openssl/ct.h>
13
#include "../ssl_local.h"
14
#include "internal/cryptlib.h"
15
#include "internal/ssl_unwrap.h"
16
#include "statem_local.h"
17
18
typedef struct {
19
    void *add_arg;
20
    custom_ext_add_cb add_cb;
21
    custom_ext_free_cb free_cb;
22
} custom_ext_add_cb_wrap;
23
24
typedef struct {
25
    void *parse_arg;
26
    custom_ext_parse_cb parse_cb;
27
} custom_ext_parse_cb_wrap;
28
29
/*
30
 * Provide thin wrapper callbacks which convert new style arguments to old style
31
 */
32
static int custom_ext_add_old_cb_wrap(SSL *s, unsigned int ext_type,
33
    unsigned int context,
34
    const unsigned char **out,
35
    size_t *outlen, X509 *x, size_t chainidx,
36
    int *al, void *add_arg)
37
0
{
38
0
    custom_ext_add_cb_wrap *add_cb_wrap = (custom_ext_add_cb_wrap *)add_arg;
39
40
0
    if (add_cb_wrap->add_cb == NULL)
41
0
        return 1;
42
43
0
    return add_cb_wrap->add_cb(s, ext_type, out, outlen, al,
44
0
        add_cb_wrap->add_arg);
45
0
}
46
47
static void custom_ext_free_old_cb_wrap(SSL *s, unsigned int ext_type,
48
    unsigned int context,
49
    const unsigned char *out, void *add_arg)
50
0
{
51
0
    custom_ext_add_cb_wrap *add_cb_wrap = (custom_ext_add_cb_wrap *)add_arg;
52
53
0
    if (add_cb_wrap->free_cb == NULL)
54
0
        return;
55
56
0
    add_cb_wrap->free_cb(s, ext_type, out, add_cb_wrap->add_arg);
57
0
}
58
59
static int custom_ext_parse_old_cb_wrap(SSL *s, unsigned int ext_type,
60
    unsigned int context,
61
    const unsigned char *in,
62
    size_t inlen, X509 *x, size_t chainidx,
63
    int *al, void *parse_arg)
64
0
{
65
0
    custom_ext_parse_cb_wrap *parse_cb_wrap = (custom_ext_parse_cb_wrap *)parse_arg;
66
67
0
    if (parse_cb_wrap->parse_cb == NULL)
68
0
        return 1;
69
70
0
    return parse_cb_wrap->parse_cb(s, ext_type, in, inlen, al,
71
0
        parse_cb_wrap->parse_arg);
72
0
}
73
74
/*
75
 * Find a custom extension from the list. The |role| param is there to
76
 * support the legacy API where custom extensions for client and server could
77
 * be set independently on the same SSL_CTX. It is set to ENDPOINT_SERVER if we
78
 * are trying to find a method relevant to the server, ENDPOINT_CLIENT for the
79
 * client, or ENDPOINT_BOTH for either
80
 */
81
custom_ext_method *custom_ext_find(const custom_ext_methods *exts,
82
    ENDPOINT role, unsigned int ext_type,
83
    size_t *idx)
84
0
{
85
0
    size_t i;
86
0
    custom_ext_method *meth = exts->meths;
87
88
0
    for (i = 0; i < exts->meths_count; i++, meth++) {
89
0
        if (ext_type == meth->ext_type
90
0
            && (role == ENDPOINT_BOTH || role == meth->role
91
0
                || meth->role == ENDPOINT_BOTH)) {
92
0
            if (idx != NULL)
93
0
                *idx = i;
94
0
            return meth;
95
0
        }
96
0
    }
97
0
    return NULL;
98
0
}
99
100
/*
101
 * Initialise custom extensions flags to indicate neither sent nor received.
102
 */
103
void custom_ext_init(custom_ext_methods *exts)
104
0
{
105
0
    size_t i;
106
0
    custom_ext_method *meth = exts->meths;
107
108
0
    for (i = 0; i < exts->meths_count; i++, meth++)
109
0
        meth->ext_flags = 0;
110
0
}
111
112
/* Pass received custom extension data to the application for parsing. */
113
int custom_ext_parse(SSL_CONNECTION *s, unsigned int context,
114
    unsigned int ext_type,
115
    const unsigned char *ext_data, size_t ext_size, X509 *x,
116
    size_t chainidx)
117
0
{
118
0
    int al = 0;
119
0
    custom_ext_methods *exts = &s->cert->custext;
120
0
    custom_ext_method *meth;
121
0
    ENDPOINT role = ENDPOINT_BOTH;
122
123
0
    if ((context & (SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO)) != 0)
124
0
        role = s->server ? ENDPOINT_SERVER : ENDPOINT_CLIENT;
125
126
0
    meth = custom_ext_find(exts, role, ext_type, NULL);
127
    /* If not found return success */
128
0
    if (!meth)
129
0
        return 1;
130
131
    /* Check if extension is defined for our protocol. If not, skip */
132
0
    if (!extension_is_relevant(s, meth->context, context))
133
0
        return 1;
134
135
0
    if ((context & (SSL_EXT_TLS1_2_SERVER_HELLO | SSL_EXT_TLS1_3_SERVER_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS)) != 0) {
136
        /*
137
         * If it's ServerHello or EncryptedExtensions we can't have any
138
         * extensions not sent in ClientHello.
139
         */
140
0
        if ((meth->ext_flags & SSL_EXT_FLAG_SENT) == 0) {
141
0
            SSLfatal(s, TLS1_AD_UNSUPPORTED_EXTENSION, SSL_R_BAD_EXTENSION);
142
0
            return 0;
143
0
        }
144
0
    }
145
146
    /*
147
     * Extensions received in the ClientHello or CertificateRequest are marked
148
     * with the SSL_EXT_FLAG_RECEIVED. This is so we know to add the equivalent
149
     * extensions in the response messages
150
     */
151
0
    if ((context & (SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST))
152
0
        != 0)
153
0
        meth->ext_flags |= SSL_EXT_FLAG_RECEIVED;
154
155
    /* If no parse function set return success */
156
0
    if (meth->parse_cb == NULL)
157
0
        return 1;
158
159
0
    if (meth->parse_cb(SSL_CONNECTION_GET_USER_SSL(s), ext_type, context, ext_data,
160
0
            ext_size, x, chainidx, &al, meth->parse_arg)
161
0
        <= 0) {
162
0
        SSLfatal(s, al, SSL_R_BAD_EXTENSION);
163
0
        return 0;
164
0
    }
165
166
0
    return 1;
167
0
}
168
169
/*
170
 * Request custom extension data from the application and add to the return
171
 * buffer.
172
 */
173
int custom_ext_add(SSL_CONNECTION *s, int context, WPACKET *pkt, X509 *x,
174
    size_t chainidx, int maxversion)
175
0
{
176
0
    custom_ext_methods *exts = &s->cert->custext;
177
0
    custom_ext_method *meth;
178
0
    size_t i;
179
0
    int al;
180
0
    int for_comp = (context & SSL_EXT_TLS1_3_CERTIFICATE_COMPRESSION) != 0;
181
182
0
    for (i = 0; i < exts->meths_count; i++) {
183
0
        const unsigned char *out = NULL;
184
0
        size_t outlen = 0;
185
186
0
        meth = exts->meths + i;
187
188
0
        if (!should_add_extension(s, meth->context, context, maxversion))
189
0
            continue;
190
191
0
        if ((context & (SSL_EXT_TLS1_2_SERVER_HELLO | SSL_EXT_TLS1_3_SERVER_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS | SSL_EXT_TLS1_3_CERTIFICATE | SSL_EXT_TLS1_3_RAW_PUBLIC_KEY | SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST)) != 0) {
192
            /* Only send extensions present in ClientHello/CertificateRequest */
193
0
            if (!(meth->ext_flags & SSL_EXT_FLAG_RECEIVED))
194
0
                continue;
195
0
        }
196
197
0
#ifndef OPENSSL_NO_ECH
198
0
        if ((context & SSL_EXT_CLIENT_HELLO) != 0
199
0
            && s->ext.ech.attempted == 1) {
200
0
            if (s->ext.ech.ch_depth == 1) {
201
                /* mark custom CH ext for ECH compression, if doing ECH */
202
0
                if (s->ext.ech.n_outer_only >= OSSL_ECH_OUTERS_MAX) {
203
0
                    OSSL_TRACE_BEGIN(TLS)
204
0
                    {
205
0
                        BIO_printf(trc_out,
206
0
                            "Too many outers to compress (max=%d)\n",
207
0
                            OSSL_ECH_OUTERS_MAX);
208
0
                    }
209
0
                    OSSL_TRACE_END(TLS);
210
0
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_EXTENSION);
211
0
                    return 0;
212
0
                }
213
0
                s->ext.ech.outer_only[s->ext.ech.n_outer_only] = meth->ext_type;
214
0
                s->ext.ech.n_outer_only++;
215
0
                OSSL_TRACE_BEGIN(TLS)
216
0
                {
217
0
                    BIO_printf(trc_out, "ECH compressing type "
218
0
                                        "0x%04x (tot: %d)\n",
219
0
                        (int)meth->ext_type,
220
0
                        (int)s->ext.ech.n_outer_only);
221
0
                }
222
0
                OSSL_TRACE_END(TLS);
223
0
            }
224
0
            if (s->ext.ech.ch_depth == 0) {
225
                /*
226
                 * We store/access the index of the extension handler in
227
                 * s->ext.ech.ext_ind, as we'd otherwise not know it here.
228
                 * Be nice were there a better way to handle that.
229
                 */
230
                /* copy over the extension octets (if any) to outer */
231
0
                int j, tind = -1;
232
0
                RAW_EXTENSION *raws = NULL;
233
234
                /* we gotta find the relevant index to copy over this ext */
235
0
                if (s->clienthello == NULL
236
0
                    || s->clienthello->pre_proc_exts == NULL) {
237
0
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_EXTENSION);
238
0
                    return 0;
239
0
                }
240
0
                raws = s->clienthello->pre_proc_exts;
241
0
                for (j = 0; j != (int)s->clienthello->pre_proc_exts_len; j++) {
242
0
                    if (raws[j].type == meth->ext_type) {
243
0
                        tind = j;
244
0
                        break;
245
0
                    }
246
0
                }
247
0
                if (tind == -1) {
248
0
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_EXTENSION);
249
0
                    return 0;
250
0
                }
251
0
                if (ossl_ech_copy_inner2outer(s, meth->ext_type, tind,
252
0
                        pkt)
253
0
                    != OSSL_ECH_SAME_EXT_DONE) {
254
                    /* for custom exts, we really should have found it */
255
0
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_EXTENSION);
256
0
                    return 0;
257
0
                }
258
                /* we're done with that one now */
259
0
                continue;
260
0
            }
261
0
        }
262
0
#endif
263
264
        /*
265
         * We skip it if the callback is absent - except for a ClientHello where
266
         * we add an empty extension.
267
         */
268
0
        if ((context & SSL_EXT_CLIENT_HELLO) == 0 && meth->add_cb == NULL)
269
0
            continue;
270
271
0
        if (meth->add_cb != NULL) {
272
0
            int cb_retval = meth->add_cb(SSL_CONNECTION_GET_USER_SSL(s),
273
0
                meth->ext_type, context, &out,
274
0
                &outlen, x, chainidx, &al,
275
0
                meth->add_arg);
276
277
0
            if (cb_retval < 0) {
278
0
                if (!for_comp)
279
0
                    SSLfatal(s, al, SSL_R_CALLBACK_FAILED);
280
0
                return 0; /* error */
281
0
            }
282
0
            if (cb_retval == 0)
283
0
                continue; /* skip this extension */
284
0
        }
285
286
0
        if (!WPACKET_put_bytes_u16(pkt, meth->ext_type)
287
0
            || !WPACKET_start_sub_packet_u16(pkt)
288
0
            || (outlen > 0 && !WPACKET_memcpy(pkt, out, outlen))
289
0
            || !WPACKET_close(pkt)) {
290
0
            if (meth->free_cb != NULL)
291
0
                meth->free_cb(SSL_CONNECTION_GET_USER_SSL(s), meth->ext_type,
292
0
                    context, out, meth->add_arg);
293
0
            if (!for_comp)
294
0
                SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
295
0
            return 0;
296
0
        }
297
0
        if ((context & SSL_EXT_CLIENT_HELLO) != 0) {
298
            /*
299
             * We can't send duplicates: code logic should prevent this.
300
             */
301
0
            if (!ossl_assert((meth->ext_flags & SSL_EXT_FLAG_SENT) == 0)) {
302
0
                if (meth->free_cb != NULL)
303
0
                    meth->free_cb(SSL_CONNECTION_GET_USER_SSL(s), meth->ext_type,
304
0
                        context, out, meth->add_arg);
305
0
                if (!for_comp)
306
0
                    SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
307
0
                return 0;
308
0
            }
309
            /*
310
             * Indicate extension has been sent: this is both a sanity check to
311
             * ensure we don't send duplicate extensions and indicates that it
312
             * is not an error if the extension is present in ServerHello.
313
             */
314
0
            meth->ext_flags |= SSL_EXT_FLAG_SENT;
315
0
        }
316
0
        if (meth->free_cb != NULL)
317
0
            meth->free_cb(SSL_CONNECTION_GET_USER_SSL(s), meth->ext_type,
318
0
                context, out, meth->add_arg);
319
0
    }
320
0
    return 1;
321
0
}
322
323
/* Copy the flags from src to dst for any extensions that exist in both */
324
int custom_exts_copy_flags(custom_ext_methods *dst,
325
    const custom_ext_methods *src)
326
0
{
327
0
    size_t i;
328
0
    custom_ext_method *methsrc = src->meths;
329
330
0
    for (i = 0; i < src->meths_count; i++, methsrc++) {
331
0
        custom_ext_method *methdst = custom_ext_find(dst, methsrc->role,
332
0
            methsrc->ext_type, NULL);
333
334
0
        if (methdst == NULL)
335
0
            continue;
336
337
0
        methdst->ext_flags = methsrc->ext_flags;
338
0
    }
339
340
0
    return 1;
341
0
}
342
343
/* Copy old style API wrapper arguments */
344
static void custom_ext_copy_old_cb(custom_ext_method *methdst,
345
    const custom_ext_method *methsrc,
346
    int *err)
347
0
{
348
0
    if (methsrc->add_cb != custom_ext_add_old_cb_wrap)
349
0
        return;
350
351
0
    if (*err) {
352
0
        methdst->add_arg = NULL;
353
0
        methdst->parse_arg = NULL;
354
0
        return;
355
0
    }
356
357
0
    methdst->add_arg = OPENSSL_memdup(methsrc->add_arg,
358
0
        sizeof(custom_ext_add_cb_wrap));
359
0
    methdst->parse_arg = OPENSSL_memdup(methsrc->parse_arg,
360
0
        sizeof(custom_ext_parse_cb_wrap));
361
362
0
    if (methdst->add_arg == NULL || methdst->parse_arg == NULL)
363
0
        *err = 1;
364
365
0
    return;
366
0
}
367
368
/* Copy table of custom extensions */
369
int custom_exts_copy(custom_ext_methods *dst, const custom_ext_methods *src)
370
0
{
371
0
    size_t i;
372
0
    int err = 0;
373
374
0
    if (src->meths_count > 0) {
375
0
        dst->meths = OPENSSL_memdup(src->meths,
376
0
            sizeof(*src->meths) * src->meths_count);
377
0
        if (dst->meths == NULL)
378
0
            return 0;
379
0
        dst->meths_count = src->meths_count;
380
381
0
        for (i = 0; i < src->meths_count; i++)
382
0
            custom_ext_copy_old_cb(&dst->meths[i], &src->meths[i], &err);
383
0
    }
384
385
0
    if (err) {
386
0
        custom_exts_free(dst);
387
0
        return 0;
388
0
    }
389
390
0
    return 1;
391
0
}
392
393
void custom_exts_free(custom_ext_methods *exts)
394
0
{
395
0
    size_t i;
396
0
    custom_ext_method *meth;
397
398
0
    for (i = 0, meth = exts->meths; i < exts->meths_count; i++, meth++) {
399
0
        if (meth->add_cb != custom_ext_add_old_cb_wrap)
400
0
            continue;
401
402
        /* Old style API wrapper. Need to free the arguments too */
403
0
        OPENSSL_free(meth->add_arg);
404
0
        OPENSSL_free(meth->parse_arg);
405
0
    }
406
0
    OPENSSL_free(exts->meths);
407
0
    exts->meths = NULL;
408
0
    exts->meths_count = 0;
409
0
}
410
411
/* Return true if a client custom extension exists, false otherwise */
412
int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx, unsigned int ext_type)
413
0
{
414
0
    return custom_ext_find(&ctx->cert->custext, ENDPOINT_CLIENT, ext_type,
415
0
               NULL)
416
0
        != NULL;
417
0
}
418
419
int ossl_tls_add_custom_ext_intern(SSL_CTX *ctx, custom_ext_methods *exts,
420
    ENDPOINT role, unsigned int ext_type,
421
    unsigned int context,
422
    SSL_custom_ext_add_cb_ex add_cb,
423
    SSL_custom_ext_free_cb_ex free_cb,
424
    void *add_arg,
425
    SSL_custom_ext_parse_cb_ex parse_cb,
426
    void *parse_arg)
427
0
{
428
0
    custom_ext_method *meth, *tmp;
429
430
    /*
431
     * Check application error: if add_cb is not set free_cb will never be
432
     * called.
433
     */
434
0
    if (add_cb == NULL && free_cb != NULL)
435
0
        return 0;
436
437
0
    if (exts == NULL)
438
0
        exts = &ctx->cert->custext;
439
440
0
#ifndef OPENSSL_NO_CT
441
    /*
442
     * We don't want applications registering callbacks for SCT extensions
443
     * whilst simultaneously using the built-in SCT validation features, as
444
     * these two things may not play well together.
445
     */
446
0
    if (ext_type == TLSEXT_TYPE_signed_certificate_timestamp
447
0
        && (context & SSL_EXT_CLIENT_HELLO) != 0
448
0
        && ctx != NULL
449
0
        && SSL_CTX_ct_is_enabled(ctx))
450
0
        return 0;
451
0
#endif
452
453
    /*
454
     * Don't add if extension supported internally, but make exception
455
     * for extension types that previously were not supported, but now are.
456
     */
457
0
    if (SSL_extension_supported(ext_type)
458
0
        && ext_type != TLSEXT_TYPE_signed_certificate_timestamp)
459
0
        return 0;
460
461
    /* Extension type must fit in 16 bits */
462
0
    if (ext_type > 0xffff)
463
0
        return 0;
464
    /* Search for duplicate */
465
0
    if (custom_ext_find(exts, role, ext_type, NULL))
466
0
        return 0;
467
0
    tmp = OPENSSL_realloc(exts->meths,
468
0
        (exts->meths_count + 1) * sizeof(custom_ext_method));
469
0
    if (tmp == NULL)
470
0
        return 0;
471
472
0
    exts->meths = tmp;
473
0
    meth = exts->meths + exts->meths_count;
474
0
    memset(meth, 0, sizeof(*meth));
475
0
    meth->role = role;
476
0
    meth->context = context;
477
0
    meth->parse_cb = parse_cb;
478
0
    meth->add_cb = add_cb;
479
0
    meth->free_cb = free_cb;
480
0
    meth->ext_type = ext_type;
481
0
    meth->add_arg = add_arg;
482
0
    meth->parse_arg = parse_arg;
483
0
    exts->meths_count++;
484
0
    return 1;
485
0
}
486
487
static int add_old_custom_ext(SSL_CTX *ctx, ENDPOINT role,
488
    unsigned int ext_type,
489
    unsigned int context,
490
    custom_ext_add_cb add_cb,
491
    custom_ext_free_cb free_cb,
492
    void *add_arg,
493
    custom_ext_parse_cb parse_cb, void *parse_arg)
494
0
{
495
0
    custom_ext_add_cb_wrap *add_cb_wrap
496
0
        = OPENSSL_malloc(sizeof(*add_cb_wrap));
497
0
    custom_ext_parse_cb_wrap *parse_cb_wrap
498
0
        = OPENSSL_malloc(sizeof(*parse_cb_wrap));
499
0
    int ret;
500
501
0
    if (add_cb_wrap == NULL || parse_cb_wrap == NULL) {
502
0
        OPENSSL_free(add_cb_wrap);
503
0
        OPENSSL_free(parse_cb_wrap);
504
0
        return 0;
505
0
    }
506
507
0
    add_cb_wrap->add_arg = add_arg;
508
0
    add_cb_wrap->add_cb = add_cb;
509
0
    add_cb_wrap->free_cb = free_cb;
510
0
    parse_cb_wrap->parse_arg = parse_arg;
511
0
    parse_cb_wrap->parse_cb = parse_cb;
512
513
0
    ret = ossl_tls_add_custom_ext_intern(ctx, NULL, role, ext_type,
514
0
        context,
515
0
        custom_ext_add_old_cb_wrap,
516
0
        custom_ext_free_old_cb_wrap,
517
0
        add_cb_wrap,
518
0
        custom_ext_parse_old_cb_wrap,
519
0
        parse_cb_wrap);
520
521
0
    if (!ret) {
522
0
        OPENSSL_free(add_cb_wrap);
523
0
        OPENSSL_free(parse_cb_wrap);
524
0
    }
525
526
0
    return ret;
527
0
}
528
529
/* Application level functions to add the old custom extension callbacks */
530
int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
531
    custom_ext_add_cb add_cb,
532
    custom_ext_free_cb free_cb,
533
    void *add_arg,
534
    custom_ext_parse_cb parse_cb, void *parse_arg)
535
0
{
536
0
    return add_old_custom_ext(ctx, ENDPOINT_CLIENT, ext_type,
537
0
        SSL_EXT_TLS1_2_AND_BELOW_ONLY
538
0
            | SSL_EXT_CLIENT_HELLO
539
0
            | SSL_EXT_TLS1_2_SERVER_HELLO
540
0
            | SSL_EXT_IGNORE_ON_RESUMPTION,
541
0
        add_cb, free_cb, add_arg, parse_cb, parse_arg);
542
0
}
543
544
int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
545
    custom_ext_add_cb add_cb,
546
    custom_ext_free_cb free_cb,
547
    void *add_arg,
548
    custom_ext_parse_cb parse_cb, void *parse_arg)
549
0
{
550
0
    return add_old_custom_ext(ctx, ENDPOINT_SERVER, ext_type,
551
0
        SSL_EXT_TLS1_2_AND_BELOW_ONLY
552
0
            | SSL_EXT_CLIENT_HELLO
553
0
            | SSL_EXT_TLS1_2_SERVER_HELLO
554
0
            | SSL_EXT_IGNORE_ON_RESUMPTION,
555
0
        add_cb, free_cb, add_arg, parse_cb, parse_arg);
556
0
}
557
558
int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
559
    unsigned int context,
560
    SSL_custom_ext_add_cb_ex add_cb,
561
    SSL_custom_ext_free_cb_ex free_cb,
562
    void *add_arg,
563
    SSL_custom_ext_parse_cb_ex parse_cb, void *parse_arg)
564
0
{
565
0
    return ossl_tls_add_custom_ext_intern(ctx, NULL, ENDPOINT_BOTH, ext_type,
566
0
        context, add_cb, free_cb, add_arg,
567
0
        parse_cb, parse_arg);
568
0
}
569
570
int SSL_extension_supported(unsigned int ext_type)
571
0
{
572
0
    switch (ext_type) {
573
        /* Internally supported extensions. */
574
0
    case TLSEXT_TYPE_application_layer_protocol_negotiation:
575
0
    case TLSEXT_TYPE_ec_point_formats:
576
0
    case TLSEXT_TYPE_supported_groups:
577
0
    case TLSEXT_TYPE_key_share:
578
0
#ifndef OPENSSL_NO_NEXTPROTONEG
579
0
    case TLSEXT_TYPE_next_proto_neg:
580
0
#endif
581
0
    case TLSEXT_TYPE_padding:
582
0
    case TLSEXT_TYPE_renegotiate:
583
0
    case TLSEXT_TYPE_max_fragment_length:
584
0
    case TLSEXT_TYPE_server_name:
585
0
    case TLSEXT_TYPE_session_ticket:
586
0
    case TLSEXT_TYPE_signature_algorithms:
587
0
#ifndef OPENSSL_NO_SRP
588
0
    case TLSEXT_TYPE_srp:
589
0
#endif
590
0
#ifndef OPENSSL_NO_OCSP
591
0
    case TLSEXT_TYPE_status_request:
592
0
#endif
593
0
#ifndef OPENSSL_NO_CT
594
0
    case TLSEXT_TYPE_signed_certificate_timestamp:
595
0
#endif
596
0
#ifndef OPENSSL_NO_SRTP
597
0
    case TLSEXT_TYPE_use_srtp:
598
0
#endif
599
0
    case TLSEXT_TYPE_encrypt_then_mac:
600
0
    case TLSEXT_TYPE_supported_versions:
601
0
    case TLSEXT_TYPE_extended_master_secret:
602
0
    case TLSEXT_TYPE_psk_kex_modes:
603
0
    case TLSEXT_TYPE_cookie:
604
0
    case TLSEXT_TYPE_early_data:
605
0
    case TLSEXT_TYPE_certificate_authorities:
606
0
    case TLSEXT_TYPE_psk:
607
0
    case TLSEXT_TYPE_post_handshake_auth:
608
0
    case TLSEXT_TYPE_compress_certificate:
609
0
    case TLSEXT_TYPE_client_cert_type:
610
0
    case TLSEXT_TYPE_server_cert_type:
611
0
#ifndef OPENSSL_NO_ECH
612
0
    case TLSEXT_TYPE_ech:
613
0
    case TLSEXT_TYPE_outer_extensions:
614
0
#endif
615
0
        return 1;
616
0
    default:
617
0
        return 0;
618
0
    }
619
0
}