Coverage Report

Created: 2026-08-31 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/ssl/ssl_local.h
Line
Count
Source
1
/*
2
 * Copyright 1995-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
4
 * Copyright 2005 Nokia. All rights reserved.
5
 *
6
 * Licensed under the Apache License 2.0 (the "License").  You may not use
7
 * this file except in compliance with the License.  You can obtain a copy
8
 * in the file LICENSE in the source distribution or at
9
 * https://www.openssl.org/source/license.html
10
 */
11
12
#ifndef OSSL_SSL_LOCAL_H
13
#define OSSL_SSL_LOCAL_H
14
15
#include <stdbool.h>
16
#include <stdlib.h>
17
#include <time.h>
18
#include <errno.h>
19
#include "internal/common.h" /* for HAS_PREFIX */
20
21
#include <openssl/buffer.h>
22
#include <openssl/bio.h>
23
#include <openssl/comp.h>
24
#include <openssl/dsa.h>
25
#include <openssl/err.h>
26
#include <openssl/ssl.h>
27
#include <openssl/async.h>
28
#include <openssl/symhacks.h>
29
#include <openssl/ct.h>
30
#include "internal/recordmethod.h"
31
#include "internal/statem.h"
32
#include "internal/packet.h"
33
#include "internal/dane.h"
34
#include "internal/refcount.h"
35
#include "internal/tlssigalgs.h"
36
#include "internal/tsan_assist.h"
37
#include "internal/bio.h"
38
#include "internal/ktls.h"
39
#include "internal/list.h"
40
#include "internal/time.h"
41
#include "internal/ssl.h"
42
#include "internal/cryptlib.h"
43
#include "internal/quic_predef.h"
44
#include "record/record.h"
45
#include "internal/quic_predef.h"
46
#include "internal/quic_tls.h"
47
#include "internal/thread_arch.h"
48
#include "internal/bio_addr.h"
49
#include "internal/dtls_record_rx.h"
50
#include "internal/dgram_conn_lookup.h"
51
#include "internal/rio_notifier.h"
52
#ifndef OPENSSL_NO_ECH
53
#include "ech/ech_local.h"
54
#endif
55
56
/*
57
 * Forward declarations for DTLS listener types. These are defined in the
58
 * headers above when DTLS is enabled, but we need forward declarations
59
 * for the pointer types used in structures when DTLS is disabled.
60
 * DGRAM_DEMUX requires either QUIC or DTLS to be enabled.
61
 */
62
#if defined(OPENSSL_NO_QUIC) && defined(OPENSSL_NO_DTLS)
63
typedef struct dgram_demux_st DGRAM_DEMUX;
64
#endif
65
#ifdef OPENSSL_NO_DTLS
66
typedef struct dtls_rx_st DTLS_RX;
67
typedef struct dgram_conn_lookup_st DGRAM_CONN_LOOKUP;
68
#endif
69
70
#ifdef OPENSSL_BUILD_SHLIBSSL
71
#undef OPENSSL_EXTERN
72
#define OPENSSL_EXTERN OPENSSL_EXPORT
73
#endif
74
75
0
#define TLS_MAX_VERSION_INTERNAL TLS1_3_VERSION
76
0
#define DTLS_MAX_VERSION_INTERNAL DTLS1_3_VERSION
77
78
/*
79
 * DTLS version numbers are strange because they're inverted. Except for
80
 * DTLS1_BAD_VER, which should be considered "lower" than the rest.
81
 */
82
0
#define dtls_ver_ordinal(v1) (((v1) == DTLS1_BAD_VER) ? 0xff00 : (v1))
83
0
#define DTLS_VERSION_GT(v1, v2) (dtls_ver_ordinal(v1) < dtls_ver_ordinal(v2))
84
0
#define DTLS_VERSION_GE(v1, v2) (dtls_ver_ordinal(v1) <= dtls_ver_ordinal(v2))
85
0
#define DTLS_VERSION_LT(v1, v2) (dtls_ver_ordinal(v1) > dtls_ver_ordinal(v2))
86
0
#define DTLS_VERSION_LE(v1, v2) (dtls_ver_ordinal(v1) >= dtls_ver_ordinal(v2))
87
/* TLS/DTLS version for the given SSL object: XTLS(ssl, 1, 2) == TLS 1.2 or DTLS 1.2 */
88
0
#define XTLS(ssl, m, n) (SSL_is_dtls(ssl) ? (((0xFF - m) << 8) | (0xFF - n)) : (((0x02 + m) << 8) | (0x01 + n)))
89
90
/*
91
 * SSL/TLS version comparison
92
 *
93
 * Returns
94
 *      0 if versiona is equal to versionb or if either are 0 or less
95
 *      1 if versiona is greater than versionb
96
 *     -1 if versiona is less than versionb
97
 */
98
#define TLS_VERSION_CMP(versiona, versionb)                        \
99
0
    ((!ossl_assert((versiona) > 0) || !ossl_assert((versionb) > 0) \
100
0
         || (versiona) == (versionb))                              \
101
0
            ? 0                                                    \
102
0
            : ((versiona) < (versionb) ? -1 : 1))
103
/*
104
 * DTLS version comparison
105
 *
106
 * Returns
107
 *      0 if versiona is equal to versionb or if either are 0 or less
108
 *      1 if versiona is greater than versionb
109
 *     -1 if versiona is less than versionb
110
 */
111
#define DTLS_VERSION_CMP(versiona, versionb)                       \
112
0
    ((!ossl_assert((versiona) > 0) || !ossl_assert((versionb) > 0) \
113
0
         || (versiona) == (versionb))                              \
114
0
            ? 0                                                    \
115
0
            : (DTLS_VERSION_LT((versiona),                         \
116
0
                   (versionb))                                     \
117
0
                      ? -1                                         \
118
0
                      : 1))
119
/*
120
 * SSL/TLS/DTLS version comparison
121
 *
122
 * Returns
123
 *      0 if versiona is equal to versionb or if either are 0 or less
124
 *      1 if versiona is greater than versionb
125
 *     -1 if versiona is less than versionb
126
 */
127
#define PROTOCOL_VERSION_CMP(isdtls, versiona, versionb) \
128
0
    ((isdtls) ? DTLS_VERSION_CMP(versiona, versionb)     \
129
0
              : TLS_VERSION_CMP(versiona, versionb))
130
131
0
#define SSL_AD_NO_ALERT -1
132
133
/*
134
 * Define the Bitmasks for SSL_CIPHER.algorithms.
135
 * This bits are used packed as dense as possible. If new methods/ciphers
136
 * etc will be added, the bits a likely to change, so this information
137
 * is for internal library use only, even though SSL_CIPHER.algorithms
138
 * can be publicly accessed.
139
 * Use the according functions for cipher management instead.
140
 *
141
 * The bit mask handling in the selection and sorting scheme in
142
 * ssl_create_cipher_list() has only limited capabilities, reflecting
143
 * that the different entities within are mutually exclusive:
144
 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
145
 */
146
147
/* Bits for algorithm_mkey (key exchange algorithm) */
148
/* RSA key exchange */
149
0
#define SSL_kRSA 0x00000001U
150
/* tmp DH key no DH cert */
151
0
#define SSL_kDHE 0x00000002U
152
/* ephemeral ECDH */
153
0
#define SSL_kECDHE 0x00000004U
154
/* PSK */
155
0
#define SSL_kPSK 0x00000008U
156
/* GOST key exchange */
157
0
#define SSL_kGOST 0x00000010U
158
/* SRP */
159
0
#define SSL_kSRP 0x00000020U
160
161
0
#define SSL_kRSAPSK 0x00000040U
162
0
#define SSL_kECDHEPSK 0x00000080U
163
0
#define SSL_kDHEPSK 0x00000100U
164
/* GOST KDF key exchange, draft-smyshlyaev-tls12-gost-suites */
165
0
#define SSL_kGOST18 0x00000200U
166
167
/* all PSK */
168
169
0
#define SSL_PSK (SSL_kPSK | SSL_kRSAPSK | SSL_kECDHEPSK | SSL_kDHEPSK)
170
171
/* Any appropriate key exchange algorithm (for TLS 1.3 ciphersuites) */
172
0
#define SSL_kANY 0x00000000U
173
174
/* Bits for algorithm_auth (server authentication) */
175
/* RSA auth */
176
0
#define SSL_aRSA 0x00000001U
177
/* DSS auth */
178
0
#define SSL_aDSS 0x00000002U
179
/* no auth (i.e. use ADH or AECDH) */
180
0
#define SSL_aNULL 0x00000004U
181
/* ECDSA auth*/
182
0
#define SSL_aECDSA 0x00000008U
183
/* PSK auth */
184
0
#define SSL_aPSK 0x00000010U
185
/* GOST R 34.10-2001 signature auth */
186
0
#define SSL_aGOST01 0x00000020U
187
/* SRP auth */
188
0
#define SSL_aSRP 0x00000040U
189
/* GOST R 34.10-2012 signature auth */
190
0
#define SSL_aGOST12 0x00000080U
191
/* Any appropriate signature auth (for TLS 1.3 ciphersuites) */
192
0
#define SSL_aANY 0x00000000U
193
/* All bits requiring a certificate */
194
#define SSL_aCERT \
195
0
    (SSL_aRSA | SSL_aDSS | SSL_aECDSA | SSL_aGOST01 | SSL_aGOST12)
196
197
/* Bits for algorithm_enc (symmetric encryption) */
198
0
#define SSL_DES 0x00000001U
199
0
#define SSL_3DES 0x00000002U
200
0
#define SSL_RC4 0x00000004U
201
0
#define SSL_RC2 0x00000008U
202
0
#define SSL_IDEA 0x00000010U
203
0
#define SSL_eNULL 0x00000020U
204
0
#define SSL_AES128 0x00000040U
205
0
#define SSL_AES256 0x00000080U
206
0
#define SSL_CAMELLIA128 0x00000100U
207
0
#define SSL_CAMELLIA256 0x00000200U
208
0
#define SSL_eGOST2814789CNT 0x00000400U
209
0
#define SSL_SEED 0x00000800U
210
0
#define SSL_AES128GCM 0x00001000U
211
0
#define SSL_AES256GCM 0x00002000U
212
0
#define SSL_AES128CCM 0x00004000U
213
0
#define SSL_AES256CCM 0x00008000U
214
0
#define SSL_AES128CCM8 0x00010000U
215
0
#define SSL_AES256CCM8 0x00020000U
216
0
#define SSL_eGOST2814789CNT12 0x00040000U
217
0
#define SSL_CHACHA20POLY1305 0x00080000U
218
0
#define SSL_ARIA128GCM 0x00100000U
219
0
#define SSL_ARIA256GCM 0x00200000U
220
0
#define SSL_MAGMA 0x00400000U
221
0
#define SSL_KUZNYECHIK 0x00800000U
222
0
#define SSL_SM4GCM 0x01000000U
223
0
#define SSL_SM4CCM 0x02000000U
224
225
0
#define SSL_AESGCM (SSL_AES128GCM | SSL_AES256GCM)
226
0
#define SSL_AESCCM (SSL_AES128CCM | SSL_AES256CCM | SSL_AES128CCM8 | SSL_AES256CCM8)
227
0
#define SSL_AES (SSL_AES128 | SSL_AES256 | SSL_AESGCM | SSL_AESCCM)
228
0
#define SSL_AES128_ANY (SSL_AES128 | SSL_AES128CCM | SSL_AES128CCM8 \
229
0
    | SSL_AES128GCM)
230
0
#define SSL_AES256_ANY (SSL_AES256 | SSL_AES256CCM | SSL_AES256CCM8 \
231
0
    | SSL_AES256GCM)
232
#define SSL_CAMELLIA (SSL_CAMELLIA128 | SSL_CAMELLIA256)
233
0
#define SSL_CHACHA20 (SSL_CHACHA20POLY1305)
234
0
#define SSL_ARIAGCM (SSL_ARIA128GCM | SSL_ARIA256GCM)
235
#define SSL_ARIA (SSL_ARIAGCM)
236
#define SSL_CBC (SSL_DES | SSL_3DES | SSL_RC2 | SSL_IDEA \
237
    | SSL_AES128 | SSL_AES256 | SSL_CAMELLIA128          \
238
    | SSL_CAMELLIA256 | SSL_SEED)
239
240
/* Bits for algorithm_mac (symmetric authentication) */
241
242
0
#define SSL_MD5 0x00000001U
243
0
#define SSL_SHA1 0x00000002U
244
0
#define SSL_GOST94 0x00000004U
245
0
#define SSL_GOST89MAC 0x00000008U
246
0
#define SSL_SHA256 0x00000010U
247
0
#define SSL_SHA384 0x00000020U
248
/* Not a real MAC, just an indication it is part of cipher */
249
0
#define SSL_AEAD 0x00000040U
250
0
#define SSL_GOST12_256 0x00000080U
251
0
#define SSL_GOST89MAC12 0x00000100U
252
0
#define SSL_GOST12_512 0x00000200U
253
0
#define SSL_MAGMAOMAC 0x00000400U
254
0
#define SSL_KUZNYECHIKOMAC 0x00000800U
255
256
/*
257
 * When adding new digest in the ssl_ciph.c and increment SSL_MD_NUM_IDX make
258
 * sure to update this constant too
259
 */
260
261
0
#define SSL_MD_MD5_IDX 0
262
0
#define SSL_MD_SHA1_IDX 1
263
#define SSL_MD_GOST94_IDX 2
264
0
#define SSL_MD_GOST89MAC_IDX 3
265
0
#define SSL_MD_SHA256_IDX 4
266
0
#define SSL_MD_SHA384_IDX 5
267
#define SSL_MD_GOST12_256_IDX 6
268
0
#define SSL_MD_GOST89MAC12_IDX 7
269
#define SSL_MD_GOST12_512_IDX 8
270
0
#define SSL_MD_MD5_SHA1_IDX 9
271
0
#define SSL_MD_SHA224_IDX 10
272
#define SSL_MD_SHA512_IDX 11
273
0
#define SSL_MD_MAGMAOMAC_IDX 12
274
0
#define SSL_MD_KUZNYECHIKOMAC_IDX 13
275
#define SSL_MD_SM3_IDX 14
276
0
#define SSL_MAX_DIGEST 15
277
278
0
#define SSL_MD_NUM_IDX SSL_MAX_DIGEST
279
280
/* Bits for algorithm2 (handshake digests and other extra flags) */
281
282
/* Bits 0-7 are handshake MAC */
283
0
#define SSL_HANDSHAKE_MAC_MASK 0xFF
284
0
#define SSL_HANDSHAKE_MAC_MD5_SHA1 SSL_MD_MD5_SHA1_IDX
285
0
#define SSL_HANDSHAKE_MAC_SHA256 SSL_MD_SHA256_IDX
286
0
#define SSL_HANDSHAKE_MAC_SHA384 SSL_MD_SHA384_IDX
287
#define SSL_HANDSHAKE_MAC_GOST94 SSL_MD_GOST94_IDX
288
#define SSL_HANDSHAKE_MAC_GOST12_256 SSL_MD_GOST12_256_IDX
289
#define SSL_HANDSHAKE_MAC_GOST12_512 SSL_MD_GOST12_512_IDX
290
#define SSL_HANDSHAKE_MAC_SM3 SSL_MD_SM3_IDX
291
0
#define SSL_HANDSHAKE_MAC_DEFAULT SSL_HANDSHAKE_MAC_MD5_SHA1
292
293
/* Bits 8-15 bits are PRF */
294
0
#define TLS1_PRF_DGST_SHIFT 8
295
#define TLS1_PRF_SHA1_MD5 (SSL_MD_MD5_SHA1_IDX << TLS1_PRF_DGST_SHIFT)
296
0
#define TLS1_PRF_SHA256 (SSL_MD_SHA256_IDX << TLS1_PRF_DGST_SHIFT)
297
0
#define TLS1_PRF_SHA384 (SSL_MD_SHA384_IDX << TLS1_PRF_DGST_SHIFT)
298
#define TLS1_PRF_GOST94 (SSL_MD_GOST94_IDX << TLS1_PRF_DGST_SHIFT)
299
#define TLS1_PRF_GOST12_256 (SSL_MD_GOST12_256_IDX << TLS1_PRF_DGST_SHIFT)
300
#define TLS1_PRF_GOST12_512 (SSL_MD_GOST12_512_IDX << TLS1_PRF_DGST_SHIFT)
301
0
#define TLS1_PRF (SSL_MD_MD5_SHA1_IDX << TLS1_PRF_DGST_SHIFT)
302
303
/*
304
 * Stream MAC for GOST ciphersuites from cryptopro draft (currently this also
305
 * goes into algorithm2)
306
 */
307
0
#define TLS1_STREAM_MAC 0x10000
308
/*
309
 * TLSTREE cipher/mac key derivation from draft-smyshlyaev-tls12-gost-suites
310
 * (currently this also  goes into algorithm2)
311
 */
312
0
#define TLS1_TLSTREE 0x20000
313
314
/* Ciphersuite supported in QUIC */
315
0
#define SSL_QUIC 0x00040000U
316
317
0
#define SSL_STRONG_MASK 0x0000001FU
318
0
#define SSL_DEFAULT_MASK 0X00000020U
319
320
#define SSL_STRONG_NONE 0x00000001U
321
#define SSL_LOW 0x00000002U
322
#define SSL_MEDIUM 0x00000004U
323
#define SSL_HIGH 0x00000008U
324
/* #define SSL_FIPS 0x00000010U obsolete FIPS canister remnant */
325
#define SSL_NOT_DEFAULT 0x00000020U
326
327
/* we have used 0000003f - 26 bits left to go */
328
329
/* Flag used on OpenSSL ciphersuite ids to indicate they are for SSLv3+ */
330
0
#define SSL3_CK_CIPHERSUITE_FLAG 0x03000000
331
332
/* Check if an SSL structure is using DTLS */
333
#define SSL_CONNECTION_IS_DTLS(s) \
334
0
    (SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS)
335
336
/* Check if an SSL structure is using DTLS */
337
#define SSL_CONNECTION_MIDDLEBOX_IS_ENABLED(s)          \
338
0
    ((s->options & SSL_OP_ENABLE_MIDDLEBOX_COMPAT) != 0 \
339
0
        && !SSL_CONNECTION_IS_DTLS(s))
340
341
/* Check if we are using DTLSv1.3 */
342
0
#define SSL_CONNECTION_IS_DTLS13(s) (SSL_CONNECTION_IS_DTLS(s)                      \
343
0
    && DTLS_VERSION_GE(SSL_CONNECTION_GET_SSL(s)->method->version, DTLS1_3_VERSION) \
344
0
    && SSL_CONNECTION_GET_SSL(s)->method->version != DTLS_ANY_VERSION)
345
346
/* Check if an SSL_CTX structure is using DTLS */
347
#define SSL_CTX_IS_DTLS(ctx) \
348
0
    ((ctx->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS) != 0)
349
350
/* Check if we are using TLSv1.3 */
351
0
#define SSL_CONNECTION_IS_TLS13(s) (!SSL_CONNECTION_IS_DTLS(s)      \
352
0
    && SSL_CONNECTION_GET_SSL(s)->method->version >= TLS1_3_VERSION \
353
0
    && SSL_CONNECTION_GET_SSL(s)->method->version != TLS_ANY_VERSION)
354
355
/* Check if we are using (D)TLSv1.3 */
356
#define SSL_CONNECTION_IS_VERSION13(s) \
357
0
    (SSL_CONNECTION_IS_DTLS13(s) || SSL_CONNECTION_IS_TLS13(s))
358
359
#define SSL_CONNECTION_TREAT_AS_TLS13(s)                         \
360
0
    (SSL_CONNECTION_IS_VERSION13(s)                              \
361
0
        || (s)->early_data_state == SSL_EARLY_DATA_CONNECTING    \
362
0
        || (s)->early_data_state == SSL_EARLY_DATA_CONNECT_RETRY \
363
0
        || (s)->early_data_state == SSL_EARLY_DATA_WRITING       \
364
0
        || (s)->early_data_state == SSL_EARLY_DATA_WRITE_RETRY   \
365
0
        || (s)->hello_retry_request == SSL_HRR_PENDING)
366
367
0
#define SSL_IS_FIRST_HANDSHAKE(s) ((s)->s3.tmp.finish_md_len == 0 \
368
0
    || (s)->s3.tmp.peer_finish_md_len == 0)
369
370
/*
371
 * See if we use signature algorithms extension and signature algorithm
372
 * before signatures.
373
 */
374
#define SSL_USE_SIGALGS(s) \
375
0
    (SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_SIGALGS)
376
377
#define IS_MAX_FRAGMENT_LENGTH_EXT_VALID(value) \
378
0
    (((value) >= TLSEXT_max_fragment_length_512) && ((value) <= TLSEXT_max_fragment_length_4096))
379
#define USE_MAX_FRAGMENT_LENGTH_EXT(session) \
380
0
    IS_MAX_FRAGMENT_LENGTH_EXT_VALID(session->ext.max_fragment_len_mode)
381
#define GET_MAX_FRAGMENT_LENGTH(session) \
382
0
    (512U << (session->ext.max_fragment_len_mode - 1))
383
384
0
#define SSL_READ_ETM(s) (s->s3.flags & TLS1_FLAGS_ENCRYPT_THEN_MAC_READ)
385
0
#define SSL_WRITE_ETM(s) (s->s3.flags & TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE)
386
387
0
#define SSL_IS_QUIC_HANDSHAKE(s) (((s)->s3.flags & TLS1_FLAGS_QUIC) != 0)
388
0
#define SSL_IS_QUIC_INT_HANDSHAKE(s) (((s)->s3.flags & TLS1_FLAGS_QUIC_INTERNAL) != 0)
389
390
/* no end of early data */
391
0
#define SSL_NO_EOED(s) (SSL_IS_QUIC_HANDSHAKE(s) || SSL_CONNECTION_IS_DTLS13(s))
392
393
/* alert_dispatch values */
394
395
/* No alert pending */
396
0
#define SSL_ALERT_DISPATCH_NONE 0
397
/* Alert pending */
398
0
#define SSL_ALERT_DISPATCH_PENDING 1
399
/* Pending alert write needs to be retried */
400
0
#define SSL_ALERT_DISPATCH_RETRY 2
401
402
/* Mostly for SSLv3 */
403
0
#define SSL_PKEY_RSA 0
404
0
#define SSL_PKEY_RSA_PSS_SIGN 1
405
0
#define SSL_PKEY_DSA_SIGN 2
406
0
#define SSL_PKEY_ECC 3
407
0
#define SSL_PKEY_GOST01 4
408
0
#define SSL_PKEY_GOST12_256 5
409
0
#define SSL_PKEY_GOST12_512 6
410
0
#define SSL_PKEY_ED25519 7
411
0
#define SSL_PKEY_ED448 8
412
0
#define SSL_PKEY_NUM 9
413
414
#define SSL_ENC_DES_IDX 0
415
#define SSL_ENC_3DES_IDX 1
416
#define SSL_ENC_RC4_IDX 2
417
#define SSL_ENC_RC2_IDX 3
418
#define SSL_ENC_IDEA_IDX 4
419
0
#define SSL_ENC_NULL_IDX 5
420
#define SSL_ENC_AES128_IDX 6
421
#define SSL_ENC_AES256_IDX 7
422
#define SSL_ENC_CAMELLIA128_IDX 8
423
#define SSL_ENC_CAMELLIA256_IDX 9
424
#define SSL_ENC_GOST89_IDX 10
425
#define SSL_ENC_SEED_IDX 11
426
#define SSL_ENC_AES128GCM_IDX 12
427
#define SSL_ENC_AES256GCM_IDX 13
428
#define SSL_ENC_AES128CCM_IDX 14
429
#define SSL_ENC_AES256CCM_IDX 15
430
#define SSL_ENC_AES128CCM8_IDX 16
431
#define SSL_ENC_AES256CCM8_IDX 17
432
#define SSL_ENC_GOST8912_IDX 18
433
#define SSL_ENC_CHACHA_IDX 19
434
#define SSL_ENC_ARIA128GCM_IDX 20
435
#define SSL_ENC_ARIA256GCM_IDX 21
436
#define SSL_ENC_MAGMA_IDX 22
437
#define SSL_ENC_KUZNYECHIK_IDX 23
438
#define SSL_ENC_SM4GCM_IDX 24
439
#define SSL_ENC_SM4CCM_IDX 25
440
0
#define SSL_ENC_NUM_IDX 26
441
442
/*-
443
 * SSL_kRSA <- RSA_ENC
444
 * SSL_kDH  <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
445
 * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
446
 * SSL_aRSA <- RSA_ENC | RSA_SIGN
447
 * SSL_aDSS <- DSA_SIGN
448
 */
449
450
/* Certificate Type State */
451
0
#define OSSL_CERT_TYPE_CTOS_NONE 0
452
0
#define OSSL_CERT_TYPE_CTOS_GOOD 1
453
0
#define OSSL_CERT_TYPE_CTOS_ERROR 2
454
455
/* Post-Handshake Authentication state */
456
typedef enum {
457
    SSL_PHA_NONE = 0,
458
    SSL_PHA_EXT_SENT, /* client-side only: extension sent */
459
    SSL_PHA_EXT_RECEIVED, /* server-side only: extension received */
460
    SSL_PHA_REQUEST_PENDING, /* server-side only: request pending */
461
    SSL_PHA_REQUESTED /* request received by client, or sent by server */
462
} SSL_PHA_STATE;
463
464
/* CipherSuite value length. */
465
0
#define TLS_CIPHER_LEN 2
466
/* used to hold info on the particular ciphers used */
467
struct ssl_cipher_st {
468
    uint32_t valid;
469
    const char *name; /* text name */
470
    const char *stdname; /* RFC name */
471
    uint32_t id; /* id, 4 bytes, first is version */
472
    /*
473
     * changed in 1.0.0: these four used to be portions of a single value
474
     * 'algorithms'
475
     */
476
    uint32_t algorithm_mkey; /* key exchange algorithm */
477
    uint32_t algorithm_auth; /* server authentication */
478
    uint32_t algorithm_enc; /* symmetric encryption */
479
    uint32_t algorithm_mac; /* symmetric authentication */
480
    int min_tls; /* minimum SSL/TLS protocol version */
481
    int max_tls; /* maximum SSL/TLS protocol version */
482
    int min_dtls; /* minimum DTLS protocol version */
483
    int max_dtls; /* maximum DTLS protocol version */
484
    uint32_t algo_strength; /* strength and export flags */
485
    uint32_t algorithm2; /* Extra flags */
486
    int32_t strength_bits; /* Number of bits really used */
487
    uint32_t alg_bits; /* Number of bits for algorithm */
488
};
489
490
/* Used to hold SSL/TLS functions */
491
struct ssl_method_st {
492
    int version;
493
    unsigned flags;
494
    uint64_t mask;
495
    SSL *(*ssl_new)(SSL_CTX *ctx);
496
    void (*ssl_free)(SSL *s);
497
    int (*ssl_reset)(SSL *s);
498
    int (*ssl_init)(SSL *s);
499
    int (*ssl_clear)(SSL *s);
500
    void (*ssl_deinit)(SSL *s);
501
    int (*ssl_accept)(SSL *s);
502
    int (*ssl_connect)(SSL *s);
503
    int (*ssl_read)(SSL *s, void *buf, size_t len, size_t *readbytes);
504
    int (*ssl_peek)(SSL *s, void *buf, size_t len, size_t *readbytes);
505
    int (*ssl_write)(SSL *s, const void *buf, size_t len, size_t *written);
506
    int (*ssl_shutdown)(SSL *s);
507
    int (*ssl_renegotiate)(SSL *s);
508
    int (*ssl_renegotiate_check)(SSL *s, int);
509
    int (*ssl_read_bytes)(SSL *s, uint8_t type, uint8_t *recvd_type,
510
        unsigned char *buf, size_t len, int peek,
511
        size_t *readbytes);
512
    int (*ssl_write_bytes)(SSL *s, uint8_t type, const void *buf_, size_t len,
513
        size_t *written);
514
    int (*ssl_dispatch_alert)(SSL *s);
515
    long (*ssl_ctrl)(SSL *s, int cmd, long larg, void *parg);
516
    long (*ssl_ctx_ctrl)(SSL_CTX *ctx, int cmd, long larg, void *parg);
517
    const SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
518
    int (*put_cipher_by_char)(const SSL_CIPHER *cipher, WPACKET *pkt,
519
        size_t *len);
520
    size_t (*ssl_pending)(const SSL *s);
521
    int (*num_ciphers)(void);
522
    const SSL_CIPHER *(*get_cipher)(unsigned ncipher);
523
    OSSL_TIME (*get_timeout)(void);
524
    const struct ssl3_enc_method *ssl3_enc; /* Extra TLS stuff */
525
    int (*ssl_version)(void);
526
    long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)(void));
527
    long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)(void));
528
};
529
530
/*
531
 * Matches the length of PSK_MAX_PSK_LEN. We keep it the same value for
532
 * consistency, even in the event of OPENSSL_NO_PSK being defined.
533
 */
534
0
#define TLS13_MAX_RESUMPTION_PSK_LENGTH 512
535
536
/*-
537
 * Lets make this into an ASN.1 type structure as follows
538
 * SSL_SESSION_ID ::= SEQUENCE {
539
 *      version                 INTEGER,        -- structure version number
540
 *      SSLversion              INTEGER,        -- SSL version number
541
 *      Cipher                  OCTET STRING,   -- the 3 byte cipher ID
542
 *      Session_ID              OCTET STRING,   -- the Session ID
543
 *      Master_key              OCTET STRING,   -- the master key
544
 *      Key_Arg [ 0 ] IMPLICIT  OCTET STRING,   -- the optional Key argument
545
 *      Time [ 1 ] EXPLICIT     INTEGER,        -- optional Start Time
546
 *      Timeout [ 2 ] EXPLICIT  INTEGER,        -- optional Timeout ins seconds
547
 *      Peer [ 3 ] EXPLICIT     X509,           -- optional Peer Certificate
548
 *      Session_ID_context [ 4 ] EXPLICIT OCTET STRING,   -- the Session ID context
549
 *      Verify_result [ 5 ] EXPLICIT INTEGER,   -- X509_V_... code for `Peer'
550
 *      HostName [ 6 ] EXPLICIT OCTET STRING,   -- optional HostName from servername TLS extension
551
 *      PSK_identity_hint [ 7 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
552
 *      PSK_identity [ 8 ] EXPLICIT OCTET STRING,  -- optional PSK identity
553
 *      Ticket_lifetime_hint [9] EXPLICIT INTEGER, -- server's lifetime hint for session ticket
554
 *      Ticket [10]             EXPLICIT OCTET STRING, -- session ticket (clients only)
555
 *      Compression_meth [11]   EXPLICIT OCTET STRING, -- optional compression method
556
 *      SRP_username [ 12 ] EXPLICIT OCTET STRING -- optional SRP username
557
 *      flags [ 13 ] EXPLICIT INTEGER -- optional flags
558
 *      }
559
 * Look in ssl/ssl_asn1.c for more details
560
 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
561
 */
562
struct ssl_session_st {
563
    int ssl_version; /* what ssl version session info is being kept
564
                      * in here? */
565
    size_t master_key_length;
566
567
    /* TLSv1.3 early_secret used for external PSKs */
568
    unsigned char early_secret[EVP_MAX_MD_SIZE];
569
    /*
570
     * For <=TLS1.2 this is the master_key. For TLS1.3 this is the resumption
571
     * PSK
572
     */
573
    unsigned char master_key[TLS13_MAX_RESUMPTION_PSK_LENGTH];
574
    /* session_id - valid? */
575
    size_t session_id_length;
576
    unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
577
    /*
578
     * this is used to determine whether the session is being reused in the
579
     * appropriate context. It is up to the application to set this, via
580
     * SSL_new
581
     */
582
    size_t sid_ctx_length;
583
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
584
#ifndef OPENSSL_NO_PSK
585
    char *psk_identity_hint;
586
    char *psk_identity;
587
#endif
588
    /*
589
     * Used to indicate that session resumption is not allowed. Applications
590
     * can also set this bit for a new session via not_resumable_session_cb
591
     * to disable session caching and tickets.
592
     */
593
    int not_resumable;
594
    /*
595
     * Set when this session's master key was resolved from an external PSK
596
     * identity (psk_find_session_cb(), or the legacy psk_server_callback())
597
     * rather than from a resumption ticket or session-cache lookup.
598
     * ssl_get_prev_session() uses this to exempt such sessions from sid_ctx
599
     * checks that only make sense for a real cache lookup.
600
     *
601
     * Deliberately not part of the SSL_SESSION ASN.1 encoding: it must not
602
     * survive a real ticket round-trip (a session reconstructed by
603
     * d2i_SSL_SESSION() from a genuine, previously-issued ticket is by
604
     * definition not an external-PSK match, and should get the ordinary
605
     * sid_ctx treatment). ssl_session_dup() resets it to 0 on every copy,
606
     * mirroring not_resumable just above, for the same reason.
607
     */
608
    int psk_external;
609
    /* Peer raw public key, if available */
610
    EVP_PKEY *peer_rpk;
611
    /* This is the cert and type for the other end. */
612
    X509 *peer;
613
    /* Certificate chain peer sent. */
614
    STACK_OF(X509) *peer_chain;
615
    /*
616
     * when app_verify_callback accepts a session where the peer's
617
     * certificate is not ok, we must remember the error for session reuse:
618
     */
619
    long verify_result; /* only for servers */
620
    OSSL_TIME timeout;
621
    OSSL_TIME time;
622
    OSSL_TIME calc_timeout;
623
    unsigned int compress_meth; /* Need to lookup the method */
624
    const SSL_CIPHER *cipher;
625
    unsigned long cipher_id; /* when ASN.1 loaded, this needs to be used to
626
                              * load the 'cipher' structure */
627
    unsigned int kex_group; /* TLS group from key exchange */
628
    CRYPTO_EX_DATA ex_data; /* application specific data */
629
630
    struct {
631
        char *hostname;
632
        /* RFC4507 info */
633
        unsigned char *tick; /* Session ticket */
634
        size_t ticklen; /* Session ticket length */
635
        /* Session lifetime hint in seconds */
636
        unsigned long tick_lifetime_hint;
637
        uint32_t tick_age_add;
638
        /* Max number of bytes that can be sent as early data */
639
        uint32_t max_early_data;
640
        /* The ALPN protocol selected for this session */
641
        unsigned char *alpn_selected;
642
        size_t alpn_selected_len;
643
        /*
644
         * Maximum Fragment Length as per RFC 4366.
645
         * If this value does not contain RFC 4366 allowed values (1-4) then
646
         * either the Maximum Fragment Length Negotiation failed or was not
647
         * performed at all.
648
         */
649
        uint8_t max_fragment_len_mode;
650
    } ext;
651
#ifndef OPENSSL_NO_SRP
652
    char *srp_username;
653
#endif
654
    unsigned char *ticket_appdata;
655
    size_t ticket_appdata_len;
656
    uint32_t flags;
657
    SSL_CTX *owner;
658
659
    /*
660
     * These are used to make removal of session-ids more efficient and to
661
     * implement a maximum cache size. Access requires protection of ctx->lock.
662
     */
663
    struct ssl_session_st *prev, *next;
664
    CRYPTO_REF_COUNT references;
665
};
666
667
/* Extended master secret support */
668
0
#define SSL_SESS_FLAG_EXTMS 0x1
669
670
#ifndef OPENSSL_NO_SRP
671
672
typedef struct srp_ctx_st {
673
    /* param for all the callbacks */
674
    void *SRP_cb_arg;
675
    /* set client Hello login callback */
676
    int (*TLS_ext_srp_username_callback)(SSL *, int *, void *);
677
    /* set SRP N/g param callback for verification */
678
    int (*SRP_verify_param_callback)(SSL *, void *);
679
    /* set SRP client passwd callback */
680
    char *(*SRP_give_srp_client_pwd_callback)(SSL *, void *);
681
    char *login;
682
    BIGNUM *N, *g, *s, *B, *A;
683
    BIGNUM *a, *b, *v;
684
    char *info;
685
    int strength;
686
    unsigned long srp_Mask;
687
} SRP_CTX;
688
689
#endif
690
691
typedef enum {
692
    SSL_EARLY_DATA_NONE = 0,
693
    SSL_EARLY_DATA_CONNECT_RETRY,
694
    SSL_EARLY_DATA_CONNECTING,
695
    SSL_EARLY_DATA_WRITE_RETRY,
696
    SSL_EARLY_DATA_WRITING,
697
    SSL_EARLY_DATA_WRITE_FLUSH,
698
    SSL_EARLY_DATA_UNAUTH_WRITING,
699
    SSL_EARLY_DATA_FINISHED_WRITING,
700
    SSL_EARLY_DATA_ACCEPT_RETRY,
701
    SSL_EARLY_DATA_ACCEPTING,
702
    SSL_EARLY_DATA_READ_RETRY,
703
    SSL_EARLY_DATA_READING,
704
    SSL_EARLY_DATA_FINISHED_READING
705
} SSL_EARLY_DATA_STATE;
706
707
/*
708
 * We check that the amount of unreadable early data doesn't exceed
709
 * max_early_data. max_early_data is given in plaintext bytes. However if it is
710
 * unreadable then we only know the number of ciphertext bytes. We also don't
711
 * know how much the overhead should be because it depends on the ciphersuite.
712
 * We make a small allowance. We assume 5 records of actual data plus the end
713
 * of early data alert record. Each record has a tag and a content type byte.
714
 * The longest tag length we know of is EVP_GCM_TLS_TAG_LEN. We don't count the
715
 * content of the alert record either which is 2 bytes.
716
 */
717
0
#define EARLY_DATA_CIPHERTEXT_OVERHEAD ((6 * (EVP_GCM_TLS_TAG_LEN + 1)) + 2)
718
719
/*
720
 * The allowance we have between the client's calculated ticket age and our own.
721
 * We allow for 10 seconds. If a ticket is presented and the
722
 * client's age calculation is different by more than this than our own then we
723
 * do not allow that ticket for early_data.
724
 */
725
0
#define TICKET_AGE_ALLOWANCE ossl_seconds2time(10)
726
727
0
#define MAX_COMPRESSIONS_SIZE 255
728
729
typedef struct raw_extension_st {
730
    /* Raw packet data for the extension */
731
    PACKET data;
732
    /* Set to 1 if the extension is present or 0 otherwise */
733
    int present;
734
    /* Set to 1 if we have already parsed the extension or 0 otherwise */
735
    int parsed;
736
    /* The type of this extension, i.e. a TLSEXT_TYPE_* value */
737
    unsigned int type;
738
    /* Track what order extensions are received in (0-based). */
739
    size_t received_order;
740
} RAW_EXTENSION;
741
742
typedef struct {
743
    unsigned int legacy_version;
744
    unsigned char random[SSL3_RANDOM_SIZE];
745
    size_t session_id_len;
746
    unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
747
    size_t dtls_cookie_len;
748
    unsigned char dtls_cookie[DTLS1_COOKIE_LENGTH];
749
    PACKET ciphersuites;
750
    size_t compressions_len;
751
    unsigned char compressions[MAX_COMPRESSIONS_SIZE];
752
    PACKET extensions;
753
    size_t pre_proc_exts_len;
754
    RAW_EXTENSION *pre_proc_exts;
755
} CLIENTHELLO_MSG;
756
757
/*
758
 * Extension index values NOTE: Any updates to these defines should be mirrored
759
 * with equivalent updates to ext_defs in extensions.c
760
 */
761
typedef enum tlsext_index_en {
762
    TLSEXT_IDX_renegotiate,
763
    TLSEXT_IDX_server_name,
764
    TLSEXT_IDX_max_fragment_length,
765
    TLSEXT_IDX_srp,
766
    TLSEXT_IDX_ec_point_formats,
767
    TLSEXT_IDX_supported_groups,
768
    TLSEXT_IDX_session_ticket,
769
    TLSEXT_IDX_status_request,
770
    TLSEXT_IDX_next_proto_neg,
771
    TLSEXT_IDX_application_layer_protocol_negotiation,
772
    TLSEXT_IDX_use_srtp,
773
    TLSEXT_IDX_encrypt_then_mac,
774
    TLSEXT_IDX_signed_certificate_timestamp,
775
    TLSEXT_IDX_extended_master_secret,
776
    TLSEXT_IDX_signature_algorithms_cert,
777
    TLSEXT_IDX_post_handshake_auth,
778
    TLSEXT_IDX_client_cert_type,
779
    TLSEXT_IDX_server_cert_type,
780
    TLSEXT_IDX_signature_algorithms,
781
    TLSEXT_IDX_supported_versions,
782
    TLSEXT_IDX_psk_kex_modes,
783
    TLSEXT_IDX_key_share,
784
    TLSEXT_IDX_cookie,
785
    TLSEXT_IDX_cryptopro_bug,
786
    TLSEXT_IDX_compress_certificate,
787
    TLSEXT_IDX_early_data,
788
    TLSEXT_IDX_certificate_authorities,
789
    TLSEXT_IDX_ech,
790
    TLSEXT_IDX_outer_extensions,
791
    TLSEXT_IDX_grease1,
792
    TLSEXT_IDX_grease2,
793
    TLSEXT_IDX_psk,
794
    /* Dummy index - must always be the last entry */
795
    TLSEXT_IDX_num_builtins
796
} TLSEXT_INDEX;
797
798
/* RFC 8701 GREASE seed indices */
799
0
#define OSSL_GREASE_CIPHER 0
800
0
#define OSSL_GREASE_GROUP 1
801
0
#define OSSL_GREASE_EXT1 2
802
0
#define OSSL_GREASE_EXT2 3
803
#define OSSL_GREASE_VERSION 4
804
#define OSSL_GREASE_SIGALG 5
805
0
#define OSSL_GREASE_LAST_INDEX 5
806
807
DEFINE_LHASH_OF_EX(SSL_SESSION);
808
/* Needed in ssl_cert.c */
809
DEFINE_LHASH_OF_EX(X509_NAME);
810
811
0
#define TLSEXT_KEYNAME_LENGTH 16
812
#define TLSEXT_TICK_KEY_LENGTH 32
813
814
typedef struct ssl_ctx_ext_secure_st {
815
    unsigned char tick_hmac_key[TLSEXT_TICK_KEY_LENGTH];
816
    unsigned char tick_aes_key[TLSEXT_TICK_KEY_LENGTH];
817
} SSL_CTX_EXT_SECURE;
818
819
/*
820
 * Helper function for HMAC
821
 * The structure should be considered opaque, it will change once the low
822
 * level deprecated calls are removed.  At that point it can be replaced
823
 * by EVP_MAC_CTX and most of the functions converted to macros or inlined
824
 * directly.
825
 */
826
typedef struct ssl_hmac_st {
827
    EVP_MAC_CTX *ctx;
828
#ifndef OPENSSL_NO_DEPRECATED_3_0
829
    HMAC_CTX *old_ctx;
830
#endif
831
} SSL_HMAC;
832
833
SSL_HMAC *ssl_hmac_construct(const SSL_CTX *ctx, SSL_HMAC *hctx);
834
void ssl_hmac_destruct(SSL_HMAC *ctx);
835
#ifndef OPENSSL_NO_DEPRECATED_3_0
836
HMAC_CTX *ssl_hmac_get0_HMAC_CTX(SSL_HMAC *ctx);
837
#endif
838
EVP_MAC_CTX *ssl_hmac_get0_EVP_MAC_CTX(SSL_HMAC *ctx);
839
int ssl_hmac_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
840
int ssl_hmac_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
841
int ssl_hmac_final(SSL_HMAC *ctx, unsigned char *md, size_t *len,
842
    size_t max_size);
843
size_t ssl_hmac_size(const SSL_HMAC *ctx);
844
845
int ssl_get_EC_curve_nid(const EVP_PKEY *pkey);
846
__owur int tls13_set_encoded_pub_key(EVP_PKEY *pkey,
847
    const unsigned char *enckey,
848
    size_t enckeylen);
849
850
typedef struct tls_group_info_st {
851
    char *tlsname; /* Curve Name as in TLS specs */
852
    char *realname; /* Curve Name according to provider */
853
    char *algorithm; /* Algorithm name to fetch */
854
    unsigned int secbits; /* Bits of security (from SP800-57) */
855
    uint16_t group_id; /* Group ID */
856
    int mintls; /* Minimum TLS version, -1 unsupported */
857
    int maxtls; /* Maximum TLS version (or 0 for undefined) */
858
    int mindtls; /* Minimum DTLS version, -1 unsupported */
859
    int maxdtls; /* Maximum DTLS version (or 0 for undefined) */
860
    char is_kem; /* Mode for this Group: 0 is KEX, 1 is KEM */
861
} TLS_GROUP_INFO;
862
863
typedef struct tls_sigalg_info_st {
864
    char *name; /* name as in IANA TLS specs */
865
    uint16_t code_point; /* IANA-specified code point of sigalg-name */
866
    char *sigalg_name; /* (combined) sigalg name */
867
    char *sigalg_oid; /* (combined) sigalg OID */
868
    char *sig_name; /* pure signature algorithm name */
869
    char *sig_oid; /* pure signature algorithm OID */
870
    char *hash_name; /* hash algorithm name */
871
    char *hash_oid; /* hash algorithm OID */
872
    char *keytype; /* keytype name */
873
    char *keytype_oid; /* keytype OID */
874
    unsigned int secbits; /* Bits of security (from SP800-57) */
875
    int mintls; /* Minimum TLS version, -1 unsupported */
876
    int maxtls; /* Maximum TLS version (or 0 for undefined) */
877
    int mindtls; /* Minimum DTLS version, -1 unsupported */
878
    int maxdtls; /* Maximum DTLS version (or 0 for undefined) */
879
} TLS_SIGALG_INFO;
880
881
/*
882
 * Structure containing table entry of certificate info corresponding to
883
 * CERT_PKEY entries
884
 */
885
typedef struct {
886
    int pkey_nid; /* NID of public key algorithm */
887
    uint32_t amask; /* authmask corresponding to key type */
888
} SSL_CERT_LOOKUP;
889
890
#if !defined(OPENSSL_NO_TLS1)      \
891
    || !defined(OPENSSL_NO_TLS1_1) \
892
    || !defined(OPENSSL_NO_TLS1_2) \
893
    || !defined(OPENSSL_NO_DTLS1)  \
894
    || !defined(OPENSSL_NO_DTLS1_2)
895
#define OPENSSL_HAVE_TLS1PRF
896
#endif
897
898
struct ssl_ctx_st {
899
    OSSL_LIB_CTX *libctx;
900
901
    const SSL_METHOD *method;
902
    STACK_OF(SSL_CIPHER) *cipher_list;
903
    /* same as above but sorted for lookup */
904
    STACK_OF(SSL_CIPHER) *cipher_list_by_id;
905
    /* TLSv1.3 specific ciphersuites */
906
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
907
    struct x509_store_st /* X509_STORE */ *cert_store;
908
    LHASH_OF(SSL_SESSION) *sessions;
909
    EVP_MAC *hmac;
910
    EVP_MD *sha256;
911
    EVP_CIPHER *tktenc;
912
#ifdef OPENSSL_HAVE_TLS1PRF
913
    EVP_KDF *tls1prf;
914
#endif
915
    /*
916
     * Most session-ids that will be cached, default is
917
     * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
918
     */
919
    size_t session_cache_size;
920
    struct ssl_session_st *session_cache_head;
921
    struct ssl_session_st *session_cache_tail;
922
    /*
923
     * This can have one of 2 values, ored together, SSL_SESS_CACHE_CLIENT,
924
     * SSL_SESS_CACHE_SERVER, Default is SSL_SESSION_CACHE_SERVER, which
925
     * means only SSL_accept will cache SSL_SESSIONS.
926
     */
927
    uint32_t session_cache_mode;
928
    /*
929
     * If timeout is not 0, it is the default timeout value set when
930
     * SSL_new() is called.  This has been put in to make life easier to set
931
     * things up
932
     */
933
    OSSL_TIME session_timeout;
934
    /*
935
     * If this callback is not null, it will be called each time a session id
936
     * is added to the cache.  If this function returns 1, it means that the
937
     * callback will do an SSL_SESSION_free() when it has finished using it.
938
     * Otherwise, on 0, it means the callback has finished with it. If
939
     * remove_session_cb is not null, it will be called when a session-id is
940
     * removed from the cache.  After the call, OpenSSL will
941
     * SSL_SESSION_free() it.
942
     */
943
    int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
944
    void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
945
    SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
946
        const unsigned char *data, int len,
947
        int *copy);
948
    struct {
949
        TSAN_QUALIFIER int sess_connect; /* SSL new conn - started */
950
        TSAN_QUALIFIER int sess_connect_renegotiate; /* SSL reneg - requested */
951
        TSAN_QUALIFIER int sess_connect_good; /* SSL new conne/reneg - finished */
952
        TSAN_QUALIFIER int sess_accept; /* SSL new accept - started */
953
        TSAN_QUALIFIER int sess_accept_renegotiate; /* SSL reneg - requested */
954
        TSAN_QUALIFIER int sess_accept_good; /* SSL accept/reneg - finished */
955
        TSAN_QUALIFIER int sess_miss; /* session lookup misses */
956
        TSAN_QUALIFIER int sess_timeout; /* reuse attempt on timeouted session */
957
        TSAN_QUALIFIER int sess_cache_full; /* session removed due to full cache */
958
        TSAN_QUALIFIER int sess_hit; /* session reuse actually done */
959
        TSAN_QUALIFIER int sess_cb_hit; /* session-id that was not in
960
                                         * the cache was passed back via
961
                                         * the callback. This indicates
962
                                         * that the application is
963
                                         * supplying session-id's from
964
                                         * other processes - spooky
965
                                         * :-) */
966
    } stats;
967
#ifdef TSAN_REQUIRES_LOCKING
968
    CRYPTO_RWLOCK *tsan_lock;
969
#endif
970
971
    CRYPTO_REF_COUNT references;
972
973
    /* if defined, these override the X509_verify_cert() calls */
974
    int (*app_verify_callback)(X509_STORE_CTX *, void *);
975
    void *app_verify_arg;
976
    /*
977
     * before OpenSSL 0.9.7, 'app_verify_arg' was ignored
978
     * ('app_verify_callback' was called with just one argument)
979
     */
980
981
    /* Default password callback. */
982
    pem_password_cb *default_passwd_callback;
983
984
    /* Default password callback user data. */
985
    void *default_passwd_callback_userdata;
986
987
    /* get client cert callback */
988
    int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
989
990
    /* cookie generate callback */
991
    int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
992
        unsigned int *cookie_len);
993
994
    /* verify cookie callback */
995
    int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie,
996
        unsigned int cookie_len);
997
998
    /* TLS1.3 app-controlled cookie generate callback */
999
    int (*gen_stateless_cookie_cb)(SSL *ssl, unsigned char *cookie,
1000
        size_t *cookie_len);
1001
1002
    /* TLS1.3 verify app-controlled cookie callback */
1003
    int (*verify_stateless_cookie_cb)(SSL *ssl, const unsigned char *cookie,
1004
        size_t cookie_len);
1005
1006
    CRYPTO_EX_DATA ex_data;
1007
1008
    STACK_OF(X509) *extra_certs;
1009
    STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, TLSv1 */
1010
1011
    /* Default values used when no per-SSL value is defined follow */
1012
1013
    /* used if SSL's info_callback is NULL */
1014
    void (*info_callback)(const SSL *ssl, int type, int val);
1015
1016
    /*
1017
     * What we put in certificate_authorities extension for TLS 1.3
1018
     * (ClientHello and CertificateRequest) or just client cert requests for
1019
     * earlier versions. If client_ca_names is populated then it is only used
1020
     * for client cert requests, and in preference to ca_names.
1021
     */
1022
    STACK_OF(X509_NAME) *ca_names;
1023
    STACK_OF(X509_NAME) *client_ca_names;
1024
1025
    /*
1026
     * Default values to use in SSL structures follow (these are copied by
1027
     * SSL_new)
1028
     */
1029
1030
    uint64_t options;
1031
    uint32_t mode;
1032
    int min_proto_version;
1033
    int max_proto_version;
1034
    size_t max_cert_list;
1035
1036
    struct cert_st /* CERT */ *cert;
1037
    SSL_CERT_LOOKUP *ssl_cert_info;
1038
    int read_ahead;
1039
1040
    /* callback that allows applications to peek at protocol messages */
1041
    ossl_msg_cb msg_callback;
1042
    void *msg_callback_arg;
1043
1044
    uint32_t verify_mode;
1045
    size_t sid_ctx_length;
1046
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1047
    /* called 'verify_callback' in the SSL */
1048
    int (*default_verify_callback)(int ok, X509_STORE_CTX *ctx);
1049
1050
    /* Default generate session ID callback. */
1051
    GEN_SESSION_CB generate_session_id;
1052
1053
    X509_VERIFY_PARAM *param;
1054
1055
    int quiet_shutdown;
1056
1057
#ifndef OPENSSL_NO_CT
1058
    CTLOG_STORE *ctlog_store; /* CT Log Store */
1059
    /*
1060
     * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
1061
     * If they are not, the connection should be aborted.
1062
     */
1063
    ssl_ct_validation_cb ct_validation_callback;
1064
    void *ct_validation_callback_arg;
1065
#endif
1066
1067
    /*
1068
     * If we're using more than one pipeline how should we divide the data
1069
     * up between the pipes?
1070
     */
1071
    size_t split_send_fragment;
1072
    /*
1073
     * Maximum amount of data to send in one fragment. actual record size can
1074
     * be more than this due to padding and MAC overheads.
1075
     */
1076
    size_t max_send_fragment;
1077
1078
    /* Up to how many pipelines should we use? If 0 then 1 is assumed */
1079
    size_t max_pipelines;
1080
1081
    /* The default read buffer length to use (0 means not set) */
1082
    size_t default_read_buf_len;
1083
1084
    /* ClientHello callback.  Mostly for extensions, but not entirely. */
1085
    SSL_client_hello_cb_fn client_hello_cb;
1086
    void *client_hello_cb_arg;
1087
1088
    /* Callback to announce new pending ssl objects in the accept queue */
1089
    SSL_new_pending_conn_cb_fn new_pending_conn_cb;
1090
    void *new_pending_conn_arg;
1091
1092
    /* TLS extensions. */
1093
    struct {
1094
        /* TLS extensions servername callback */
1095
        int (*servername_cb)(SSL *, int *, void *);
1096
        void *servername_arg;
1097
        /* RFC 4507 session ticket keys */
1098
        unsigned char tick_key_name[TLSEXT_KEYNAME_LENGTH];
1099
        SSL_CTX_EXT_SECURE *secure;
1100
#ifndef OPENSSL_NO_DEPRECATED_3_0
1101
        /* Callback to support customisation of ticket key setting */
1102
        int (*ticket_key_cb)(SSL *ssl,
1103
            unsigned char *name, unsigned char *iv,
1104
            EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
1105
#endif
1106
        int (*ticket_key_evp_cb)(SSL *ssl,
1107
            unsigned char *name, unsigned char *iv,
1108
            EVP_CIPHER_CTX *ectx, EVP_MAC_CTX *hctx,
1109
            int enc);
1110
1111
        /* certificate status request info */
1112
        /* Callback for status request */
1113
        int (*status_cb)(SSL *ssl, void *arg);
1114
        void *status_arg;
1115
        /* ext status type used for CSR extension (OCSP Stapling) */
1116
        int status_type;
1117
        /* RFC 4366 Maximum Fragment Length Negotiation */
1118
        uint8_t max_fragment_len_mode;
1119
1120
        size_t supportedgroups_len;
1121
        uint16_t *supportedgroups;
1122
1123
        size_t keyshares_len;
1124
        uint16_t *keyshares;
1125
1126
        size_t tuples_len; /* Number of group tuples */
1127
        size_t *tuples; /* Number of groups in each group tuple */
1128
1129
        /*
1130
         * ALPN information (we are in the process of transitioning from NPN to
1131
         * ALPN.)
1132
         */
1133
1134
        /*-
1135
         * For a server, this contains a callback function that allows the
1136
         * server to select the protocol for the connection.
1137
         *   out: on successful return, this must point to the raw protocol
1138
         *        name (without the length prefix).
1139
         *   outlen: on successful return, this contains the length of |*out|.
1140
         *   in: points to the client's list of supported protocols in
1141
         *       wire-format.
1142
         *   inlen: the length of |in|.
1143
         */
1144
        int (*alpn_select_cb)(SSL *s,
1145
            const unsigned char **out,
1146
            unsigned char *outlen,
1147
            const unsigned char *in,
1148
            unsigned int inlen, void *arg);
1149
        void *alpn_select_cb_arg;
1150
1151
        /*
1152
         * For a client, this contains the list of supported protocols in wire
1153
         * format.
1154
         */
1155
        unsigned char *alpn;
1156
        size_t alpn_len;
1157
1158
#ifndef OPENSSL_NO_NEXTPROTONEG
1159
        /* Next protocol negotiation information */
1160
1161
        /*
1162
         * For a server, this contains a callback function by which the set of
1163
         * advertised protocols can be provided.
1164
         */
1165
        SSL_CTX_npn_advertised_cb_func npn_advertised_cb;
1166
        void *npn_advertised_cb_arg;
1167
        /*
1168
         * For a client, this contains a callback function that selects the next
1169
         * protocol from the list provided by the server.
1170
         */
1171
        SSL_CTX_npn_select_cb_func npn_select_cb;
1172
        void *npn_select_cb_arg;
1173
#endif
1174
1175
        unsigned char cookie_hmac_key[SHA256_DIGEST_LENGTH];
1176
#ifndef OPENSSL_NO_ECH
1177
        OSSL_ECH_CTX ech;
1178
#endif
1179
    } ext;
1180
1181
#ifndef OPENSSL_NO_PSK
1182
    SSL_psk_client_cb_func psk_client_callback;
1183
    SSL_psk_server_cb_func psk_server_callback;
1184
#endif
1185
    SSL_psk_find_session_cb_func psk_find_session_cb;
1186
    SSL_psk_use_session_cb_func psk_use_session_cb;
1187
1188
#ifndef OPENSSL_NO_SRP
1189
    SRP_CTX srp_ctx; /* ctx for SRP authentication */
1190
#endif
1191
1192
    /* Shared DANE context */
1193
    struct dane_ctx_st dane;
1194
1195
#ifndef OPENSSL_NO_SRTP
1196
    /* SRTP profiles we are willing to do from RFC 5764 */
1197
    STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
1198
#endif
1199
    /*
1200
     * Callback for disabling session caching and ticket support on a session
1201
     * basis, depending on the chosen cipher.
1202
     */
1203
    int (*not_resumable_session_cb)(SSL *ssl, int is_forward_secure);
1204
1205
    CRYPTO_RWLOCK *lock;
1206
1207
    /*
1208
     * Callback for logging key material for use with debugging tools like
1209
     * Wireshark. The callback should log `line` followed by a newline.
1210
     */
1211
    SSL_CTX_keylog_cb_func keylog_callback;
1212
1213
    /*
1214
     * Private flag for internal key logging based on SSLKEYLOG env
1215
     */
1216
#ifndef OPENSSL_NO_SSLKEYLOG
1217
    uint32_t do_sslkeylog;
1218
#endif
1219
1220
    /*
1221
     * The maximum number of bytes advertised in session tickets that can be
1222
     * sent as early data.
1223
     */
1224
    uint32_t max_early_data;
1225
1226
    /*
1227
     * The maximum number of bytes of early data that a server will tolerate
1228
     * (which should be at least as much as max_early_data).
1229
     */
1230
    uint32_t recv_max_early_data;
1231
1232
    /* TLS1.3 padding callback */
1233
    size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
1234
    void *record_padding_arg;
1235
    size_t block_padding;
1236
    size_t hs_padding;
1237
1238
    /* Session ticket appdata */
1239
    SSL_CTX_generate_session_ticket_fn generate_ticket_cb;
1240
    SSL_CTX_decrypt_session_ticket_fn decrypt_ticket_cb;
1241
    void *ticket_cb_data;
1242
1243
    /* The number of TLS1.3 tickets to automatically send */
1244
    size_t num_tickets;
1245
1246
    /* Callback to determine if early_data is acceptable or not */
1247
    SSL_allow_early_data_cb_fn allow_early_data_cb;
1248
    void *allow_early_data_cb_data;
1249
1250
    /* Do we advertise Post-handshake auth support? */
1251
    int pha_enabled;
1252
1253
    /* Callback for SSL async handling */
1254
    SSL_async_callback_fn async_cb;
1255
    void *async_cb_arg;
1256
1257
    char *propq;
1258
1259
    int ssl_mac_pkey_id[SSL_MD_NUM_IDX];
1260
    const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX];
1261
    const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX];
1262
    size_t ssl_mac_secret_size[SSL_MD_NUM_IDX];
1263
1264
    size_t sigalg_lookup_cache_len;
1265
    size_t tls12_sigalgs_len;
1266
    /* Cache of all sigalgs we know and whether they are available or not */
1267
    struct sigalg_lookup_st *sigalg_lookup_cache;
1268
    /* List of all sigalgs (code points) available, incl. from providers */
1269
    uint16_t *tls12_sigalgs;
1270
1271
    TLS_GROUP_INFO *group_list;
1272
    size_t group_list_len;
1273
    size_t group_list_max_len;
1274
1275
    TLS_SIGALG_INFO *sigalg_list;
1276
    size_t sigalg_list_len;
1277
    size_t sigalg_list_max_len;
1278
1279
    /* masks of disabled algorithms */
1280
    uint32_t disabled_enc_mask;
1281
    uint32_t disabled_mac_mask;
1282
    uint32_t disabled_mkey_mask;
1283
    uint32_t disabled_auth_mask;
1284
1285
#ifndef OPENSSL_NO_COMP_ALG
1286
    /* certificate compression preferences */
1287
    int cert_comp_prefs[TLSEXT_comp_cert_limit];
1288
#endif
1289
1290
    /* Certificate Type stuff - for RPK vs X.509 */
1291
    unsigned char *client_cert_type;
1292
    size_t client_cert_type_len;
1293
    unsigned char *server_cert_type;
1294
    size_t server_cert_type_len;
1295
1296
#ifndef OPENSSL_NO_QUIC
1297
    uint64_t domain_flags;
1298
    SSL_TOKEN_STORE *tokencache;
1299
#endif
1300
1301
#ifndef OPENSSL_NO_QLOG
1302
    char *qlog_title; /* Session title for qlog */
1303
#endif
1304
};
1305
1306
typedef struct ossl_quic_tls_callbacks_st {
1307
    int (*crypto_send_cb)(SSL *s, const unsigned char *buf, size_t buf_len,
1308
        size_t *consumed, void *arg);
1309
    int (*crypto_recv_rcd_cb)(SSL *s, const unsigned char **buf,
1310
        size_t *bytes_read, void *arg);
1311
    int (*crypto_release_rcd_cb)(SSL *s, size_t bytes_read, void *arg);
1312
    int (*yield_secret_cb)(SSL *s, uint32_t prot_level, int direction,
1313
        const unsigned char *secret, size_t secret_len,
1314
        void *arg);
1315
    int (*got_transport_params_cb)(SSL *s, const unsigned char *params,
1316
        size_t params_len,
1317
        void *arg);
1318
    int (*alert_cb)(SSL *s, unsigned char alert_code, void *arg);
1319
} OSSL_QUIC_TLS_CALLBACKS;
1320
1321
typedef struct cert_pkey_st CERT_PKEY;
1322
1323
0
#define SSL_TYPE_SSL_CONNECTION 0
1324
0
#define SSL_TYPE_QUIC_CONNECTION 0x80
1325
0
#define SSL_TYPE_QUIC_XSO 0x81
1326
0
#define SSL_TYPE_QUIC_LISTENER 0x82
1327
0
#define SSL_TYPE_QUIC_DOMAIN 0x83
1328
0
#define SSL_TYPE_DTLS_LISTENER 0x01
1329
1330
0
#define SSL_TYPE_IS_QUIC(x) (((x) & 0x80) != 0)
1331
#define IS_DTLS_LISTENER(ssl) \
1332
0
    ((ssl) != NULL && (ssl)->type == SSL_TYPE_DTLS_LISTENER)
1333
1334
struct ssl_st {
1335
    int type;
1336
    SSL_CTX *ctx;
1337
    const SSL_METHOD *defltmeth;
1338
    const SSL_METHOD *method;
1339
    CRYPTO_REF_COUNT references;
1340
    CRYPTO_RWLOCK *lock;
1341
    /* extra application data */
1342
    CRYPTO_EX_DATA ex_data;
1343
};
1344
1345
struct ssl_connection_st {
1346
    /* type identifier and common data */
1347
    struct ssl_st ssl;
1348
1349
    /*
1350
     * The actual end user's SSL object. Could be different to this one for
1351
     * QUIC
1352
     */
1353
    SSL *user_ssl;
1354
1355
    /*
1356
     * protocol version (one of TLS1_VERSION, TLS1_1_VERSION, TLS1_2_VERSION,
1357
     * TLS1_3_VERSION, DTLS1_VERSION, DTLS1_2_VERSION, DTLS1_3_VERSION)
1358
     */
1359
    int version;
1360
1361
    /*
1362
     * The negotiated version for the connection. Initially PROTO_VERSION_UNSET.
1363
     * Set by ssl_set_negotiated_protocol_version().
1364
     */
1365
    int negotiated_version;
1366
1367
    /*
1368
     * There are 2 BIO's even though they are normally both the same.  This
1369
     * is so data can be read and written to different handlers
1370
     */
1371
    /* used by SSL_read */
1372
    BIO *rbio;
1373
    /* used by SSL_write */
1374
    BIO *wbio;
1375
    /* used during session-id reuse to concatenate messages */
1376
    BIO *bbio;
1377
    /*
1378
     * This holds a variable that indicates what we were doing when a 0 or -1
1379
     * is returned.  This is needed for non-blocking IO so we know what
1380
     * request needs re-doing when in SSL_accept or SSL_connect
1381
     */
1382
    int rwstate;
1383
    int (*handshake_func)(SSL *);
1384
    /*
1385
     * Imagine that here's a boolean member "init" that is switched as soon
1386
     * as SSL_set_{accept/connect}_state is called for the first time, so
1387
     * that "state" and "handshake_func" are properly initialized.  But as
1388
     * handshake_func is == 0 until then, we use this test instead of an
1389
     * "init" member.
1390
     */
1391
    /* are we the server side? */
1392
    int server;
1393
    /*
1394
     * Generate a new session or reuse an old one.
1395
     * NB: For servers, the 'new' session may actually be a previously
1396
     * cached session or even the previous session unless
1397
     * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set
1398
     */
1399
    int new_session;
1400
    /* don't send shutdown packets */
1401
    int quiet_shutdown;
1402
    /* we have shut things down, 0x01 sent, 0x02 for received */
1403
    int shutdown;
1404
    /* Timestamps used to calculate the handshake RTT */
1405
    OSSL_TIME ts_msg_write;
1406
    OSSL_TIME ts_msg_read;
1407
    /* where we are */
1408
    OSSL_STATEM statem;
1409
    SSL_EARLY_DATA_STATE early_data_state;
1410
    BUF_MEM *init_buf; /* buffer used during init */
1411
    void *init_msg; /* pointer to handshake message body, set by
1412
                     * tls_get_message_header() */
1413
    size_t init_num; /* amount read/written */
1414
    size_t init_off; /* amount read/written */
1415
1416
    size_t ssl_pkey_num;
1417
1418
    /* QUIC TLS fields */
1419
    OSSL_QUIC_TLS_CALLBACKS qtcb;
1420
    void *qtarg;
1421
    QUIC_TLS *qtls;
1422
1423
    struct {
1424
        long flags;
1425
        unsigned char server_random[SSL3_RANDOM_SIZE];
1426
        unsigned char client_random[SSL3_RANDOM_SIZE];
1427
1428
        /* used during startup, digest all incoming/outgoing packets */
1429
        BIO *handshake_buffer;
1430
        /*
1431
         * When handshake digest is determined, buffer is hashed and
1432
         * freed and MD_CTX for the required digest is stored here.
1433
         */
1434
        EVP_MD_CTX *handshake_dgst;
1435
        /*
1436
         * Set whenever an expected ChangeCipherSpec message is processed.
1437
         * Unset when the peer's Finished message is received.
1438
         * Unexpected ChangeCipherSpec messages trigger a fatal alert.
1439
         */
1440
        int change_cipher_spec;
1441
        int warn_alert;
1442
        int fatal_alert;
1443
        /*
1444
         * we allow one fatal and one warning alert to be outstanding, send close
1445
         * alert via the warning alert
1446
         */
1447
        int alert_dispatch;
1448
        unsigned char send_alert[2];
1449
        /*
1450
         * This flag is set when we should renegotiate ASAP, basically when there
1451
         * is no more data in the read or write buffers
1452
         */
1453
        int renegotiate;
1454
        int total_renegotiations;
1455
        int num_renegotiations;
1456
        int in_read_app_data;
1457
1458
        struct {
1459
            /* actually only need to be 12 for TLS */
1460
            unsigned char finish_md[EVP_MAX_MD_SIZE * 2];
1461
            size_t finish_md_len;
1462
            unsigned char peer_finish_md[EVP_MAX_MD_SIZE * 2];
1463
            size_t peer_finish_md_len;
1464
            size_t message_size;
1465
            int message_type;
1466
            uint64_t record_epoch;
1467
            uint64_t record_seq_num;
1468
            /* used to hold the new cipher we are going to use */
1469
            const SSL_CIPHER *new_cipher;
1470
            EVP_PKEY *pkey; /* holds short lived key exchange key */
1471
            /* holds the array of short lived key exchange key (pointers) */
1472
            EVP_PKEY *ks_pkey[OPENSSL_CLIENT_MAX_KEY_SHARES];
1473
            uint16_t ks_group_id[OPENSSL_CLIENT_MAX_KEY_SHARES]; /* The IDs of the keyshare keys */
1474
            size_t num_ks_pkey; /* how many keyshares are there */
1475
            /* used for certificate requests */
1476
            int cert_req;
1477
            /* Certificate types in certificate request message. */
1478
            uint8_t *ctype;
1479
            size_t ctype_len;
1480
            /* Certificate authorities list peer sent */
1481
            STACK_OF(X509_NAME) *peer_ca_names;
1482
            size_t key_block_length;
1483
            unsigned char *key_block;
1484
            const EVP_CIPHER *new_sym_enc;
1485
            const EVP_CIPHER *new_sym_enc_sn;
1486
            const EVP_MD *new_hash;
1487
            int new_mac_pkey_type;
1488
            size_t new_mac_secret_size;
1489
#ifndef OPENSSL_NO_COMP
1490
            const SSL_COMP *new_compression;
1491
#else
1492
            char *new_compression;
1493
#endif
1494
            int cert_request;
1495
            /* Raw values of the cipher list from a client */
1496
            unsigned char *ciphers_raw;
1497
            size_t ciphers_rawlen;
1498
            /* Temporary storage for premaster secret */
1499
            unsigned char *pms;
1500
            size_t pmslen;
1501
#ifndef OPENSSL_NO_PSK
1502
            /* Temporary storage for PSK key */
1503
            unsigned char *psk;
1504
            size_t psklen;
1505
#endif
1506
            /* Signature algorithm we actually use */
1507
            const struct sigalg_lookup_st *sigalg;
1508
            /* Pointer to certificate we use */
1509
            CERT_PKEY *cert;
1510
            /*
1511
             * signature algorithms peer reports: e.g. supported signature
1512
             * algorithms extension for server or as part of a certificate
1513
             * request for client.
1514
             * Keep track of the algorithms for TLS and X.509 usage separately.
1515
             */
1516
            uint16_t *peer_sigalgs;
1517
            uint16_t *peer_cert_sigalgs;
1518
            /* Size of above arrays */
1519
            size_t peer_sigalgslen;
1520
            size_t peer_cert_sigalgslen;
1521
            /* Sigalg peer actually uses */
1522
            const struct sigalg_lookup_st *peer_sigalg;
1523
            /*
1524
             * Set if corresponding CERT_PKEY can be used with current
1525
             * SSL session: e.g. appropriate curve, signature algorithms etc.
1526
             * If zero it can't be used at all.
1527
             */
1528
            uint32_t *valid_flags;
1529
            /*
1530
             * For servers the following masks are for the key and auth algorithms
1531
             * that are supported by the certs below. For clients they are masks of
1532
             * *disabled* algorithms based on the current session.
1533
             */
1534
            uint32_t mask_k;
1535
            uint32_t mask_a;
1536
            /*
1537
             * The following are used by the client to see if a cipher is allowed or
1538
             * not.  It contains the minimum and maximum version the client's using
1539
             * based on what it knows so far.
1540
             */
1541
            int min_ver;
1542
            int max_ver;
1543
        } tmp;
1544
1545
        /* Connection binding to prevent renegotiation attacks */
1546
        unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1547
        size_t previous_client_finished_len;
1548
        unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1549
        size_t previous_server_finished_len;
1550
        int send_connection_binding;
1551
1552
#ifndef OPENSSL_NO_NEXTPROTONEG
1553
        /*
1554
         * Set if we saw the Next Protocol Negotiation extension from our peer.
1555
         */
1556
        int npn_seen;
1557
#endif
1558
1559
        /*
1560
         * ALPN information (we are in the process of transitioning from NPN to
1561
         * ALPN.)
1562
         */
1563
1564
        /*
1565
         * In a server these point to the selected ALPN protocol after the
1566
         * ClientHello has been processed. In a client these contain the protocol
1567
         * that the server selected once the ServerHello has been processed.
1568
         */
1569
        unsigned char *alpn_selected;
1570
        size_t alpn_selected_len;
1571
        /* used by the server to know what options were proposed */
1572
        unsigned char *alpn_proposed;
1573
        size_t alpn_proposed_len;
1574
        /* used by the client to know if it actually sent alpn */
1575
        int alpn_sent;
1576
1577
        /*
1578
         * This is set to true if we believe that this is a version of Safari
1579
         * running on OS X 10.6 or newer. We wish to know this because Safari on
1580
         * 10.8 .. 10.8.3 has broken ECDHE-ECDSA support.
1581
         */
1582
        char is_probably_safari;
1583
1584
        /*
1585
         * Track whether we did a key exchange this handshake or not, so
1586
         * SSL_get_negotiated_group() knows whether to fall back to the
1587
         * value in the SSL_SESSION.
1588
         */
1589
        char did_kex;
1590
        /* For clients: peer temporary key */
1591
        /* The group_id for the key exchange key */
1592
        uint16_t group_id;
1593
        EVP_PKEY *peer_tmp;
1594
        /* The cached group_id candidate for the key exchange key */
1595
        uint16_t group_id_candidate;
1596
    } s3;
1597
1598
    struct dtls1_state_st *d1; /* DTLSv1 variables */
1599
    /* callback that allows applications to peek at protocol messages */
1600
    void (*msg_callback)(int write_p, int version, int content_type,
1601
        const void *buf, size_t len, SSL *ssl, void *arg);
1602
    void *msg_callback_arg;
1603
    int hit; /* reusing a previous session */
1604
    X509_VERIFY_PARAM *param;
1605
    /* Per connection DANE state */
1606
    SSL_DANE dane;
1607
    /* crypto */
1608
    STACK_OF(SSL_CIPHER) *peer_ciphers;
1609
    STACK_OF(SSL_CIPHER) *cipher_list;
1610
    STACK_OF(SSL_CIPHER) *cipher_list_by_id;
1611
    /* TLSv1.3 specific ciphersuites */
1612
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
1613
    /*
1614
     * These are the ones being used, the ones in SSL_SESSION are the ones to
1615
     * be 'copied' into these ones
1616
     */
1617
    uint32_t mac_flags;
1618
    /*
1619
     * The TLS1.3 secrets.
1620
     */
1621
    unsigned char early_secret[EVP_MAX_MD_SIZE];
1622
    unsigned char handshake_secret[EVP_MAX_MD_SIZE];
1623
    unsigned char master_secret[EVP_MAX_MD_SIZE];
1624
    unsigned char resumption_master_secret[EVP_MAX_MD_SIZE];
1625
    unsigned char client_finished_secret[EVP_MAX_MD_SIZE];
1626
    unsigned char server_finished_secret[EVP_MAX_MD_SIZE];
1627
    unsigned char server_finished_hash[EVP_MAX_MD_SIZE];
1628
    unsigned char handshake_traffic_hash[EVP_MAX_MD_SIZE];
1629
    unsigned char client_app_traffic_secret[EVP_MAX_MD_SIZE];
1630
    unsigned char server_app_traffic_secret[EVP_MAX_MD_SIZE];
1631
    unsigned char exporter_master_secret[EVP_MAX_MD_SIZE];
1632
    unsigned char early_exporter_master_secret[EVP_MAX_MD_SIZE];
1633
1634
    /* session info */
1635
    /* client cert? */
1636
    /* This is used to hold the server certificate used */
1637
    struct cert_st /* CERT */ *cert;
1638
1639
    /*
1640
     * The hash of all messages prior to the CertificateVerify, and the length
1641
     * of that hash.
1642
     */
1643
    unsigned char cert_verify_hash[EVP_MAX_MD_SIZE];
1644
    size_t cert_verify_hash_len;
1645
1646
    /* Flag to indicate whether we should send a HelloRetryRequest or not */
1647
    enum { SSL_HRR_NONE = 0,
1648
        SSL_HRR_PENDING,
1649
        SSL_HRR_COMPLETE } hello_retry_request;
1650
1651
    /*
1652
     * the session_id_context is used to ensure sessions are only reused in
1653
     * the appropriate context
1654
     */
1655
    size_t sid_ctx_length;
1656
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1657
    /* This can also be in the session once a session is established */
1658
    SSL_SESSION *session;
1659
    /* TLSv1.3 PSK session */
1660
    SSL_SESSION *psksession;
1661
    unsigned char *psksession_id;
1662
    size_t psksession_id_len;
1663
    /* Default generate session ID callback. */
1664
    GEN_SESSION_CB generate_session_id;
1665
    /*
1666
     * The temporary TLSv1.3 session id. This isn't really a session id at all
1667
     * but is a random value sent in the legacy session id field.
1668
     */
1669
    unsigned char tmp_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
1670
    size_t tmp_session_id_len;
1671
    /* Used in SSL3 */
1672
    /*
1673
     * 0 don't care about verify failure.
1674
     * 1 fail if verify fails
1675
     */
1676
    uint32_t verify_mode;
1677
    /* fail if callback returns 0 */
1678
    int (*verify_callback)(int ok, X509_STORE_CTX *ctx);
1679
    /* optional informational callback */
1680
    void (*info_callback)(const SSL *ssl, int type, int val);
1681
    /* error bytes to be written */
1682
    int error;
1683
    /* actual code */
1684
    int error_code;
1685
#ifndef OPENSSL_NO_PSK
1686
    SSL_psk_client_cb_func psk_client_callback;
1687
    SSL_psk_server_cb_func psk_server_callback;
1688
#endif
1689
    SSL_psk_find_session_cb_func psk_find_session_cb;
1690
    SSL_psk_use_session_cb_func psk_use_session_cb;
1691
1692
    /* Verified chain of peer */
1693
    STACK_OF(X509) *verified_chain;
1694
    long verify_result;
1695
    /*
1696
     * What we put in certificate_authorities extension for TLS 1.3
1697
     * (ClientHello and CertificateRequest) or just client cert requests for
1698
     * earlier versions. If client_ca_names is populated then it is only used
1699
     * for client cert requests, and in preference to ca_names.
1700
     */
1701
    STACK_OF(X509_NAME) *ca_names;
1702
    STACK_OF(X509_NAME) *client_ca_names;
1703
    /* protocol behaviour */
1704
    uint64_t options;
1705
    /* API behaviour */
1706
    uint32_t mode;
1707
    int min_proto_version;
1708
    int max_proto_version;
1709
    size_t max_cert_list;
1710
    int first_packet;
1711
    /*
1712
     * What was passed in ClientHello.legacy_version. Used for RSA pre-master
1713
     * secret and (D)TLS (<=1.2) rollback check
1714
     */
1715
    int client_version;
1716
    /*
1717
     * If we're using more than one pipeline how should we divide the data
1718
     * up between the pipes?
1719
     */
1720
    size_t split_send_fragment;
1721
    /*
1722
     * Maximum amount of data to send in one fragment. actual record size can
1723
     * be more than this due to padding and MAC overheads.
1724
     */
1725
    size_t max_send_fragment;
1726
    /* Up to how many pipelines should we use? If 0 then 1 is assumed */
1727
    size_t max_pipelines;
1728
1729
    struct {
1730
        /* Built-in extension flags */
1731
        uint8_t extflags[TLSEXT_IDX_num_builtins];
1732
        /* TLS extension debug callback */
1733
        void (*debug_cb)(SSL *s, int client_server, int type,
1734
            const unsigned char *data, int len, void *arg);
1735
        void *debug_arg;
1736
        char *hostname;
1737
        /* certificate status request info */
1738
        /* Status type or -1 if no status type */
1739
        int status_type;
1740
        /* Raw extension data, if seen */
1741
        unsigned char *scts;
1742
        /* Length of raw extension data, if seen */
1743
        uint16_t scts_len;
1744
1745
        struct {
1746
            /* OCSP status request only */
1747
            STACK_OF(OCSP_RESPID) *ids;
1748
            X509_EXTENSIONS *exts;
1749
            /* OCSP response received or to be sent */
1750
            unsigned char *resp;
1751
            size_t resp_len;
1752
            STACK_OF(OCSP_RESPONSE) *resp_ex;
1753
        } ocsp;
1754
1755
        /* TLS 1.3 tickets requested by the application. */
1756
        int extra_tickets_expected;
1757
1758
        /*
1759
         * Peer's advertised ec_point_formats list (TLS 1.2 and below),
1760
         * retained as received so SSL_get0_ec_point_formats() can return
1761
         * it verbatim.  Point format no longer influences cert selection
1762
         * or acceptance; the parse hook validates RFC 4492/8422 section
1763
         * 5.1.2 ("uncompressed" must be present) inline.
1764
         */
1765
        size_t peer_ecpointformats_len;
1766
        unsigned char *peer_ecpointformats;
1767
1768
        /* our list */
1769
        size_t supportedgroups_len;
1770
        uint16_t *supportedgroups;
1771
        /* peer's list */
1772
        size_t peer_supportedgroups_len;
1773
        uint16_t *peer_supportedgroups;
1774
1775
        /* key shares */
1776
        size_t keyshares_len;
1777
        uint16_t *keyshares;
1778
        /* supported groups tuples */
1779
        size_t tuples_len;
1780
        size_t *tuples;
1781
1782
        /* TLS Session Ticket extension override */
1783
        TLS_SESSION_TICKET_EXT *session_ticket;
1784
        /* TLS Session Ticket extension callback */
1785
        tls_session_ticket_ext_cb_fn session_ticket_cb;
1786
        void *session_ticket_cb_arg;
1787
        /* TLS pre-shared secret session resumption */
1788
        tls_session_secret_cb_fn session_secret_cb;
1789
        void *session_secret_cb_arg;
1790
        /*
1791
         * For a client, this contains the list of supported protocols in wire
1792
         * format.
1793
         */
1794
        unsigned char *alpn;
1795
        size_t alpn_len;
1796
        /*
1797
         * Next protocol negotiation. For the client, this is the protocol that
1798
         * we sent in NextProtocol and is set when handling ServerHello
1799
         * extensions. For a server, this is the client's selected_protocol from
1800
         * NextProtocol and is set when handling the NextProtocol message, before
1801
         * the Finished message.
1802
         */
1803
        unsigned char *npn;
1804
        size_t npn_len;
1805
1806
        /* The available PSK key exchange modes */
1807
        int psk_kex_mode;
1808
1809
        /* Are we expecting to receive early data? */
1810
        int early_data;
1811
1812
        /* May be sent by a server in HRR. Must be echoed back in ClientHello */
1813
        unsigned char *tls13_cookie;
1814
        size_t tls13_cookie_len;
1815
1816
        /*
1817
         * Maximum Fragment Length as per RFC 4366.
1818
         * If this member contains one of the allowed values (1-4)
1819
         * then we should include Maximum Fragment Length Negotiation
1820
         * extension in Client Hello.
1821
         * Please note that value of this member does not have direct
1822
         * effect. The actual (binding) value is stored in SSL_SESSION,
1823
         * as this extension is optional on server side.
1824
         */
1825
        uint8_t max_fragment_len_mode;
1826
1827
        /*
1828
         * On the client side the number of ticket identities we sent in the
1829
         * ClientHello. On the server side the identity of the ticket we
1830
         * selected.
1831
         */
1832
        int tick_identity;
1833
1834
        /*
1835
         * Cached result of the resumption ticket age/lifetime check for the
1836
         * ClientHello under construction. Time-dependent, double-checked
1837
         * within the same flight (see tls13_check_tick_lifetime_hint()).
1838
         */
1839
        uint32_t tick_age_ms;
1840
1841
        /*
1842
         * The first-offered PSK, the one that keys any 0-RTT, recorded while
1843
         * the ClientHello is built -- the resumption session when we offer it,
1844
         * else the external psksession; NULL when no 0-RTT is offered. Held
1845
         * (up-ref'd) so it stays valid across the post-ServerHello swap, and
1846
         * read by the binder, the early-key derivation, the early exporter and
1847
         * the byte-budget lookup. Freed at handshake reset and connection free.
1848
         */
1849
        SSL_SESSION *early_data_session;
1850
1851
        /* This is the list of algorithms the peer supports that we also support */
1852
        int compress_certificate_from_peer[TLSEXT_comp_cert_limit];
1853
1854
        uint8_t client_cert_type;
1855
        uint8_t client_cert_type_ctos;
1856
        uint8_t server_cert_type;
1857
        uint8_t server_cert_type_ctos;
1858
1859
#ifndef OPENSSL_NO_ECH
1860
        OSSL_ECH_CONN ech;
1861
#endif
1862
1863
        /* RFC 8701 GREASE */
1864
        uint8_t grease_seed[OSSL_GREASE_LAST_INDEX + 1];
1865
1866
        /* "bool" fields go last, for slightly better packing */
1867
        bool grease_seeded;
1868
1869
        /* Expect OCSP CertificateStatus message */
1870
        bool status_expected;
1871
1872
        /* RFC4507 session ticket expected to be received or sent */
1873
        bool ticket_expected;
1874
1875
        /* Set to one if we have negotiated ETM */
1876
        bool use_etm;
1877
1878
        /* Is the session perhaps suitable for early data? */
1879
        bool early_data_ok;
1880
1881
        /* Was the session found unsuitable for early data? */
1882
        bool early_data_suppressed;
1883
1884
        /*
1885
         * Cached result of the resumption ticket age/lifetime check for the
1886
         * ClientHello under construction. Time-dependent, double-checked
1887
         * within the same flight (see tls13_check_tick_lifetime_hint()).
1888
         */
1889
        bool tick_age_checked;
1890
        bool tick_age_ok;
1891
1892
        /* Have we received a cookie from the client? */
1893
        bool cookieok;
1894
1895
        /* indicate that we sent the extension, so we'll accept it */
1896
        bool compress_certificate_sent;
1897
    } ext;
1898
1899
    /*
1900
     * Parsed form of the ClientHello, kept around across client_hello_cb
1901
     * calls.
1902
     */
1903
    CLIENTHELLO_MSG *clienthello;
1904
1905
    /*-
1906
     * no further mod of servername
1907
     * 0 : call the servername extension callback.
1908
     * 1 : prepare 2, allow last ack just after in server callback.
1909
     * 2 : don't call servername callback, no ack in server hello
1910
     */
1911
    int servername_done;
1912
#ifndef OPENSSL_NO_CT
1913
    /*
1914
     * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
1915
     * If they are not, the connection should be aborted.
1916
     */
1917
    ssl_ct_validation_cb ct_validation_callback;
1918
    /* User-supplied argument that is passed to the ct_validation_callback */
1919
    void *ct_validation_callback_arg;
1920
    /*
1921
     * Consolidated stack of SCTs from all sources.
1922
     * Lazily populated by CT_get_peer_scts(SSL*)
1923
     */
1924
    STACK_OF(SCT) *scts;
1925
    /* Have we attempted to find/parse SCTs yet? */
1926
    int scts_parsed;
1927
#endif
1928
    SSL_CTX *session_ctx; /* initial ctx, used to store sessions */
1929
#ifndef OPENSSL_NO_SRTP
1930
    /* What we'll do */
1931
    STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
1932
    /* What's been chosen */
1933
    SRTP_PROTECTION_PROFILE *srtp_profile;
1934
#endif
1935
    /*-
1936
     * 1 if we are renegotiating.
1937
     * 2 if we are a server and are inside a handshake
1938
     * (i.e. not just sending a HelloRequest)
1939
     */
1940
    int renegotiate;
1941
    /* If sending a KeyUpdate is pending */
1942
    int key_update;
1943
    /* Post-handshake authentication state */
1944
    SSL_PHA_STATE post_handshake_auth;
1945
    int pha_enabled;
1946
    uint8_t *pha_context;
1947
    size_t pha_context_len;
1948
    int certreqs_sent;
1949
    EVP_MD_CTX *pha_dgst; /* this is just the digest through ClientFinished */
1950
1951
#ifndef OPENSSL_NO_SRP
1952
    /* ctx for SRP authentication */
1953
    SRP_CTX srp_ctx;
1954
#endif
1955
    /*
1956
     * Callback for disabling session caching and ticket support on a session
1957
     * basis, depending on the chosen cipher.
1958
     */
1959
    int (*not_resumable_session_cb)(SSL *ssl, int is_forward_secure);
1960
1961
    /* Record layer data */
1962
    RECORD_LAYER rlayer;
1963
1964
    /* Default password callback. */
1965
    pem_password_cb *default_passwd_callback;
1966
    /* Default password callback user data. */
1967
    void *default_passwd_callback_userdata;
1968
    /* Async Job info */
1969
    ASYNC_JOB *job;
1970
    ASYNC_WAIT_CTX *waitctx;
1971
    size_t asyncrw;
1972
1973
    /*
1974
     * The maximum number of bytes advertised in session tickets that can be
1975
     * sent as early data.
1976
     */
1977
    uint32_t max_early_data;
1978
    /*
1979
     * The maximum number of bytes of early data that a server will tolerate
1980
     * (which should be at least as much as max_early_data).
1981
     */
1982
    uint32_t recv_max_early_data;
1983
1984
    /*
1985
     * The number of bytes of early data received so far. If we accepted early
1986
     * data then this is a count of the plaintext bytes. If we rejected it then
1987
     * this is a count of the ciphertext bytes.
1988
     */
1989
    uint32_t early_data_count;
1990
1991
    /* The number of TLS1.3 tickets to automatically send */
1992
    size_t num_tickets;
1993
    /* The number of TLS1.3 tickets actually sent so far */
1994
    size_t sent_tickets;
1995
    /* The next nonce value to use when we send a ticket on this connection */
1996
    uint64_t next_ticket_nonce;
1997
1998
    /* Callback to determine if early_data is acceptable or not */
1999
    SSL_allow_early_data_cb_fn allow_early_data_cb;
2000
    void *allow_early_data_cb_data;
2001
2002
    /* Callback for SSL async handling */
2003
    SSL_async_callback_fn async_cb;
2004
    void *async_cb_arg;
2005
2006
    /*
2007
     * Signature algorithms shared by client and server: cached because these
2008
     * are used most often.
2009
     */
2010
    const struct sigalg_lookup_st **shared_sigalgs;
2011
    size_t shared_sigalgslen;
2012
2013
#ifndef OPENSSL_NO_COMP_ALG
2014
    /* certificate compression preferences */
2015
    int cert_comp_prefs[TLSEXT_comp_cert_limit];
2016
#endif
2017
2018
    /* Certificate Type stuff - for RPK vs X.509 */
2019
    unsigned char *client_cert_type;
2020
    size_t client_cert_type_len;
2021
    unsigned char *server_cert_type;
2022
    size_t server_cert_type_len;
2023
2024
    /* DTLS 1.3 needs to know when we have processed the Client/Server Hello */
2025
    int dtls13_process_hello;
2026
};
2027
2028
/*
2029
 * Structure containing table entry of values associated with the signature
2030
 * algorithms (signature scheme) extension
2031
 */
2032
typedef struct sigalg_lookup_st {
2033
    /* TLS 1.3 signature scheme name */
2034
    const char *name;
2035
    /* TLS 1.2 signature scheme name */
2036
    const char *name12;
2037
    /* Raw value used in extension */
2038
    uint16_t sigalg;
2039
    /* NID of hash algorithm or NID_undef if no hash */
2040
    int hash;
2041
    /* Index of hash algorithm or -1 if no hash algorithm */
2042
    int hash_idx;
2043
    /* NID of signature algorithm */
2044
    int sig;
2045
    /* Index of signature algorithm */
2046
    int sig_idx;
2047
    /* Combined hash and signature NID, if any */
2048
    int sigandhash;
2049
    /* Required public key curve (ECDSA only) */
2050
    int curve;
2051
    /* Whether this signature algorithm is actually available for use */
2052
    int available;
2053
    /* Whether this signature algorithm is by default advertised */
2054
    int advertise;
2055
    /* Supported protocol ranges */
2056
    int mintls;
2057
    int maxtls;
2058
    int mindtls;
2059
    int maxdtls;
2060
} SIGALG_LOOKUP;
2061
2062
typedef enum downgrade_en {
2063
    DOWNGRADE_NONE,
2064
    DOWNGRADE_TO_1_2,
2065
    DOWNGRADE_TO_1_1
2066
} DOWNGRADE;
2067
2068
/* DTLS structures */
2069
2070
#ifndef OPENSSL_NO_SCTP
2071
#define DTLS1_SCTP_AUTH_LABEL "EXPORTER_DTLS_OVER_SCTP"
2072
#endif
2073
2074
/* Max MTU overhead we know about so far is 40 for IPv6 + 8 for UDP */
2075
0
#define DTLS1_MAX_MTU_OVERHEAD 48
2076
2077
struct dtls1_retransmit_state {
2078
    const OSSL_RECORD_METHOD *wrlmethod;
2079
    OSSL_RECORD_LAYER *wrl;
2080
};
2081
2082
struct hm_header_st {
2083
    unsigned char type;
2084
    size_t msg_len;
2085
    unsigned short seq;
2086
    size_t frag_off;
2087
    size_t frag_len;
2088
};
2089
2090
typedef struct hm_fragment_st {
2091
    struct hm_header_st msg_header;
2092
    unsigned char *fragment;
2093
    unsigned char *reassembly;
2094
} hm_fragment;
2095
2096
typedef struct pqueue_st pqueue;
2097
typedef struct pitem_st pitem;
2098
2099
struct pqueue_st {
2100
    pitem *items;
2101
    int count;
2102
};
2103
2104
struct pitem_st {
2105
    unsigned char priority[8]; /* 64-bit value in big-endian encoding */
2106
    void *data;
2107
    pitem *next;
2108
};
2109
2110
typedef struct pitem_st *piterator;
2111
2112
pitem *pitem_new(unsigned char *prio64be, void *data);
2113
pitem *pitem_new_u64(uint64_t prio, void *data);
2114
void pitem_free(pitem *item);
2115
pqueue *pqueue_new(void);
2116
void pqueue_free(pqueue *pq);
2117
pitem *pqueue_insert(pqueue *pq, pitem *item);
2118
pitem *pqueue_peek(pqueue *pq);
2119
pitem *pqueue_pop(pqueue *pq);
2120
pitem *pqueue_find(pqueue *pq, unsigned char *prio64be);
2121
pitem *pqueue_find_u64(pqueue *pq, uint64_t prio);
2122
pitem *pqueue_iterator(pqueue *pq);
2123
pitem *pqueue_next(piterator *iter);
2124
size_t pqueue_size(pqueue *pq);
2125
2126
typedef struct dtls_msg_info_st {
2127
    unsigned char record_type;
2128
    unsigned char msg_type;
2129
    size_t msg_body_len;
2130
    unsigned short msg_seq;
2131
} dtls_msg_info;
2132
2133
/* rfc9147, section 4 */
2134
typedef struct dtls1_record_number_st DTLS1_RECORD_NUMBER;
2135
2136
struct dtls1_record_number_st {
2137
    uint64_t epoch;
2138
    uint64_t seqnum;
2139
    OSSL_LIST_MEMBER(record_number, DTLS1_RECORD_NUMBER);
2140
};
2141
2142
0
DEFINE_LIST_OF(record_number, DTLS1_RECORD_NUMBER);
Unexecuted instantiation: rec_layer_d1.c:ossl_list_record_number_insert_tail
Unexecuted instantiation: statem_dtls.c:ossl_list_record_number_insert_tail
Unexecuted instantiation: statem_dtls.c:ossl_list_record_number_head
Unexecuted instantiation: statem_dtls.c:ossl_list_record_number_next
Unexecuted instantiation: statem_dtls.c:ossl_list_record_number_remove
Unexecuted instantiation: d1_lib.c:ossl_list_record_number_head
Unexecuted instantiation: d1_lib.c:ossl_list_record_number_next
Unexecuted instantiation: d1_lib.c:ossl_list_record_number_remove
2143
0
2144
0
DTLS1_RECORD_NUMBER *dtls1_record_number_new(uint64_t epoch, uint64_t seqnum);
2145
0
2146
0
void ossl_list_record_number_elem_free(OSSL_LIST(record_number) * p_list);
2147
0
2148
0
typedef struct dtls_sent_msg_st {
2149
0
    dtls_msg_info msg_info;
2150
0
    OSSL_LIST(record_number)
2151
0
    rec_nums;
2152
0
    unsigned char *msg_buf;
2153
0
    struct dtls1_retransmit_state saved_retransmit_state;
2154
0
} dtls_sent_msg;
2155
0
2156
0
int dtls_any_sent_messages_are_missing_acknowledge(SSL_CONNECTION *s);
2157
0
2158
0
static ossl_inline int dtls_msg_needs_ack(int sentbyserver, unsigned char msgtype)
2159
0
{
2160
0
    switch (msgtype) {
2161
0
    case SSL3_MT_NEWSESSION_TICKET:
2162
0
    case SSL3_MT_KEY_UPDATE:
2163
0
        return 1;
2164
2165
0
    case SSL3_MT_CERTIFICATE:
2166
0
    case SSL3_MT_COMPRESSED_CERTIFICATE:
2167
0
    case SSL3_MT_CERTIFICATE_VERIFY:
2168
0
    case SSL3_MT_FINISHED:
2169
0
        if (!sentbyserver)
2170
0
            return 1;
2171
        /* fall-through */
2172
0
    default:
2173
0
        return 0;
2174
0
    }
2175
0
}
Unexecuted instantiation: methods.c:dtls_msg_needs_ack
Unexecuted instantiation: s3_lib.c:dtls_msg_needs_ack
Unexecuted instantiation: s3_msg.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_cert.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_ciph.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_init.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_lib.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_mcnf.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_rsa.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_sess.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_stat.c:dtls_msg_needs_ack
Unexecuted instantiation: t1_lib.c:dtls_msg_needs_ack
Unexecuted instantiation: tls13_enc.c:dtls_msg_needs_ack
Unexecuted instantiation: tls_depr.c:dtls_msg_needs_ack
Unexecuted instantiation: tls_srp.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_impl.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_method.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_obj.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_port.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_record_rx.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_record_shared.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_record_tx.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_record_util.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_thread_assist.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_tls.c:dtls_msg_needs_ack
Unexecuted instantiation: rec_layer_d1.c:dtls_msg_needs_ack
Unexecuted instantiation: rec_layer_s3.c:dtls_msg_needs_ack
Unexecuted instantiation: dtls_meth.c:dtls_msg_needs_ack
Unexecuted instantiation: tls13_meth.c:dtls_msg_needs_ack
Unexecuted instantiation: tls1_meth.c:dtls_msg_needs_ack
Unexecuted instantiation: tls_common.c:dtls_msg_needs_ack
Unexecuted instantiation: tls_multib.c:dtls_msg_needs_ack
Unexecuted instantiation: tlsany_meth.c:dtls_msg_needs_ack
Unexecuted instantiation: extensions.c:dtls_msg_needs_ack
Unexecuted instantiation: extensions_clnt.c:dtls_msg_needs_ack
Unexecuted instantiation: extensions_cust.c:dtls_msg_needs_ack
Unexecuted instantiation: extensions_srvr.c:dtls_msg_needs_ack
Unexecuted instantiation: statem.c:dtls_msg_needs_ack
Unexecuted instantiation: statem_clnt.c:dtls_msg_needs_ack
Unexecuted instantiation: statem_dtls.c:dtls_msg_needs_ack
Unexecuted instantiation: statem_lib.c:dtls_msg_needs_ack
Unexecuted instantiation: statem_srvr.c:dtls_msg_needs_ack
Unexecuted instantiation: ech_helper.c:dtls_msg_needs_ack
Unexecuted instantiation: ech_internal.c:dtls_msg_needs_ack
Unexecuted instantiation: ech_store.c:dtls_msg_needs_ack
Unexecuted instantiation: d1_lib.c:dtls_msg_needs_ack
Unexecuted instantiation: d1_msg.c:dtls_msg_needs_ack
Unexecuted instantiation: d1_srtp.c:dtls_msg_needs_ack
Unexecuted instantiation: d1_transcript.c:dtls_msg_needs_ack
Unexecuted instantiation: dtls_record_rx.c:dtls_msg_needs_ack
Unexecuted instantiation: pqueue.c:dtls_msg_needs_ack
Unexecuted instantiation: s3_enc.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_asn1.c:dtls_msg_needs_ack
Unexecuted instantiation: ssl_conf.c:dtls_msg_needs_ack
Unexecuted instantiation: t1_enc.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_channel.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_engine.c:dtls_msg_needs_ack
Unexecuted instantiation: quic_rx_depack.c:dtls_msg_needs_ack
Unexecuted instantiation: poll_immediate.c:dtls_msg_needs_ack
2176
2177
typedef struct dtls1_state_st {
2178
    unsigned char cookie[DTLS1_COOKIE_LENGTH];
2179
    size_t cookie_len;
2180
    unsigned int cookie_verified;
2181
    /* handshake message numbers */
2182
    unsigned short handshake_write_seq;
2183
    unsigned short next_handshake_write_seq;
2184
    unsigned short handshake_read_seq;
2185
    /* Buffered received handshake messages */
2186
    pqueue rcvd_messages;
2187
    /* Buffered (sent) handshake records */
2188
    pqueue sent_messages;
2189
    /* Flag to indicate current HelloVerifyRequest status */
2190
    enum { SSL_HVR_NONE = 0,
2191
        SSL_HVR_RECEIVED,
2192
        SSL_HVR_SENT } hello_verify_request;
2193
    DOWNGRADE downgrade_after_hvr; /* Only used by a stateful server */
2194
    size_t link_mtu; /* max on-the-wire DTLS packet size */
2195
    size_t mtu; /* max DTLS packet size */
2196
    dtls_msg_info w_msg;
2197
    unsigned short r_msg_seq;
2198
    /* Number of alerts received so far */
2199
    unsigned int timeout_num_alerts;
2200
    /*
2201
     * Indicates when the last handshake msg sent will timeout
2202
     */
2203
    OSSL_TIME next_timeout;
2204
    /* Timeout duration */
2205
    unsigned int timeout_duration_us;
2206
2207
    unsigned int retransmitting;
2208
    unsigned int has_change_cipher_spec;
2209
#ifndef OPENSSL_NO_SCTP
2210
    int shutdown_received;
2211
#endif
2212
2213
    /* Sequence numbers that are to be acknowledged */
2214
    OSSL_LIST(record_number)
2215
    ack_rec_num;
2216
2217
    DTLS_timer_cb timer_cb;
2218
2219
#ifndef OPENSSL_NO_SOCK
2220
    /*
2221
     * Peer address for listener-created connections. When set, the record
2222
     * layer will use BIO_sendmmsg() with this address for writes instead
2223
     * of BIO_write(). This allows multiple connections to share the
2224
     * listener's network BIO.
2225
     */
2226
    BIO_ADDR peer_addr;
2227
#endif
2228
2229
#ifndef OPENSSL_NO_DTLS
2230
    /*
2231
     * DTLS_RX structure is used by the DTLS Listener and
2232
     * contains the DGRAM_DEMUX and DGRAM_URXE_LIST of
2233
     * pending packets.
2234
     */
2235
    DTLS_RX *rx;
2236
2237
    /*
2238
     * Reference to the parent listener for connections created via
2239
     * SSL_accept_connection(). This allows the connection to trigger
2240
     * the listener's demux pump when reading data.
2241
     */
2242
    SSL *listener;
2243
2244
    /*
2245
     * Timestamp when this connection was created (for listener-created
2246
     * connections). Used to detect and clean up stale pending connections
2247
     * that haven't completed their handshake within the timeout period.
2248
     */
2249
    OSSL_TIME created_at;
2250
2251
    /*
2252
     * Set when this connection is being driven by dtls_listener_drive_pending().
2253
     * Used to prevent multiple threads from driving the same connection
2254
     * concurrently and to allow the demux pump to be called without holding
2255
     * the listener mutex.
2256
     */
2257
    unsigned int being_driven : 1;
2258
2259
    /*
2260
     * Blocking mode requested for this connection, as a DTLS_BLOCKING_MODE.
2261
     * Defaults to inheriting from the listener it came from.
2262
     */
2263
    unsigned int req_blocking_mode : 2;
2264
2265
    /*
2266
     * Set while the listener itself is driving this connection's handshake, to
2267
     * stop it blocking. The listener drives pending connections from inside its
2268
     * own tick, so a connection which blocked there would stop the listener
2269
     * making any further progress, including the progress being waited for.
2270
     */
2271
    unsigned int force_nonblocking : 1;
2272
#endif
2273
2274
} DTLS1_STATE;
2275
2276
#if !defined(OPENSSL_NO_DTLS) && !defined(OPENSSL_NO_SOCK)
2277
/*
2278
 * Blocking mode of a DTLS listener or of a connection created from one.
2279
 *
2280
 * A connection set to INHERIT follows its listener, and a listener set to
2281
 * INHERIT means blocking, so blocking is the default throughout unless an
2282
 * application asks otherwise. This mirrors QUIC_BLOCKING_MODE.
2283
 */
2284
enum {
2285
    DTLS_BLOCKING_MODE_INHERIT,
2286
    DTLS_BLOCKING_MODE_NONBLOCKING,
2287
    DTLS_BLOCKING_MODE_BLOCKING
2288
};
2289
2290
/*
2291
 * Define stack of SSL for DTLS listener incoming connections.
2292
 */
2293
DEFINE_STACK_OF(SSL)
2294
2295
/*
2296
 * Default maximum number of pending connections for DTLS listeners.
2297
 */
2298
0
#define DTLS_LISTENER_DEFAULT_MAX_PENDING_CONNS 256
2299
2300
/*
2301
 * Default maximum size in bytes of a datagram a DTLS listener will receive.
2302
 * A DTLS 1.3 ClientHello carrying large (e.g. post-quantum) key shares can
2303
 * exceed the 1500-byte Ethernet MTU; default a little above it so that such a
2304
 * ClientHello, when sent unfragmented, is received whole rather than truncated.
2305
 * Applied to the listener's demuxer.
2306
 */
2307
0
#define DTLS_LISTENER_DEFAULT_MAX_DGRAM_SIZE 2000
2308
2309
/*
2310
 * Upper bound for the DTLS listener receive datagram size: nothing larger than
2311
 * the maximum UDP payload can ever arrive. It may be raised up to this ceiling
2312
 * via SSL_set_value_uint(SSL_VALUE_DTLS_LISTENER_MAX_DGRAM_SIZE).
2313
 */
2314
0
#define DTLS_LISTENER_MAX_DGRAM_SIZE 65535
2315
2316
/*
2317
 * DTLS listener SSL object type. This implements the API personality
2318
 * layer for DTLS listener objects, providing server-side connection
2319
 * demultiplexing for DTLS 1.3.
2320
 */
2321
typedef struct dtls_listener_st {
2322
    /* SSL object common header. */
2323
    struct ssl_st ssl;
2324
2325
    /*
2326
     * Mutex protecting listener-owned data structures accessed across threads:
2327
     * - pending_conns: pending connection lookup table
2328
     * - established_conns: established connection lookup table
2329
     * - incoming_connections: queue of completed connections awaiting accept
2330
     *
2331
     * Accessed from:
2332
     * - Listener thread: packet handling, driving handshakes
2333
     * - Connection thread: unregistering via SSL_free -> dtls1_free
2334
     */
2335
    CRYPTO_MUTEX *mutex;
2336
2337
    /* Datagram demultiplexer for incoming connections. */
2338
    DGRAM_DEMUX *demux;
2339
2340
    /* The network BIOs for sending and receiving datagrams. */
2341
    BIO *net_rbio;
2342
    BIO *net_wbio;
2343
2344
    /* Queue of incoming connections awaiting accept. */
2345
    STACK_OF(SSL) *incoming_connections;
2346
2347
    /*
2348
     * Use DGRAM_CONN_LOOKUP to find pending connections.
2349
     */
2350
    DGRAM_CONN_LOOKUP *pending_conns;
2351
2352
    /*
2353
     * Use DGRAM_CONN_LOOKUP to keep track of established connections.
2354
     */
2355
    DGRAM_CONN_LOOKUP *established_conns;
2356
2357
    /* Have we started listening yet? */
2358
    TSAN_QUALIFIER int listening;
2359
2360
    /*
2361
     * Set by ossl_dtls_tick() when the network BIO returns a hard error.
2362
     * Once set, ossl_dtls_accept_connection() returns NULL immediately.
2363
     */
2364
    int fatal;
2365
2366
    /* Require HelloVerifyRequest + cookie for DTLS 1.0/1.2 */
2367
    unsigned int require_hvr_cookie : 1;
2368
2369
    /* Require HelloRetryRequest + cookie for DTLS 1.3 */
2370
    unsigned int require_hrr_cookie : 1;
2371
2372
    /* Using the notifier architecture */
2373
    unsigned int have_notifier : 1;
2374
2375
    /* Notifier has been signalled */
2376
    int signalled_notifier;
2377
2378
    /*
2379
     * Time callback for customizable time source (primarily for testing).
2380
     * If NULL, ossl_time_now() is used.
2381
     */
2382
    OSSL_TIME (*now_cb)(void *arg);
2383
    void *now_cb_arg;
2384
2385
    /*
2386
     * Timeout for pending connections. Connections that haven't completed
2387
     * their handshake within this duration are considered stale and removed.
2388
     * Default: 30 seconds. Set to ossl_time_infinite() to disable.
2389
     */
2390
    OSSL_TIME pending_timeout;
2391
2392
    /*
2393
     * Maximum number of pending connections allowed.
2394
     * When this limit is reached, new connection attempts are rejected.
2395
     *
2396
     * Default: DTLS_LISTENER_DEFAULT_MAX_PENDING_CONNS
2397
     * This limit cannot be disabled.
2398
     */
2399
    size_t max_pending_conns;
2400
2401
    /*
2402
     * Largest datagram the listener will receive, chosen by the application.
2403
     *
2404
     * Default: DTLS_LISTENER_DEFAULT_MAX_DGRAM_SIZE
2405
     */
2406
    size_t max_dgram_size;
2407
2408
    CRYPTO_CONDVAR *notifier_cv;
2409
2410
    /*
2411
     * Notifier for signaling events related to this listener.
2412
     */
2413
    RIO_NOTIFIER notifier;
2414
2415
    /*
2416
     * Count of threads currently blocked waiting in poll().
2417
     */
2418
    size_t cur_blocking_waiters;
2419
2420
    /*
2421
     * Blocking mode requested for this listener, as a DTLS_BLOCKING_MODE.
2422
     * INHERIT here means blocking, there being nothing further to inherit
2423
     * from.
2424
     */
2425
    unsigned int req_blocking_mode : 2;
2426
} DTLS_LISTENER;
2427
2428
#endif /* !OPENSSL_NO_DTLS && !OPENSSL_NO_SOCK */
2429
2430
/*
2431
 * From ECC-TLS draft, used in encoding the curve type in ECParameters
2432
 */
2433
#define EXPLICIT_PRIME_CURVE_TYPE 1
2434
#define EXPLICIT_CHAR2_CURVE_TYPE 2
2435
0
#define NAMED_CURVE_TYPE 3
2436
2437
#ifndef OPENSSL_NO_COMP_ALG
2438
struct ossl_comp_cert_st {
2439
    unsigned char *data;
2440
    size_t len;
2441
    size_t orig_len;
2442
    CRYPTO_REF_COUNT references;
2443
    int alg;
2444
};
2445
typedef struct ossl_comp_cert_st OSSL_COMP_CERT;
2446
2447
void OSSL_COMP_CERT_free(OSSL_COMP_CERT *c);
2448
int OSSL_COMP_CERT_up_ref(OSSL_COMP_CERT *c);
2449
#endif
2450
2451
struct cert_pkey_st {
2452
    X509 *x509;
2453
    EVP_PKEY *privatekey;
2454
    /* Chain for this certificate */
2455
    STACK_OF(X509) *chain;
2456
    /*-
2457
     * serverinfo data for this certificate.  The data is in TLS Extension
2458
     * wire format, specifically it's a series of records like:
2459
     *   uint16_t extension_type; // (RFC 5246, 7.4.1.4, Extension)
2460
     *   uint16_t length;
2461
     *   uint8_t data[length];
2462
     */
2463
    unsigned char *serverinfo;
2464
    size_t serverinfo_length;
2465
#ifndef OPENSSL_NO_COMP_ALG
2466
    /* Compressed certificate data - index 0 is unused */
2467
    OSSL_COMP_CERT *comp_cert[TLSEXT_comp_cert_limit];
2468
    int cert_comp_used;
2469
#endif
2470
};
2471
/* Retrieve Suite B flags */
2472
0
#define tls1_suiteb(s) (s->cert->cert_flags & SSL_CERT_FLAG_SUITEB_128_LOS)
2473
/* Uses to check strict mode: suite B modes are always strict */
2474
#define SSL_CERT_FLAGS_CHECK_TLS_STRICT \
2475
0
    (SSL_CERT_FLAG_SUITEB_128_LOS | SSL_CERT_FLAG_TLS_STRICT)
2476
2477
typedef enum {
2478
    ENDPOINT_CLIENT = 0,
2479
    ENDPOINT_SERVER,
2480
    ENDPOINT_BOTH
2481
} ENDPOINT;
2482
2483
typedef struct {
2484
    unsigned short ext_type;
2485
    ENDPOINT role;
2486
    /* The context which this extension applies to */
2487
    unsigned int context;
2488
    /*
2489
     * Per-connection flags relating to this extension type: not used if
2490
     * part of an SSL_CTX structure.
2491
     */
2492
    uint32_t ext_flags;
2493
    SSL_custom_ext_add_cb_ex add_cb;
2494
    SSL_custom_ext_free_cb_ex free_cb;
2495
    void *add_arg;
2496
    SSL_custom_ext_parse_cb_ex parse_cb;
2497
    void *parse_arg;
2498
} custom_ext_method;
2499
2500
/* ext_flags values */
2501
2502
/*
2503
 * Indicates an extension has been received. Used to check for unsolicited or
2504
 * duplicate extensions.
2505
 */
2506
0
#define SSL_EXT_FLAG_RECEIVED 0x1
2507
/*
2508
 * Indicates an extension has been sent: used to enable sending of
2509
 * corresponding ServerHello extension.
2510
 */
2511
0
#define SSL_EXT_FLAG_SENT 0x2
2512
/*
2513
 * Indicates an extension that was set on SSL object and needs to be
2514
 * preserved when switching SSL contexts.
2515
 */
2516
0
#define SSL_EXT_FLAG_CONN 0x4
2517
2518
typedef struct {
2519
    custom_ext_method *meths;
2520
    size_t meths_count;
2521
} custom_ext_methods;
2522
2523
typedef struct cert_st {
2524
    /* Current active set */
2525
    /*
2526
     * ALWAYS points to an element of the pkeys array
2527
     * Probably it would make more sense to store
2528
     * an index, not a pointer.
2529
     */
2530
    CERT_PKEY *key;
2531
2532
    EVP_PKEY *dh_tmp;
2533
    DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
2534
    int dh_tmp_auto;
2535
    /* Flags related to certificates */
2536
    uint32_t cert_flags;
2537
    CERT_PKEY *pkeys;
2538
    size_t ssl_pkey_num;
2539
    /* Custom certificate types sent in certificate request message. */
2540
    uint8_t *ctype;
2541
    size_t ctype_len;
2542
    /*
2543
     * supported signature algorithms. When set on a client this is sent in
2544
     * the client hello as the supported signature algorithms extension. For
2545
     * servers it represents the signature algorithms we are willing to use.
2546
     */
2547
    uint16_t *conf_sigalgs;
2548
    /* Size of above array */
2549
    size_t conf_sigalgslen;
2550
    /*
2551
     * Client authentication signature algorithms, if not set then uses
2552
     * conf_sigalgs. On servers these will be the signature algorithms sent
2553
     * to the client in a certificate request for TLS 1.2. On a client this
2554
     * represents the signature algorithms we are willing to use for client
2555
     * authentication.
2556
     */
2557
    uint16_t *client_sigalgs;
2558
    /* Size of above array */
2559
    size_t client_sigalgslen;
2560
    /*
2561
     * Certificate setup callback: if set is called whenever a certificate
2562
     * may be required (client or server). the callback can then examine any
2563
     * appropriate parameters and setup any certificates required. This
2564
     * allows advanced applications to select certificates on the fly: for
2565
     * example based on supported signature algorithms or curves.
2566
     */
2567
    int (*cert_cb)(SSL *ssl, void *arg);
2568
    void *cert_cb_arg;
2569
    /*
2570
     * Optional X509_STORE for chain building or certificate validation If
2571
     * NULL the parent SSL_CTX store is used instead.
2572
     */
2573
    X509_STORE *chain_store;
2574
    X509_STORE *verify_store;
2575
    /* Custom extensions */
2576
    custom_ext_methods custext;
2577
    /* Security callback */
2578
    int (*sec_cb)(const SSL *s, const SSL_CTX *ctx, int op, int bits, int nid,
2579
        void *other, void *ex);
2580
    /* Security level */
2581
    int sec_level;
2582
    void *sec_ex;
2583
#ifndef OPENSSL_NO_PSK
2584
    /* If not NULL psk identity hint to use for servers */
2585
    char *psk_identity_hint;
2586
#endif
2587
    CRYPTO_REF_COUNT references; /* >1 only if SSL_copy_session_id is used */
2588
} CERT;
2589
2590
/*
2591
 * This is for the TLSv1.0 differences in crypto/hash stuff.
2592
 */
2593
typedef struct ssl3_enc_method {
2594
    int (*setup_key_block)(SSL_CONNECTION *);
2595
    int (*generate_master_secret)(SSL_CONNECTION *, unsigned char *,
2596
        unsigned char *, size_t, size_t *);
2597
    int (*change_cipher_state)(SSL_CONNECTION *, int);
2598
    size_t (*final_finish_mac)(SSL_CONNECTION *, const char *, size_t,
2599
        unsigned char *);
2600
    const char *client_finished_label;
2601
    size_t client_finished_label_len;
2602
    const char *server_finished_label;
2603
    size_t server_finished_label_len;
2604
    int (*alert_value)(int);
2605
    int (*export_keying_material)(SSL_CONNECTION *, unsigned char *, size_t,
2606
        const char *, size_t,
2607
        const unsigned char *, size_t,
2608
        int use_context);
2609
    /* Various flags indicating protocol version requirements */
2610
    uint32_t enc_flags;
2611
    /* Set the handshake header */
2612
    int (*set_handshake_header)(SSL_CONNECTION *s, WPACKET *pkt, int type);
2613
    /* Close construction of the handshake message */
2614
    int (*close_construct_packet)(SSL_CONNECTION *s, WPACKET *pkt, int htype);
2615
    /* Write out handshake message */
2616
    int (*do_write)(SSL_CONNECTION *s);
2617
} SSL3_ENC_METHOD;
2618
2619
#define ssl_set_handshake_header(s, pkt, htype) \
2620
0
    SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->set_handshake_header((s), (pkt), (htype))
2621
#define ssl_close_construct_packet(s, pkt, htype) \
2622
0
    SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->close_construct_packet((s), (pkt), (htype))
2623
0
#define ssl_do_write(s) SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->do_write(s)
2624
2625
/* Values for enc_flags */
2626
2627
/* Uses signature algorithms extension */
2628
0
#define SSL_ENC_FLAG_SIGALGS 0x2
2629
/* Uses SHA256 default PRF */
2630
0
#define SSL_ENC_FLAG_SHA256_PRF 0x4
2631
/* Is DTLS */
2632
0
#define SSL_ENC_FLAG_DTLS 0x8
2633
/*
2634
 * Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2: may
2635
 * apply to others in future.
2636
 */
2637
0
#define SSL_ENC_FLAG_TLS1_2_CIPHERS 0x10
2638
2639
/*
2640
 * Dummy status type for the status_type extension. Indicates no status type
2641
 * set
2642
 */
2643
0
#define TLSEXT_STATUSTYPE_nothing -1
2644
2645
/* Known PSK key exchange modes */
2646
0
#define TLSEXT_KEX_MODE_KE 0x00
2647
0
#define TLSEXT_KEX_MODE_KE_DHE 0x01
2648
2649
/*
2650
 * Internal representations of key exchange modes
2651
 */
2652
0
#define TLSEXT_KEX_MODE_FLAG_NONE 0
2653
0
#define TLSEXT_KEX_MODE_FLAG_KE 1
2654
0
#define TLSEXT_KEX_MODE_FLAG_KE_DHE 2
2655
2656
0
#define SSL_USE_PSS(s) (s->s3.tmp.peer_sigalg != NULL && s->s3.tmp.peer_sigalg->sig == EVP_PKEY_RSA_PSS)
2657
2658
/* TLSv1.3 downgrade protection sentinel values */
2659
extern const unsigned char tls11downgrade[8];
2660
extern const unsigned char tls12downgrade[8];
2661
2662
extern const SSL3_ENC_METHOD ssl3_undef_enc_method;
2663
2664
__owur const SSL_METHOD *tlsv1_method(void);
2665
__owur const SSL_METHOD *tlsv1_server_method(void);
2666
__owur const SSL_METHOD *tlsv1_client_method(void);
2667
__owur const SSL_METHOD *tlsv1_1_method(void);
2668
__owur const SSL_METHOD *tlsv1_1_server_method(void);
2669
__owur const SSL_METHOD *tlsv1_1_client_method(void);
2670
__owur const SSL_METHOD *tlsv1_2_method(void);
2671
__owur const SSL_METHOD *tlsv1_2_server_method(void);
2672
__owur const SSL_METHOD *tlsv1_2_client_method(void);
2673
__owur const SSL_METHOD *tlsv1_3_method(void);
2674
__owur const SSL_METHOD *tlsv1_3_server_method(void);
2675
__owur const SSL_METHOD *tlsv1_3_client_method(void);
2676
__owur const SSL_METHOD *dtlsv1_method(void);
2677
__owur const SSL_METHOD *dtlsv1_server_method(void);
2678
__owur const SSL_METHOD *dtlsv1_client_method(void);
2679
__owur const SSL_METHOD *dtls_bad_ver_client_method(void);
2680
__owur const SSL_METHOD *dtlsv1_2_method(void);
2681
__owur const SSL_METHOD *dtlsv1_2_server_method(void);
2682
__owur const SSL_METHOD *dtlsv1_2_client_method(void);
2683
__owur const SSL_METHOD *dtlsv1_3_method(void);
2684
__owur const SSL_METHOD *dtlsv1_3_server_method(void);
2685
__owur const SSL_METHOD *dtlsv1_3_client_method(void);
2686
2687
extern const SSL3_ENC_METHOD TLSv1_enc_data;
2688
extern const SSL3_ENC_METHOD TLSv1_1_enc_data;
2689
extern const SSL3_ENC_METHOD TLSv1_2_enc_data;
2690
extern const SSL3_ENC_METHOD TLSv1_3_enc_data;
2691
extern const SSL3_ENC_METHOD DTLSv1_enc_data;
2692
extern const SSL3_ENC_METHOD DTLSv1_2_enc_data;
2693
extern const SSL3_ENC_METHOD DTLSv1_3_enc_data;
2694
2695
/*
2696
 * Flags for SSL methods
2697
 */
2698
#define SSL_METHOD_NO_FIPS (1U << 0)
2699
0
#define SSL_METHOD_NO_SUITEB (1U << 1)
2700
2701
#define IMPLEMENT_tls_meth_func(version, flags, mask, func_name, s_accept, \
2702
    s_connect, enc_data)                                                   \
2703
    const SSL_METHOD *func_name(void)                                      \
2704
0
    {                                                                      \
2705
0
        static const SSL_METHOD func_name##_data = {                       \
2706
0
            version,                                                       \
2707
0
            flags,                                                         \
2708
0
            mask,                                                          \
2709
0
            ossl_ssl_connection_new,                                       \
2710
0
            ossl_ssl_connection_free,                                      \
2711
0
            ossl_ssl_connection_reset,                                     \
2712
0
            tls1_new,                                                      \
2713
0
            tls1_clear,                                                    \
2714
0
            tls1_free,                                                     \
2715
0
            s_accept,                                                      \
2716
0
            s_connect,                                                     \
2717
0
            ssl3_read,                                                     \
2718
0
            ssl3_peek,                                                     \
2719
0
            ssl3_write,                                                    \
2720
0
            ssl3_shutdown,                                                 \
2721
0
            ssl3_renegotiate,                                              \
2722
0
            ssl3_renegotiate_check,                                        \
2723
0
            ssl3_read_bytes,                                               \
2724
0
            ssl3_write_bytes,                                              \
2725
0
            ssl3_dispatch_alert,                                           \
2726
0
            ssl3_ctrl,                                                     \
2727
0
            ssl3_ctx_ctrl,                                                 \
2728
0
            ssl3_get_cipher_by_char,                                       \
2729
0
            ssl3_put_cipher_by_char,                                       \
2730
0
            ssl3_pending,                                                  \
2731
0
            ssl3_num_ciphers,                                              \
2732
0
            ssl3_get_cipher,                                               \
2733
0
            tls1_default_timeout,                                          \
2734
0
            &enc_data,                                                     \
2735
0
            ssl_undefined_void_function,                                   \
2736
0
            ssl3_callback_ctrl,                                            \
2737
0
            ssl3_ctx_callback_ctrl,                                        \
2738
0
        };                                                                 \
2739
0
        return &func_name##_data;                                          \
2740
0
    }
Unexecuted instantiation: TLS_method
Unexecuted instantiation: tlsv1_3_method
Unexecuted instantiation: tlsv1_2_method
Unexecuted instantiation: tlsv1_1_method
Unexecuted instantiation: tlsv1_method
Unexecuted instantiation: TLS_server_method
Unexecuted instantiation: tlsv1_3_server_method
Unexecuted instantiation: tlsv1_2_server_method
Unexecuted instantiation: tlsv1_1_server_method
Unexecuted instantiation: tlsv1_server_method
Unexecuted instantiation: TLS_client_method
Unexecuted instantiation: tlsv1_3_client_method
Unexecuted instantiation: tlsv1_2_client_method
Unexecuted instantiation: tlsv1_1_client_method
Unexecuted instantiation: tlsv1_client_method
2741
2742
#define IMPLEMENT_dtls1_meth_func(version, flags, mask, func_name, s_accept, \
2743
    s_connect, enc_data)                                                     \
2744
    const SSL_METHOD *func_name(void)                                        \
2745
0
    {                                                                        \
2746
0
        static const SSL_METHOD func_name##_data = {                         \
2747
0
            version,                                                         \
2748
0
            flags,                                                           \
2749
0
            mask,                                                            \
2750
0
            ossl_ssl_connection_new,                                         \
2751
0
            ossl_ssl_connection_free,                                        \
2752
0
            ossl_ssl_connection_reset,                                       \
2753
0
            dtls1_new,                                                       \
2754
0
            dtls1_clear,                                                     \
2755
0
            dtls1_free,                                                      \
2756
0
            s_accept,                                                        \
2757
0
            s_connect,                                                       \
2758
0
            ssl3_read,                                                       \
2759
0
            ssl3_peek,                                                       \
2760
0
            ssl3_write,                                                      \
2761
0
            dtls1_shutdown,                                                  \
2762
0
            ssl3_renegotiate,                                                \
2763
0
            ssl3_renegotiate_check,                                          \
2764
0
            dtls1_read_bytes,                                                \
2765
0
            dtls1_write_app_data_bytes,                                      \
2766
0
            dtls1_dispatch_alert,                                            \
2767
0
            dtls1_ctrl,                                                      \
2768
0
            ssl3_ctx_ctrl,                                                   \
2769
0
            ssl3_get_cipher_by_char,                                         \
2770
0
            ssl3_put_cipher_by_char,                                         \
2771
0
            ssl3_pending,                                                    \
2772
0
            ssl3_num_ciphers,                                                \
2773
0
            ssl3_get_cipher,                                                 \
2774
0
            dtls1_default_timeout,                                           \
2775
0
            &enc_data,                                                       \
2776
0
            ssl_undefined_void_function,                                     \
2777
0
            ssl3_callback_ctrl,                                              \
2778
0
            ssl3_ctx_callback_ctrl,                                          \
2779
0
        };                                                                   \
2780
0
        return &func_name##_data;                                            \
2781
0
    }
Unexecuted instantiation: dtlsv1_method
Unexecuted instantiation: dtlsv1_2_method
Unexecuted instantiation: dtlsv1_3_method
Unexecuted instantiation: DTLS_method
Unexecuted instantiation: dtlsv1_server_method
Unexecuted instantiation: dtlsv1_2_server_method
Unexecuted instantiation: dtlsv1_3_server_method
Unexecuted instantiation: DTLS_server_method
Unexecuted instantiation: dtlsv1_client_method
Unexecuted instantiation: dtls_bad_ver_client_method
Unexecuted instantiation: dtlsv1_2_client_method
Unexecuted instantiation: dtlsv1_3_client_method
Unexecuted instantiation: DTLS_client_method
2782
2783
struct openssl_ssl_test_functions {
2784
    int (*p_ssl_init_wbio_buffer)(SSL_CONNECTION *s);
2785
};
2786
2787
const char *ssl_protocol_to_string(int version);
2788
2789
static ossl_inline int tls12_rpk_and_privkey(const SSL_CONNECTION *sc, int idx)
2790
0
{
2791
    /*
2792
     * This is to check for special cases when using RPK with just
2793
     * a private key, and NO CERTIFICATE
2794
     */
2795
0
    return ((sc->server && sc->ext.server_cert_type == TLSEXT_cert_type_rpk)
2796
0
               || (!sc->server && sc->ext.client_cert_type == TLSEXT_cert_type_rpk))
2797
0
        && sc->cert->pkeys[idx].privatekey != NULL
2798
0
        && sc->cert->pkeys[idx].x509 == NULL;
2799
0
}
Unexecuted instantiation: methods.c:tls12_rpk_and_privkey
Unexecuted instantiation: s3_lib.c:tls12_rpk_and_privkey
Unexecuted instantiation: s3_msg.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_cert.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_ciph.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_init.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_lib.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_mcnf.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_rsa.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_sess.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_stat.c:tls12_rpk_and_privkey
Unexecuted instantiation: t1_lib.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls13_enc.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls_depr.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls_srp.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_impl.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_method.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_obj.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_port.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_record_rx.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_record_shared.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_record_tx.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_record_util.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_thread_assist.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_tls.c:tls12_rpk_and_privkey
Unexecuted instantiation: rec_layer_d1.c:tls12_rpk_and_privkey
Unexecuted instantiation: rec_layer_s3.c:tls12_rpk_and_privkey
Unexecuted instantiation: dtls_meth.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls13_meth.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls1_meth.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls_common.c:tls12_rpk_and_privkey
Unexecuted instantiation: tls_multib.c:tls12_rpk_and_privkey
Unexecuted instantiation: tlsany_meth.c:tls12_rpk_and_privkey
Unexecuted instantiation: extensions.c:tls12_rpk_and_privkey
Unexecuted instantiation: extensions_clnt.c:tls12_rpk_and_privkey
Unexecuted instantiation: extensions_cust.c:tls12_rpk_and_privkey
Unexecuted instantiation: extensions_srvr.c:tls12_rpk_and_privkey
Unexecuted instantiation: statem.c:tls12_rpk_and_privkey
Unexecuted instantiation: statem_clnt.c:tls12_rpk_and_privkey
Unexecuted instantiation: statem_dtls.c:tls12_rpk_and_privkey
Unexecuted instantiation: statem_lib.c:tls12_rpk_and_privkey
Unexecuted instantiation: statem_srvr.c:tls12_rpk_and_privkey
Unexecuted instantiation: ech_helper.c:tls12_rpk_and_privkey
Unexecuted instantiation: ech_internal.c:tls12_rpk_and_privkey
Unexecuted instantiation: ech_store.c:tls12_rpk_and_privkey
Unexecuted instantiation: d1_lib.c:tls12_rpk_and_privkey
Unexecuted instantiation: d1_msg.c:tls12_rpk_and_privkey
Unexecuted instantiation: d1_srtp.c:tls12_rpk_and_privkey
Unexecuted instantiation: d1_transcript.c:tls12_rpk_and_privkey
Unexecuted instantiation: dtls_record_rx.c:tls12_rpk_and_privkey
Unexecuted instantiation: pqueue.c:tls12_rpk_and_privkey
Unexecuted instantiation: s3_enc.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_asn1.c:tls12_rpk_and_privkey
Unexecuted instantiation: ssl_conf.c:tls12_rpk_and_privkey
Unexecuted instantiation: t1_enc.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_channel.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_engine.c:tls12_rpk_and_privkey
Unexecuted instantiation: quic_rx_depack.c:tls12_rpk_and_privkey
Unexecuted instantiation: poll_immediate.c:tls12_rpk_and_privkey
2800
2801
static ossl_inline int ssl_has_cert_type(const SSL_CONNECTION *sc, unsigned char ct)
2802
0
{
2803
0
    unsigned char *ptr;
2804
0
    size_t len;
2805
2806
0
    if (sc->server) {
2807
0
        ptr = sc->server_cert_type;
2808
0
        len = sc->server_cert_type_len;
2809
0
    } else {
2810
0
        ptr = sc->client_cert_type;
2811
0
        len = sc->client_cert_type_len;
2812
0
    }
2813
2814
0
    if (ptr == NULL)
2815
0
        return 0;
2816
2817
0
    return memchr(ptr, ct, len) != NULL;
2818
0
}
Unexecuted instantiation: methods.c:ssl_has_cert_type
Unexecuted instantiation: s3_lib.c:ssl_has_cert_type
Unexecuted instantiation: s3_msg.c:ssl_has_cert_type
Unexecuted instantiation: ssl_cert.c:ssl_has_cert_type
Unexecuted instantiation: ssl_ciph.c:ssl_has_cert_type
Unexecuted instantiation: ssl_init.c:ssl_has_cert_type
Unexecuted instantiation: ssl_lib.c:ssl_has_cert_type
Unexecuted instantiation: ssl_mcnf.c:ssl_has_cert_type
Unexecuted instantiation: ssl_rsa.c:ssl_has_cert_type
Unexecuted instantiation: ssl_sess.c:ssl_has_cert_type
Unexecuted instantiation: ssl_stat.c:ssl_has_cert_type
Unexecuted instantiation: t1_lib.c:ssl_has_cert_type
Unexecuted instantiation: tls13_enc.c:ssl_has_cert_type
Unexecuted instantiation: tls_depr.c:ssl_has_cert_type
Unexecuted instantiation: tls_srp.c:ssl_has_cert_type
Unexecuted instantiation: quic_impl.c:ssl_has_cert_type
Unexecuted instantiation: quic_method.c:ssl_has_cert_type
Unexecuted instantiation: quic_obj.c:ssl_has_cert_type
Unexecuted instantiation: quic_port.c:ssl_has_cert_type
Unexecuted instantiation: quic_record_rx.c:ssl_has_cert_type
Unexecuted instantiation: quic_record_shared.c:ssl_has_cert_type
Unexecuted instantiation: quic_record_tx.c:ssl_has_cert_type
Unexecuted instantiation: quic_record_util.c:ssl_has_cert_type
Unexecuted instantiation: quic_thread_assist.c:ssl_has_cert_type
Unexecuted instantiation: quic_tls.c:ssl_has_cert_type
Unexecuted instantiation: rec_layer_d1.c:ssl_has_cert_type
Unexecuted instantiation: rec_layer_s3.c:ssl_has_cert_type
Unexecuted instantiation: dtls_meth.c:ssl_has_cert_type
Unexecuted instantiation: tls13_meth.c:ssl_has_cert_type
Unexecuted instantiation: tls1_meth.c:ssl_has_cert_type
Unexecuted instantiation: tls_common.c:ssl_has_cert_type
Unexecuted instantiation: tls_multib.c:ssl_has_cert_type
Unexecuted instantiation: tlsany_meth.c:ssl_has_cert_type
Unexecuted instantiation: extensions.c:ssl_has_cert_type
Unexecuted instantiation: extensions_clnt.c:ssl_has_cert_type
Unexecuted instantiation: extensions_cust.c:ssl_has_cert_type
Unexecuted instantiation: extensions_srvr.c:ssl_has_cert_type
Unexecuted instantiation: statem.c:ssl_has_cert_type
Unexecuted instantiation: statem_clnt.c:ssl_has_cert_type
Unexecuted instantiation: statem_dtls.c:ssl_has_cert_type
Unexecuted instantiation: statem_lib.c:ssl_has_cert_type
Unexecuted instantiation: statem_srvr.c:ssl_has_cert_type
Unexecuted instantiation: ech_helper.c:ssl_has_cert_type
Unexecuted instantiation: ech_internal.c:ssl_has_cert_type
Unexecuted instantiation: ech_store.c:ssl_has_cert_type
Unexecuted instantiation: d1_lib.c:ssl_has_cert_type
Unexecuted instantiation: d1_msg.c:ssl_has_cert_type
Unexecuted instantiation: d1_srtp.c:ssl_has_cert_type
Unexecuted instantiation: d1_transcript.c:ssl_has_cert_type
Unexecuted instantiation: dtls_record_rx.c:ssl_has_cert_type
Unexecuted instantiation: pqueue.c:ssl_has_cert_type
Unexecuted instantiation: s3_enc.c:ssl_has_cert_type
Unexecuted instantiation: ssl_asn1.c:ssl_has_cert_type
Unexecuted instantiation: ssl_conf.c:ssl_has_cert_type
Unexecuted instantiation: t1_enc.c:ssl_has_cert_type
Unexecuted instantiation: quic_channel.c:ssl_has_cert_type
Unexecuted instantiation: quic_engine.c:ssl_has_cert_type
Unexecuted instantiation: quic_rx_depack.c:ssl_has_cert_type
Unexecuted instantiation: poll_immediate.c:ssl_has_cert_type
2819
2820
/* Returns true if certificate and private key for 'idx' are present */
2821
static ossl_inline int ssl_has_cert(const SSL_CONNECTION *s, int idx)
2822
0
{
2823
0
    if (idx < 0 || idx >= (int)s->ssl_pkey_num)
2824
0
        return 0;
2825
2826
    /* If RPK is enabled for this SSL... only require private key */
2827
0
    if (ssl_has_cert_type(s, TLSEXT_cert_type_rpk))
2828
0
        return s->cert->pkeys[idx].privatekey != NULL;
2829
2830
0
    return s->cert->pkeys[idx].x509 != NULL
2831
0
        && s->cert->pkeys[idx].privatekey != NULL;
2832
0
}
Unexecuted instantiation: methods.c:ssl_has_cert
Unexecuted instantiation: s3_lib.c:ssl_has_cert
Unexecuted instantiation: s3_msg.c:ssl_has_cert
Unexecuted instantiation: ssl_cert.c:ssl_has_cert
Unexecuted instantiation: ssl_ciph.c:ssl_has_cert
Unexecuted instantiation: ssl_init.c:ssl_has_cert
Unexecuted instantiation: ssl_lib.c:ssl_has_cert
Unexecuted instantiation: ssl_mcnf.c:ssl_has_cert
Unexecuted instantiation: ssl_rsa.c:ssl_has_cert
Unexecuted instantiation: ssl_sess.c:ssl_has_cert
Unexecuted instantiation: ssl_stat.c:ssl_has_cert
Unexecuted instantiation: t1_lib.c:ssl_has_cert
Unexecuted instantiation: tls13_enc.c:ssl_has_cert
Unexecuted instantiation: tls_depr.c:ssl_has_cert
Unexecuted instantiation: tls_srp.c:ssl_has_cert
Unexecuted instantiation: quic_impl.c:ssl_has_cert
Unexecuted instantiation: quic_method.c:ssl_has_cert
Unexecuted instantiation: quic_obj.c:ssl_has_cert
Unexecuted instantiation: quic_port.c:ssl_has_cert
Unexecuted instantiation: quic_record_rx.c:ssl_has_cert
Unexecuted instantiation: quic_record_shared.c:ssl_has_cert
Unexecuted instantiation: quic_record_tx.c:ssl_has_cert
Unexecuted instantiation: quic_record_util.c:ssl_has_cert
Unexecuted instantiation: quic_thread_assist.c:ssl_has_cert
Unexecuted instantiation: quic_tls.c:ssl_has_cert
Unexecuted instantiation: rec_layer_d1.c:ssl_has_cert
Unexecuted instantiation: rec_layer_s3.c:ssl_has_cert
Unexecuted instantiation: dtls_meth.c:ssl_has_cert
Unexecuted instantiation: tls13_meth.c:ssl_has_cert
Unexecuted instantiation: tls1_meth.c:ssl_has_cert
Unexecuted instantiation: tls_common.c:ssl_has_cert
Unexecuted instantiation: tls_multib.c:ssl_has_cert
Unexecuted instantiation: tlsany_meth.c:ssl_has_cert
Unexecuted instantiation: extensions.c:ssl_has_cert
Unexecuted instantiation: extensions_clnt.c:ssl_has_cert
Unexecuted instantiation: extensions_cust.c:ssl_has_cert
Unexecuted instantiation: extensions_srvr.c:ssl_has_cert
Unexecuted instantiation: statem.c:ssl_has_cert
Unexecuted instantiation: statem_clnt.c:ssl_has_cert
Unexecuted instantiation: statem_dtls.c:ssl_has_cert
Unexecuted instantiation: statem_lib.c:ssl_has_cert
Unexecuted instantiation: statem_srvr.c:ssl_has_cert
Unexecuted instantiation: ech_helper.c:ssl_has_cert
Unexecuted instantiation: ech_internal.c:ssl_has_cert
Unexecuted instantiation: ech_store.c:ssl_has_cert
Unexecuted instantiation: d1_lib.c:ssl_has_cert
Unexecuted instantiation: d1_msg.c:ssl_has_cert
Unexecuted instantiation: d1_srtp.c:ssl_has_cert
Unexecuted instantiation: d1_transcript.c:ssl_has_cert
Unexecuted instantiation: dtls_record_rx.c:ssl_has_cert
Unexecuted instantiation: pqueue.c:ssl_has_cert
Unexecuted instantiation: s3_enc.c:ssl_has_cert
Unexecuted instantiation: ssl_asn1.c:ssl_has_cert
Unexecuted instantiation: ssl_conf.c:ssl_has_cert
Unexecuted instantiation: t1_enc.c:ssl_has_cert
Unexecuted instantiation: quic_channel.c:ssl_has_cert
Unexecuted instantiation: quic_engine.c:ssl_has_cert
Unexecuted instantiation: quic_rx_depack.c:ssl_has_cert
Unexecuted instantiation: poll_immediate.c:ssl_has_cert
2833
2834
static ossl_inline void tls1_get_peer_groups(SSL_CONNECTION *s,
2835
    const uint16_t **pgroups,
2836
    size_t *pgroupslen)
2837
0
{
2838
0
    *pgroups = s->ext.peer_supportedgroups;
2839
0
    *pgroupslen = s->ext.peer_supportedgroups_len;
2840
0
}
Unexecuted instantiation: methods.c:tls1_get_peer_groups
Unexecuted instantiation: s3_lib.c:tls1_get_peer_groups
Unexecuted instantiation: s3_msg.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_cert.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_ciph.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_init.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_lib.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_mcnf.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_rsa.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_sess.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_stat.c:tls1_get_peer_groups
Unexecuted instantiation: t1_lib.c:tls1_get_peer_groups
Unexecuted instantiation: tls13_enc.c:tls1_get_peer_groups
Unexecuted instantiation: tls_depr.c:tls1_get_peer_groups
Unexecuted instantiation: tls_srp.c:tls1_get_peer_groups
Unexecuted instantiation: quic_impl.c:tls1_get_peer_groups
Unexecuted instantiation: quic_method.c:tls1_get_peer_groups
Unexecuted instantiation: quic_obj.c:tls1_get_peer_groups
Unexecuted instantiation: quic_port.c:tls1_get_peer_groups
Unexecuted instantiation: quic_record_rx.c:tls1_get_peer_groups
Unexecuted instantiation: quic_record_shared.c:tls1_get_peer_groups
Unexecuted instantiation: quic_record_tx.c:tls1_get_peer_groups
Unexecuted instantiation: quic_record_util.c:tls1_get_peer_groups
Unexecuted instantiation: quic_thread_assist.c:tls1_get_peer_groups
Unexecuted instantiation: quic_tls.c:tls1_get_peer_groups
Unexecuted instantiation: rec_layer_d1.c:tls1_get_peer_groups
Unexecuted instantiation: rec_layer_s3.c:tls1_get_peer_groups
Unexecuted instantiation: dtls_meth.c:tls1_get_peer_groups
Unexecuted instantiation: tls13_meth.c:tls1_get_peer_groups
Unexecuted instantiation: tls1_meth.c:tls1_get_peer_groups
Unexecuted instantiation: tls_common.c:tls1_get_peer_groups
Unexecuted instantiation: tls_multib.c:tls1_get_peer_groups
Unexecuted instantiation: tlsany_meth.c:tls1_get_peer_groups
Unexecuted instantiation: extensions.c:tls1_get_peer_groups
Unexecuted instantiation: extensions_clnt.c:tls1_get_peer_groups
Unexecuted instantiation: extensions_cust.c:tls1_get_peer_groups
Unexecuted instantiation: extensions_srvr.c:tls1_get_peer_groups
Unexecuted instantiation: statem.c:tls1_get_peer_groups
Unexecuted instantiation: statem_clnt.c:tls1_get_peer_groups
Unexecuted instantiation: statem_dtls.c:tls1_get_peer_groups
Unexecuted instantiation: statem_lib.c:tls1_get_peer_groups
Unexecuted instantiation: statem_srvr.c:tls1_get_peer_groups
Unexecuted instantiation: ech_helper.c:tls1_get_peer_groups
Unexecuted instantiation: ech_internal.c:tls1_get_peer_groups
Unexecuted instantiation: ech_store.c:tls1_get_peer_groups
Unexecuted instantiation: d1_lib.c:tls1_get_peer_groups
Unexecuted instantiation: d1_msg.c:tls1_get_peer_groups
Unexecuted instantiation: d1_srtp.c:tls1_get_peer_groups
Unexecuted instantiation: d1_transcript.c:tls1_get_peer_groups
Unexecuted instantiation: dtls_record_rx.c:tls1_get_peer_groups
Unexecuted instantiation: pqueue.c:tls1_get_peer_groups
Unexecuted instantiation: s3_enc.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_asn1.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_conf.c:tls1_get_peer_groups
Unexecuted instantiation: t1_enc.c:tls1_get_peer_groups
Unexecuted instantiation: quic_channel.c:tls1_get_peer_groups
Unexecuted instantiation: quic_engine.c:tls1_get_peer_groups
Unexecuted instantiation: quic_rx_depack.c:tls1_get_peer_groups
Unexecuted instantiation: poll_immediate.c:tls1_get_peer_groups
2841
2842
#ifndef OPENSSL_UNIT_TEST
2843
2844
__owur int ossl_ssl_init(SSL *ssl, SSL_CTX *ctx, const SSL_METHOD *method,
2845
    int type);
2846
__owur SSL *ossl_ssl_connection_new_int(SSL_CTX *ctx, SSL *user_ssl,
2847
    const SSL_METHOD *method);
2848
__owur SSL *ossl_ssl_connection_new(SSL_CTX *ctx);
2849
void ossl_ssl_connection_free(SSL *ssl);
2850
__owur int ossl_ssl_connection_reset(SSL *ssl);
2851
2852
__owur int ssl_read_internal(SSL *s, void *buf, size_t num, size_t *readbytes);
2853
__owur int ssl_write_internal(SSL *s, const void *buf, size_t num,
2854
    uint64_t flags, size_t *written);
2855
int ssl_clear_bad_session(SSL_CONNECTION *s);
2856
__owur CERT *ssl_cert_new(size_t ssl_pkey_num);
2857
__owur CERT *ssl_cert_dup(CERT *cert);
2858
void ssl_cert_clear_certs(CERT *c);
2859
void ssl_cert_free(CERT *c);
2860
__owur int ssl_generate_session_id(SSL_CONNECTION *s, SSL_SESSION *ss);
2861
__owur int ssl_get_new_session(SSL_CONNECTION *s, int session);
2862
__owur SSL_SESSION *lookup_sess_in_cache(SSL_CONNECTION *s,
2863
    const unsigned char *sess_id,
2864
    size_t sess_id_len);
2865
__owur int ssl_get_prev_session(SSL_CONNECTION *s, CLIENTHELLO_MSG *hello);
2866
__owur SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket);
2867
__owur int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
2868
DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
2869
__owur int ssl_cipher_ptr_id_cmp(const SSL_CIPHER *const *ap,
2870
    const SSL_CIPHER *const *bp);
2871
__owur STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,
2872
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites,
2873
    STACK_OF(SSL_CIPHER) **cipher_list,
2874
    STACK_OF(SSL_CIPHER) **cipher_list_by_id,
2875
    const char *rule_str,
2876
    CERT *c);
2877
__owur int ssl_cache_cipherlist(SSL_CONNECTION *s, PACKET *cipher_suites);
2878
__owur int ossl_bytes_to_cipher_list(SSL_CONNECTION *s, PACKET *cipher_suites,
2879
    STACK_OF(SSL_CIPHER) **skp,
2880
    STACK_OF(SSL_CIPHER) **scsvs,
2881
    int fatal);
2882
void ssl_update_cache(SSL_CONNECTION *s, int mode);
2883
__owur int ssl_cipher_get_evp_cipher(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2884
    const EVP_CIPHER **enc);
2885
__owur int ssl_cipher_get_evp_cipher_sn(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2886
    const EVP_CIPHER **enc);
2887
__owur int ssl_cipher_get_evp_md_mac(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2888
    const EVP_MD **md,
2889
    int *mac_pkey_type, size_t *mac_secret_size);
2890
__owur int ssl_cipher_get_evp(SSL_CTX *ctx, const SSL_SESSION *s,
2891
    const EVP_CIPHER **snenc,
2892
    const EVP_CIPHER **enc,
2893
    const EVP_MD **md,
2894
    int *mac_pkey_type, size_t *mac_secret_size,
2895
    SSL_COMP **comp, int use_etm);
2896
__owur int ssl_cipher_get_overhead(const SSL_CIPHER *c, int version,
2897
    size_t *mac_overhead, size_t *int_overhead,
2898
    size_t *blocksize, size_t *ext_overhead);
2899
__owur int ssl_cert_is_disabled(SSL_CTX *ctx, size_t idx);
2900
__owur const SSL_CIPHER *ssl_get_cipher_by_char(SSL_CONNECTION *ssl,
2901
    const unsigned char *ptr,
2902
    int all);
2903
__owur int ssl_cert_set0_chain(SSL_CONNECTION *s, SSL_CTX *ctx,
2904
    STACK_OF(X509) *chain);
2905
__owur int ssl_cert_set1_chain(SSL_CONNECTION *s, SSL_CTX *ctx,
2906
    STACK_OF(X509) *chain);
2907
__owur int ssl_cert_add0_chain_cert(SSL_CONNECTION *s, SSL_CTX *ctx, X509 *x);
2908
__owur int ssl_cert_add1_chain_cert(SSL_CONNECTION *s, SSL_CTX *ctx, X509 *x);
2909
__owur int ssl_cert_select_current(CERT *c, X509 *x);
2910
__owur int ssl_cert_set_current(CERT *c, long arg);
2911
void ssl_cert_set_cert_cb(CERT *c, int (*cb)(SSL *ssl, void *arg), void *arg);
2912
2913
__owur int ssl_verify_cert_chain(SSL_CONNECTION *s, STACK_OF(X509) *sk);
2914
__owur int ssl_verify_rpk(SSL_CONNECTION *s, EVP_PKEY *rpk);
2915
__owur int ssl_build_cert_chain(SSL_CONNECTION *s, SSL_CTX *ctx, int flags);
2916
__owur int ssl_cert_set_cert_store(CERT *c, X509_STORE *store, int chain,
2917
    int ref);
2918
__owur int ssl_cert_get_cert_store(CERT *c, X509_STORE **pstore, int chain);
2919
2920
__owur int ssl_security(const SSL_CONNECTION *s, int op, int bits, int nid,
2921
    void *other);
2922
__owur int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid,
2923
    void *other);
2924
int ssl_get_security_level_bits(const SSL *s, const SSL_CTX *ctx, int *levelp);
2925
2926
__owur int ssl_cert_lookup_by_nid(int nid, size_t *pidx, SSL_CTX *ctx);
2927
__owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_pkey(const EVP_PKEY *pk,
2928
    size_t *pidx,
2929
    SSL_CTX *ctx);
2930
__owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_idx(size_t idx, SSL_CTX *ctx);
2931
2932
int ssl_undefined_function(SSL *s);
2933
__owur int ssl_undefined_void_function(void);
2934
__owur int ssl_get_server_cert_serverinfo(SSL_CONNECTION *s,
2935
    const unsigned char **serverinfo,
2936
    size_t *serverinfo_length);
2937
void ssl_set_masks(SSL_CONNECTION *s);
2938
__owur STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL_CONNECTION *sc);
2939
__owur int ssl_x509err2alert(int type);
2940
void ssl_sort_cipher_list(void);
2941
int ssl_load_ciphers(SSL_CTX *ctx);
2942
int ssl_cipher_list_to_bytes(SSL_CONNECTION *s, STACK_OF(SSL_CIPHER) *sk,
2943
    WPACKET *pkt);
2944
uint16_t ossl_grease_value(SSL_CONNECTION *s, int index);
2945
static ossl_inline int ossl_is_grease_value(uint16_t val)
2946
0
{
2947
0
    return (val & 0x0f0f) == 0x0a0a && (val >> 8) == (val & 0xff);
2948
0
}
Unexecuted instantiation: methods.c:ossl_is_grease_value
Unexecuted instantiation: s3_lib.c:ossl_is_grease_value
Unexecuted instantiation: s3_msg.c:ossl_is_grease_value
Unexecuted instantiation: ssl_cert.c:ossl_is_grease_value
Unexecuted instantiation: ssl_ciph.c:ossl_is_grease_value
Unexecuted instantiation: ssl_init.c:ossl_is_grease_value
Unexecuted instantiation: ssl_lib.c:ossl_is_grease_value
Unexecuted instantiation: ssl_mcnf.c:ossl_is_grease_value
Unexecuted instantiation: ssl_rsa.c:ossl_is_grease_value
Unexecuted instantiation: ssl_sess.c:ossl_is_grease_value
Unexecuted instantiation: ssl_stat.c:ossl_is_grease_value
Unexecuted instantiation: t1_lib.c:ossl_is_grease_value
Unexecuted instantiation: tls13_enc.c:ossl_is_grease_value
Unexecuted instantiation: tls_depr.c:ossl_is_grease_value
Unexecuted instantiation: tls_srp.c:ossl_is_grease_value
Unexecuted instantiation: quic_impl.c:ossl_is_grease_value
Unexecuted instantiation: quic_method.c:ossl_is_grease_value
Unexecuted instantiation: quic_obj.c:ossl_is_grease_value
Unexecuted instantiation: quic_port.c:ossl_is_grease_value
Unexecuted instantiation: quic_record_rx.c:ossl_is_grease_value
Unexecuted instantiation: quic_record_shared.c:ossl_is_grease_value
Unexecuted instantiation: quic_record_tx.c:ossl_is_grease_value
Unexecuted instantiation: quic_record_util.c:ossl_is_grease_value
Unexecuted instantiation: quic_thread_assist.c:ossl_is_grease_value
Unexecuted instantiation: quic_tls.c:ossl_is_grease_value
Unexecuted instantiation: rec_layer_d1.c:ossl_is_grease_value
Unexecuted instantiation: rec_layer_s3.c:ossl_is_grease_value
Unexecuted instantiation: dtls_meth.c:ossl_is_grease_value
Unexecuted instantiation: tls13_meth.c:ossl_is_grease_value
Unexecuted instantiation: tls1_meth.c:ossl_is_grease_value
Unexecuted instantiation: tls_common.c:ossl_is_grease_value
Unexecuted instantiation: tls_multib.c:ossl_is_grease_value
Unexecuted instantiation: tlsany_meth.c:ossl_is_grease_value
Unexecuted instantiation: extensions.c:ossl_is_grease_value
Unexecuted instantiation: extensions_clnt.c:ossl_is_grease_value
Unexecuted instantiation: extensions_cust.c:ossl_is_grease_value
Unexecuted instantiation: extensions_srvr.c:ossl_is_grease_value
Unexecuted instantiation: statem.c:ossl_is_grease_value
Unexecuted instantiation: statem_clnt.c:ossl_is_grease_value
Unexecuted instantiation: statem_dtls.c:ossl_is_grease_value
Unexecuted instantiation: statem_lib.c:ossl_is_grease_value
Unexecuted instantiation: statem_srvr.c:ossl_is_grease_value
Unexecuted instantiation: ech_helper.c:ossl_is_grease_value
Unexecuted instantiation: ech_internal.c:ossl_is_grease_value
Unexecuted instantiation: ech_store.c:ossl_is_grease_value
Unexecuted instantiation: d1_lib.c:ossl_is_grease_value
Unexecuted instantiation: d1_msg.c:ossl_is_grease_value
Unexecuted instantiation: d1_srtp.c:ossl_is_grease_value
Unexecuted instantiation: d1_transcript.c:ossl_is_grease_value
Unexecuted instantiation: dtls_record_rx.c:ossl_is_grease_value
Unexecuted instantiation: pqueue.c:ossl_is_grease_value
Unexecuted instantiation: s3_enc.c:ossl_is_grease_value
Unexecuted instantiation: ssl_asn1.c:ossl_is_grease_value
Unexecuted instantiation: ssl_conf.c:ossl_is_grease_value
Unexecuted instantiation: t1_enc.c:ossl_is_grease_value
Unexecuted instantiation: quic_channel.c:ossl_is_grease_value
Unexecuted instantiation: quic_engine.c:ossl_is_grease_value
Unexecuted instantiation: quic_rx_depack.c:ossl_is_grease_value
Unexecuted instantiation: poll_immediate.c:ossl_is_grease_value
2949
__owur int ssl_setup_sigalgs(SSL_CTX *ctx);
2950
int ssl_load_groups(SSL_CTX *ctx);
2951
int ssl_load_sigalgs(SSL_CTX *ctx);
2952
__owur int ssl_fill_hello_random(SSL_CONNECTION *s, int server,
2953
    unsigned char *field, size_t len,
2954
    DOWNGRADE dgrd);
2955
__owur int ssl_generate_master_secret(SSL_CONNECTION *s, unsigned char *pms,
2956
    size_t pmslen, int free_pms);
2957
__owur EVP_PKEY *ssl_generate_pkey(SSL_CONNECTION *s, EVP_PKEY *pm);
2958
__owur int ssl_gensecret(SSL_CONNECTION *s, unsigned char *pms, size_t pmslen);
2959
__owur int ssl_derive(SSL_CONNECTION *s, EVP_PKEY *privkey, EVP_PKEY *pubkey,
2960
    int genmaster);
2961
__owur int ssl_decapsulate(SSL_CONNECTION *s, EVP_PKEY *privkey,
2962
    const unsigned char *ct, size_t ctlen,
2963
    int gensecret);
2964
__owur int ssl_encapsulate(SSL_CONNECTION *s, EVP_PKEY *pubkey,
2965
    unsigned char **ctp, size_t *ctlenp,
2966
    int gensecret);
2967
__owur EVP_PKEY *ssl_dh_to_pkey(DH *dh);
2968
__owur int ssl_set_tmp_ecdh_groups(uint16_t **pext, size_t *pextlen,
2969
    uint16_t **ksext, size_t *ksextlen,
2970
    size_t **tplext, size_t *tplextlen,
2971
    void *key);
2972
__owur unsigned int ssl_get_max_send_fragment(const SSL_CONNECTION *sc);
2973
__owur unsigned int ssl_get_split_send_fragment(const SSL_CONNECTION *sc);
2974
2975
__owur const SSL_CIPHER *ssl3_get_cipher_by_id(uint32_t id);
2976
__owur const SSL_CIPHER *ssl3_get_cipher_by_std_name(const char *stdname);
2977
__owur const SSL_CIPHER *ssl3_get_tls13_cipher_by_std_name(const char *stdname);
2978
__owur const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
2979
__owur int ssl3_put_cipher_by_char(const SSL_CIPHER *c, WPACKET *pkt,
2980
    size_t *len);
2981
int ssl3_init_finished_mac(SSL_CONNECTION *s);
2982
void ssl3_cleanup_key_block(SSL_CONNECTION *s);
2983
__owur int ssl3_do_write(SSL_CONNECTION *s, uint8_t type);
2984
int ssl3_send_alert(SSL_CONNECTION *s, int level, int desc);
2985
__owur int ssl3_get_req_cert_type(SSL_CONNECTION *s, WPACKET *pkt);
2986
__owur int ssl3_num_ciphers(void);
2987
__owur const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
2988
int ssl3_renegotiate(SSL *ssl);
2989
int ssl3_renegotiate_check(SSL *ssl, int initok);
2990
__owur int ssl3_dispatch_alert(SSL *s);
2991
__owur int ssl3_finish_mac(SSL_CONNECTION *s, const unsigned char *buf,
2992
    size_t len);
2993
void ssl3_free_digest_list(SSL_CONNECTION *s);
2994
__owur unsigned long ssl3_output_cert_chain(SSL_CONNECTION *s, WPACKET *pkt,
2995
    CERT_PKEY *cpk, int for_comp);
2996
__owur const SSL_CIPHER *ssl3_choose_cipher(SSL_CONNECTION *s,
2997
    STACK_OF(SSL_CIPHER) *clnt,
2998
    STACK_OF(SSL_CIPHER) *srvr);
2999
__owur int ssl3_digest_cached_records(SSL_CONNECTION *s, int keep);
3000
__owur int ssl3_new(SSL *s);
3001
void ssl3_free(SSL *s);
3002
__owur int ssl3_read(SSL *s, void *buf, size_t len, size_t *readbytes);
3003
__owur int ssl3_peek(SSL *s, void *buf, size_t len, size_t *readbytes);
3004
__owur int ssl3_write(SSL *s, const void *buf, size_t len, size_t *written);
3005
__owur int ssl3_shutdown(SSL *s);
3006
int ssl3_clear(SSL *s);
3007
__owur long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
3008
__owur long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
3009
__owur long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
3010
__owur long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
3011
3012
__owur int ssl3_do_change_cipher_spec(SSL_CONNECTION *s);
3013
3014
__owur int ssl3_set_handshake_header(SSL_CONNECTION *s, WPACKET *pkt,
3015
    int htype);
3016
__owur int tls_close_construct_packet(SSL_CONNECTION *s, WPACKET *pkt, int htype);
3017
__owur int tls_setup_handshake(SSL_CONNECTION *s);
3018
__owur int dtls1_set_handshake_header(SSL_CONNECTION *s, WPACKET *pkt, int htype);
3019
__owur int dtls1_close_construct_packet(SSL_CONNECTION *s, WPACKET *pkt, int htype);
3020
__owur int ssl3_handshake_write(SSL_CONNECTION *s);
3021
3022
__owur int ssl_allow_compression(SSL_CONNECTION *s);
3023
3024
__owur int ssl_version_cmp(const SSL_CONNECTION *s, int versiona, int versionb);
3025
__owur int ssl_version_supported(const SSL_CONNECTION *s, int version,
3026
    const SSL_METHOD **meth);
3027
3028
__owur int ssl_set_client_hello_version(SSL_CONNECTION *s);
3029
__owur int ssl_check_version_downgrade(SSL_CONNECTION *s);
3030
__owur int ssl_set_version_bound(int method_version, int version, int *bound);
3031
__owur int ssl_choose_server_version(SSL_CONNECTION *s, CLIENTHELLO_MSG *hello,
3032
    DOWNGRADE *dgrd);
3033
__owur int ssl_choose_client_version(SSL_CONNECTION *s, int version,
3034
    RAW_EXTENSION *extensions);
3035
__owur int ssl_get_min_max_version(const SSL_CONNECTION *s, int *min_version,
3036
    int *max_version, int *real_max);
3037
3038
__owur OSSL_TIME tls1_default_timeout(void);
3039
__owur int dtls1_do_write(SSL_CONNECTION *s, uint8_t recordtype);
3040
3041
int dtls1_write_app_data_bytes(SSL *s, uint8_t type, const void *buf_,
3042
    size_t len, size_t *written);
3043
int dtls13_transcript_hash_update(EVP_MD_CTX *mdctx,
3044
    const unsigned char *buf, size_t len);
3045
3046
__owur int dtls1_read_failed(SSL_CONNECTION *s, int code);
3047
__owur int dtls1_buffer_sent_message(SSL_CONNECTION *s, int record_type);
3048
__owur int dtls1_retransmit_message(SSL_CONNECTION *s, dtls_sent_msg *sent_msg);
3049
void dtls1_get_queue_priority(unsigned char *prio64be, unsigned short seq,
3050
    int record_type);
3051
int dtls1_retransmit_sent_messages(SSL_CONNECTION *s);
3052
void dtls1_clear_received_buffer(SSL_CONNECTION *s);
3053
void dtls1_clear_sent_buffer(SSL_CONNECTION *s, int keep_unacked_msgs);
3054
void dtls1_acknowledge_sent_buffer(SSL_CONNECTION *s, uint64_t before_epoch);
3055
__owur OSSL_TIME dtls1_default_timeout(void);
3056
__owur int dtls1_get_timeout(const SSL_CONNECTION *s, OSSL_TIME *timeleft);
3057
__owur int dtls1_check_timeout_num(SSL_CONNECTION *s);
3058
__owur int dtls1_handle_timeout(SSL_CONNECTION *s);
3059
void dtls1_start_timer(SSL_CONNECTION *s);
3060
void dtls1_stop_timer(SSL_CONNECTION *s);
3061
__owur int dtls1_is_timer_expired(SSL_CONNECTION *s);
3062
void dtls1_clear_current_wrl_from_sent_buffer(SSL_CONNECTION *s);
3063
__owur int dtls_raw_hello_verify_request(WPACKET *pkt, unsigned char *cookie,
3064
    size_t cookie_len);
3065
__owur size_t dtls1_min_mtu(SSL_CONNECTION *s);
3066
void dtls1_hm_fragment_free(hm_fragment *frag);
3067
void dtls1_sent_msg_free(dtls_sent_msg *msg);
3068
__owur int dtls1_query_mtu(SSL_CONNECTION *s);
3069
3070
#if !defined(OPENSSL_NO_DTLS) && !defined(OPENSSL_NO_SOCK)
3071
SSL *ossl_dtls_new_listener(SSL_CTX *ctx, uint64_t flags);
3072
void ossl_dtls_listener_free(SSL *ssl);
3073
SSL *ossl_dtls_get0_listener(const SSL *ssl);
3074
int ossl_dtls_listen(SSL *ssl);
3075
SSL *ossl_dtls_accept_connection(SSL *ssl, uint64_t flags);
3076
void ossl_dtls_listener_set0_net_rbio(SSL *s, BIO *bio);
3077
void ossl_dtls_listener_set0_net_wbio(SSL *s, BIO *bio);
3078
BIO *ossl_dtls_listener_get_net_rbio(const SSL *s);
3079
BIO *ossl_dtls_listener_get_net_wbio(const SSL *s);
3080
3081
/* Established connections API - these handle their own locking */
3082
SSL *ossl_dtls_listener_find_established_conn(DTLS_LISTENER *dl,
3083
    const DGRAM_URXE *urxe);
3084
void ossl_dtls_listener_unregister_established_conn(SSL *s,
3085
    const BIO_ADDR *peer_addr);
3086
void ossl_dtls_listener_clear_established_conns(DTLS_LISTENER *dl);
3087
3088
size_t ossl_dtls_get_accept_connection_queue_len(SSL *ssl);
3089
int ossl_dtls_listener_set_override_now_cb(SSL *s,
3090
    OSSL_TIME (*now_cb)(void *arg),
3091
    void *now_cb_arg);
3092
3093
int ossl_dtls_get_value_uint(SSL *s, uint32_t class_, uint32_t id, uint64_t *value);
3094
int ossl_dtls_set_value_uint(SSL *s, uint32_t class_, uint32_t id, uint64_t value);
3095
3096
/* DTLS poll event functions - used by SSL_poll() */
3097
int ossl_dtls_listener_poll_events(SSL *s, uint64_t events, int do_tick,
3098
    uint64_t *revents);
3099
int ossl_dtls_conn_poll_events(SSL *s, uint64_t events, int do_tick,
3100
    uint64_t *revents);
3101
void ossl_dtls_listener_enter_blocking_section(SSL *s);
3102
void ossl_dtls_listener_leave_blocking_section(SSL *s);
3103
int ossl_dtls_block_until_ready(SSL *ssl, uint64_t events, OSSL_TIME deadline,
3104
    int bound_by_event_timeout);
3105
int ossl_dtls_blocking(const SSL *s);
3106
int ossl_dtls_set_blocking_mode(SSL *s, int blocking);
3107
int ossl_dtls_get_blocking_mode(const SSL *s);
3108
int ossl_dtls_conn_wait_for_datagram(SSL *s);
3109
int ossl_dtls_conn_wait_for_write(SSL *s);
3110
int ossl_dtls_tick(DTLS_LISTENER *dl);
3111
3112
/* DTLS Listener internal cookie callbacks */
3113
int ossl_dtls_listener_gen_cookie_cb(SSL *ssl, unsigned char *cookie,
3114
    unsigned int *cookie_len);
3115
int ossl_dtls_listener_verify_cookie_cb(SSL *ssl, const unsigned char *cookie,
3116
    unsigned int cookie_len);
3117
int ossl_dtls_listener_gen_stateless_cookie_cb(SSL *ssl, unsigned char *cookie,
3118
    size_t *cookie_len);
3119
int ossl_dtls_listener_verify_stateless_cookie_cb(SSL *ssl,
3120
    const unsigned char *cookie,
3121
    size_t cookie_len);
3122
#endif /* !OPENSSL_NO_DTLS && !OPENSSL_NO_SOCK */
3123
3124
__owur int tls1_new(SSL *s);
3125
void tls1_free(SSL *s);
3126
int tls1_clear(SSL *s);
3127
3128
__owur int dtls1_new(SSL *s);
3129
void dtls1_free(SSL *s);
3130
int dtls1_clear(SSL *s);
3131
long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
3132
__owur int dtls1_shutdown(SSL *s);
3133
3134
__owur int dtls1_dispatch_alert(SSL *s);
3135
3136
__owur int ssl_init_wbio_buffer(SSL_CONNECTION *s);
3137
int ssl_free_wbio_buffer(SSL_CONNECTION *s);
3138
3139
__owur int tls1_change_cipher_state(SSL_CONNECTION *s, int which);
3140
__owur int tls1_setup_key_block(SSL_CONNECTION *s);
3141
__owur size_t tls1_final_finish_mac(SSL_CONNECTION *s, const char *str,
3142
    size_t slen, unsigned char *p);
3143
__owur int tls1_generate_master_secret(SSL_CONNECTION *s, unsigned char *out,
3144
    unsigned char *p, size_t len,
3145
    size_t *secret_size);
3146
__owur int tls13_setup_key_block(SSL_CONNECTION *s);
3147
__owur size_t tls13_final_finish_mac(SSL_CONNECTION *s, const char *str, size_t slen,
3148
    unsigned char *p);
3149
__owur int tls13_store_handshake_traffic_hash(SSL_CONNECTION *s);
3150
__owur int tls13_store_server_finished_hash(SSL_CONNECTION *s);
3151
__owur int tls13_change_cipher_state(SSL_CONNECTION *s, int which);
3152
__owur int tls13_update_key(SSL_CONNECTION *s, int send);
3153
__owur int tls13_hkdf_expand(SSL_CONNECTION *s,
3154
    const EVP_MD *md,
3155
    const unsigned char *secret,
3156
    const unsigned char *label, size_t labellen,
3157
    const unsigned char *data, size_t datalen,
3158
    unsigned char *out, size_t outlen, int fatal);
3159
__owur int tls13_hkdf_expand_ex(OSSL_LIB_CTX *libctx, const char *propq,
3160
    const EVP_MD *md,
3161
    const unsigned char *secret,
3162
    const unsigned char *label, size_t labellen,
3163
    const unsigned char *data, size_t datalen,
3164
    unsigned char *out, size_t outlen,
3165
    int raise_error);
3166
__owur int tls13_derive_key(SSL_CONNECTION *s, const EVP_MD *md,
3167
    const unsigned char *secret, unsigned char *key,
3168
    size_t keylen);
3169
__owur int tls13_derive_iv(SSL_CONNECTION *s, const EVP_MD *md,
3170
    const unsigned char *secret, unsigned char *iv,
3171
    size_t ivlen);
3172
__owur int tls13_derive_finishedkey(SSL_CONNECTION *s, const EVP_MD *md,
3173
    const unsigned char *secret,
3174
    unsigned char *fin, size_t finlen);
3175
int tls13_generate_secret(SSL_CONNECTION *s, const EVP_MD *md,
3176
    const unsigned char *prevsecret,
3177
    const unsigned char *insecret,
3178
    size_t insecretlen,
3179
    unsigned char *outsecret);
3180
__owur int tls13_generate_handshake_secret(SSL_CONNECTION *s,
3181
    const unsigned char *insecret,
3182
    size_t insecretlen);
3183
__owur int tls13_generate_master_secret(SSL_CONNECTION *s, unsigned char *out,
3184
    unsigned char *prev, size_t prevlen,
3185
    size_t *secret_size);
3186
__owur int tls1_export_keying_material(SSL_CONNECTION *s,
3187
    unsigned char *out, size_t olen,
3188
    const char *label, size_t llen,
3189
    const unsigned char *p, size_t plen,
3190
    int use_context);
3191
__owur int tls13_export_keying_material(SSL_CONNECTION *s,
3192
    unsigned char *out, size_t olen,
3193
    const char *label, size_t llen,
3194
    const unsigned char *context,
3195
    size_t contextlen, int use_context);
3196
__owur int tls13_export_keying_material_early(SSL_CONNECTION *s,
3197
    unsigned char *out, size_t olen,
3198
    const char *label, size_t llen,
3199
    const unsigned char *context,
3200
    size_t contextlen);
3201
__owur int tls1_alert_code(int code);
3202
__owur int tls13_alert_code(int code);
3203
3204
__owur int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL_CONNECTION *s);
3205
3206
SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
3207
3208
0
#define TLS1_GROUPS_RETURN_NUMBER -1
3209
0
#define TLS1_GROUPS_RETURN_TMP_ID -2
3210
0
#define TLS1_GROUPS_FFDHE_GROUPS 0
3211
0
#define TLS1_GROUPS_NON_FFDHE_GROUPS 1
3212
0
#define TLS1_GROUPS_ALL_GROUPS 2
3213
3214
__owur const TLS_GROUP_INFO *tls1_group_id_lookup(SSL_CTX *ctx, uint16_t curve_id);
3215
__owur const char *tls1_group_id2name(SSL_CTX *ctx, uint16_t group_id);
3216
__owur int tls1_group_id2nid(uint16_t group_id, int include_unknown);
3217
__owur uint16_t tls1_nid2group_id(int nid);
3218
__owur int tls1_check_group_id(SSL_CONNECTION *s, uint16_t group_id,
3219
    int check_own_curves);
3220
__owur int tls1_get0_implemented_groups(int min_proto_version,
3221
    int max_proto_version,
3222
    TLS_GROUP_INFO *grps,
3223
    size_t num, long all,
3224
    STACK_OF(OPENSSL_CSTRING) *out);
3225
__owur uint16_t tls1_shared_group(SSL_CONNECTION *s, int nmatch, int groups);
3226
__owur int tls1_set_groups(uint16_t **grpext, size_t *grpextlen,
3227
    uint16_t **ksext, size_t *ksextlen,
3228
    size_t **tplext, size_t *tplextlen,
3229
    int *curves, size_t ncurves);
3230
__owur int tls1_set_groups_list(SSL_CTX *ctx,
3231
    uint16_t **grpext, size_t *grpextlen,
3232
    uint16_t **ksext, size_t *ksextlen,
3233
    size_t **tplext, size_t *tplextlen,
3234
    const char *str);
3235
__owur EVP_PKEY *ssl_generate_pkey_group(SSL_CONNECTION *s, uint16_t id);
3236
__owur int tls_valid_group(SSL_CONNECTION *s, uint16_t group_id, int minversion,
3237
    int maxversion, int *okfortls13, const TLS_GROUP_INFO **giptr);
3238
__owur EVP_PKEY *ssl_generate_param_group(SSL_CONNECTION *s, uint16_t id);
3239
void tls1_get_formatlist(SSL_CONNECTION *s, const unsigned char **pformats,
3240
    size_t *num_formats);
3241
__owur int tls1_check_ffdhe_tmp_key(SSL_CONNECTION *s, unsigned long id);
3242
__owur int tls1_check_ec_tmp_key(SSL_CONNECTION *s, unsigned long id);
3243
3244
__owur int tls_group_allowed(SSL_CONNECTION *s, uint16_t curve, int op);
3245
void tls1_get_supported_groups(SSL_CONNECTION *s, const uint16_t **pgroups,
3246
    size_t *pgroupslen);
3247
void tls1_get_requested_keyshare_groups(SSL_CONNECTION *s, const uint16_t **pgroups,
3248
    size_t *pgroupslen);
3249
void tls1_get_group_tuples(SSL_CONNECTION *s, const size_t **ptuples,
3250
    size_t *ptupleslen);
3251
3252
__owur int tls1_set_server_sigalgs(SSL_CONNECTION *s);
3253
3254
__owur SSL_TICKET_STATUS tls_get_ticket_from_client(SSL_CONNECTION *s,
3255
    CLIENTHELLO_MSG *hello,
3256
    SSL_SESSION **ret);
3257
__owur SSL_TICKET_STATUS tls_decrypt_ticket(SSL_CONNECTION *s,
3258
    const unsigned char *etick,
3259
    size_t eticklen,
3260
    const unsigned char *sess_id,
3261
    size_t sesslen, SSL_SESSION **psess);
3262
3263
__owur int tls_use_ticket(SSL_CONNECTION *s);
3264
3265
void ssl_set_sig_mask(uint32_t *pmask_a, SSL_CONNECTION *s, int op);
3266
3267
__owur int tls1_set_sigalgs_list(SSL_CTX *ctx, CERT *c, const char *str, int client);
3268
__owur int tls1_set_raw_sigalgs(CERT *c, const uint16_t *psigs, size_t salglen,
3269
    int client);
3270
__owur int tls1_set_sigalgs(CERT *c, const int *salg, size_t salglen,
3271
    int client);
3272
int tls1_check_chain(SSL_CONNECTION *s, X509 *x, EVP_PKEY *pk,
3273
    STACK_OF(X509) *chain, int idx);
3274
void tls1_set_cert_validity(SSL_CONNECTION *s);
3275
3276
#ifndef OPENSSL_NO_CT
3277
__owur int ssl_validate_ct(SSL_CONNECTION *s);
3278
#endif
3279
3280
__owur EVP_PKEY *ssl_get_auto_dh(SSL_CONNECTION *s);
3281
3282
__owur int ssl_security_cert(SSL_CONNECTION *s, SSL_CTX *ctx, X509 *x, int is_ee);
3283
__owur int ssl_security_cert_chain(SSL_CONNECTION *s, STACK_OF(X509) *sk,
3284
    X509 *ex);
3285
3286
int tls_choose_sigalg(SSL_CONNECTION *s, int fatalerrs);
3287
3288
__owur long ssl_get_algorithm2(SSL_CONNECTION *s);
3289
__owur int tls12_copy_sigalgs(SSL_CONNECTION *s, WPACKET *pkt,
3290
    const uint16_t *psig, size_t psiglen);
3291
__owur int tls1_save_u16(PACKET *pkt, uint16_t **pdest, size_t *pdestlen, size_t maxnum);
3292
__owur int tls1_save_sigalgs(SSL_CONNECTION *s, PACKET *pkt, int cert);
3293
__owur int tls1_process_sigalgs(SSL_CONNECTION *s);
3294
__owur int tls1_set_peer_legacy_sigalg(SSL_CONNECTION *s, const EVP_PKEY *pkey);
3295
__owur int tls1_lookup_md(SSL_CTX *ctx, const SIGALG_LOOKUP *lu,
3296
    const EVP_MD **pmd);
3297
__owur size_t tls12_get_psigalgs(SSL_CONNECTION *s, int sent,
3298
    const uint16_t **psigs);
3299
__owur int tls_check_sigalg_curve(const SSL_CONNECTION *s, int curve);
3300
__owur int tls12_check_peer_sigalg(SSL_CONNECTION *s, uint16_t, EVP_PKEY *pkey);
3301
__owur int ssl_set_client_disabled(SSL_CONNECTION *s);
3302
__owur int ssl_cipher_disabled(const SSL_CONNECTION *s, const SSL_CIPHER *c,
3303
    int op);
3304
3305
__owur int ssl_handshake_hash(SSL_CONNECTION *s,
3306
    unsigned char *out, size_t outlen,
3307
    size_t *hashlen);
3308
__owur const EVP_MD *ssl_md(SSL_CTX *ctx, int idx);
3309
int ssl_get_md_idx(int md_nid);
3310
__owur const EVP_MD *ssl_handshake_md(SSL_CONNECTION *s);
3311
__owur const EVP_MD *ssl_prf_md(SSL_CONNECTION *s);
3312
3313
__owur int ossl_adjust_domain_flags(uint64_t domain_flags,
3314
    uint64_t *p_domain_flags);
3315
3316
/*
3317
 * ssl_log_rsa_client_key_exchange logs |premaster| to the SSL_CTX associated
3318
 * with |ssl|, if logging is enabled. It returns one on success and zero on
3319
 * failure. The entry is identified by the first 8 bytes of
3320
 * |encrypted_premaster|.
3321
 */
3322
__owur int ssl_log_rsa_client_key_exchange(SSL_CONNECTION *s,
3323
    const uint8_t *encrypted_premaster,
3324
    size_t encrypted_premaster_len,
3325
    const uint8_t *premaster,
3326
    size_t premaster_len);
3327
3328
/*
3329
 * ssl_log_secret logs |secret| to the SSL_CTX associated with |ssl|, if
3330
 * logging is available. It returns one on success and zero on failure. It tags
3331
 * the entry with |label|.
3332
 */
3333
__owur int ssl_log_secret(SSL_CONNECTION *s, const char *label,
3334
    const uint8_t *secret, size_t secret_len);
3335
3336
0
#define MASTER_SECRET_LABEL "CLIENT_RANDOM"
3337
0
#define CLIENT_EARLY_LABEL "CLIENT_EARLY_TRAFFIC_SECRET"
3338
0
#define CLIENT_HANDSHAKE_LABEL "CLIENT_HANDSHAKE_TRAFFIC_SECRET"
3339
0
#define SERVER_HANDSHAKE_LABEL "SERVER_HANDSHAKE_TRAFFIC_SECRET"
3340
0
#define CLIENT_APPLICATION_LABEL "CLIENT_TRAFFIC_SECRET_0"
3341
0
#define CLIENT_APPLICATION_N_LABEL "CLIENT_TRAFFIC_SECRET_N"
3342
0
#define SERVER_APPLICATION_LABEL "SERVER_TRAFFIC_SECRET_0"
3343
0
#define SERVER_APPLICATION_N_LABEL "SERVER_TRAFFIC_SECRET_N"
3344
0
#define EARLY_EXPORTER_SECRET_LABEL "EARLY_EXPORTER_SECRET"
3345
0
#define EXPORTER_SECRET_LABEL "EXPORTER_SECRET"
3346
3347
__owur int srp_generate_server_master_secret(SSL_CONNECTION *s);
3348
__owur int srp_generate_client_master_secret(SSL_CONNECTION *s);
3349
__owur int srp_verify_server_param(SSL_CONNECTION *s);
3350
3351
/* statem/statem_srvr.c */
3352
3353
__owur int send_certificate_request(SSL_CONNECTION *s);
3354
3355
OCSP_RESPONSE *ossl_get_ocsp_response(SSL_CONNECTION *s, int chainidx);
3356
3357
/* statem/extensions_cust.c */
3358
3359
custom_ext_method *custom_ext_find(const custom_ext_methods *exts,
3360
    ENDPOINT role, unsigned int ext_type,
3361
    size_t *idx);
3362
3363
void custom_ext_init(custom_ext_methods *meths);
3364
3365
int ossl_tls_add_custom_ext_intern(SSL_CTX *ctx, custom_ext_methods *exts,
3366
    ENDPOINT role, unsigned int ext_type,
3367
    unsigned int context,
3368
    SSL_custom_ext_add_cb_ex add_cb,
3369
    SSL_custom_ext_free_cb_ex free_cb,
3370
    void *add_arg,
3371
    SSL_custom_ext_parse_cb_ex parse_cb,
3372
    void *parse_arg);
3373
__owur int custom_ext_parse(SSL_CONNECTION *s, unsigned int context,
3374
    unsigned int ext_type,
3375
    const unsigned char *ext_data, size_t ext_size,
3376
    X509 *x, size_t chainidx);
3377
__owur int custom_ext_add(SSL_CONNECTION *s, int context, WPACKET *pkt, X509 *x,
3378
    size_t chainidx, int maxversion);
3379
3380
__owur int custom_exts_copy(custom_ext_methods *dst,
3381
    const custom_ext_methods *src);
3382
__owur int custom_exts_copy_conn(custom_ext_methods *dst,
3383
    const custom_ext_methods *src);
3384
__owur int custom_exts_copy_flags(custom_ext_methods *dst,
3385
    const custom_ext_methods *src);
3386
void custom_exts_free(custom_ext_methods *exts);
3387
3388
/* ssl_mcnf.c */
3389
int ssl_ctx_system_config(SSL_CTX *ctx);
3390
3391
const EVP_CIPHER *ssl_evp_cipher_fetch(OSSL_LIB_CTX *libctx,
3392
    const char *name,
3393
    const char *properties);
3394
int ssl_evp_cipher_up_ref(const EVP_CIPHER *cipher);
3395
void ssl_evp_cipher_free(const EVP_CIPHER *cipher);
3396
int ssl_evp_md_up_ref(const EVP_MD *md);
3397
void ssl_evp_md_free(const EVP_MD *md);
3398
3399
SSL_HMAC *ssl_hmac_old_construct(SSL_HMAC *ret);
3400
void ssl_hmac_old_destruct(SSL_HMAC *ctx);
3401
int ssl_hmac_old_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
3402
int ssl_hmac_old_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
3403
int ssl_hmac_old_final(SSL_HMAC *ctx, unsigned char *md, size_t *len);
3404
size_t ssl_hmac_old_size(const SSL_HMAC *ctx);
3405
3406
int ssl_ctx_srp_ctx_free_intern(SSL_CTX *ctx);
3407
int ssl_ctx_srp_ctx_init_intern(SSL_CTX *ctx);
3408
int ssl_srp_ctx_free_intern(SSL_CONNECTION *s);
3409
int ssl_srp_ctx_init_intern(SSL_CONNECTION *s);
3410
3411
int ssl_srp_calc_a_param_intern(SSL_CONNECTION *s);
3412
int ssl_srp_server_param_with_username_intern(SSL_CONNECTION *s, int *ad);
3413
3414
void ssl_session_calculate_timeout(SSL_SESSION *ss);
3415
3416
#else /* OPENSSL_UNIT_TEST */
3417
3418
#define ssl_init_wbio_buffer SSL_test_functions()->p_ssl_init_wbio_buffer
3419
3420
#endif
3421
3422
/* Some helper routines to support TSAN operations safely */
3423
static ossl_unused ossl_inline int ssl_tsan_lock(const SSL_CTX *ctx)
3424
0
{
3425
#ifdef TSAN_REQUIRES_LOCKING
3426
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
3427
        return 0;
3428
#endif
3429
0
    return 1;
3430
0
}
Unexecuted instantiation: methods.c:ssl_tsan_lock
Unexecuted instantiation: s3_lib.c:ssl_tsan_lock
Unexecuted instantiation: s3_msg.c:ssl_tsan_lock
Unexecuted instantiation: ssl_cert.c:ssl_tsan_lock
Unexecuted instantiation: ssl_ciph.c:ssl_tsan_lock
Unexecuted instantiation: ssl_init.c:ssl_tsan_lock
Unexecuted instantiation: ssl_lib.c:ssl_tsan_lock
Unexecuted instantiation: ssl_mcnf.c:ssl_tsan_lock
Unexecuted instantiation: ssl_rsa.c:ssl_tsan_lock
Unexecuted instantiation: ssl_sess.c:ssl_tsan_lock
Unexecuted instantiation: ssl_stat.c:ssl_tsan_lock
Unexecuted instantiation: t1_lib.c:ssl_tsan_lock
Unexecuted instantiation: tls13_enc.c:ssl_tsan_lock
Unexecuted instantiation: tls_depr.c:ssl_tsan_lock
Unexecuted instantiation: tls_srp.c:ssl_tsan_lock
Unexecuted instantiation: quic_impl.c:ssl_tsan_lock
Unexecuted instantiation: quic_method.c:ssl_tsan_lock
Unexecuted instantiation: quic_obj.c:ssl_tsan_lock
Unexecuted instantiation: quic_port.c:ssl_tsan_lock
Unexecuted instantiation: quic_record_rx.c:ssl_tsan_lock
Unexecuted instantiation: quic_record_shared.c:ssl_tsan_lock
Unexecuted instantiation: quic_record_tx.c:ssl_tsan_lock
Unexecuted instantiation: quic_record_util.c:ssl_tsan_lock
Unexecuted instantiation: quic_thread_assist.c:ssl_tsan_lock
Unexecuted instantiation: quic_tls.c:ssl_tsan_lock
Unexecuted instantiation: rec_layer_d1.c:ssl_tsan_lock
Unexecuted instantiation: rec_layer_s3.c:ssl_tsan_lock
Unexecuted instantiation: dtls_meth.c:ssl_tsan_lock
Unexecuted instantiation: tls13_meth.c:ssl_tsan_lock
Unexecuted instantiation: tls1_meth.c:ssl_tsan_lock
Unexecuted instantiation: tls_common.c:ssl_tsan_lock
Unexecuted instantiation: tls_multib.c:ssl_tsan_lock
Unexecuted instantiation: tlsany_meth.c:ssl_tsan_lock
Unexecuted instantiation: extensions.c:ssl_tsan_lock
Unexecuted instantiation: extensions_clnt.c:ssl_tsan_lock
Unexecuted instantiation: extensions_cust.c:ssl_tsan_lock
Unexecuted instantiation: extensions_srvr.c:ssl_tsan_lock
Unexecuted instantiation: statem.c:ssl_tsan_lock
Unexecuted instantiation: statem_clnt.c:ssl_tsan_lock
Unexecuted instantiation: statem_dtls.c:ssl_tsan_lock
Unexecuted instantiation: statem_lib.c:ssl_tsan_lock
Unexecuted instantiation: statem_srvr.c:ssl_tsan_lock
Unexecuted instantiation: ech_helper.c:ssl_tsan_lock
Unexecuted instantiation: ech_internal.c:ssl_tsan_lock
Unexecuted instantiation: ech_store.c:ssl_tsan_lock
Unexecuted instantiation: d1_lib.c:ssl_tsan_lock
Unexecuted instantiation: d1_msg.c:ssl_tsan_lock
Unexecuted instantiation: d1_srtp.c:ssl_tsan_lock
Unexecuted instantiation: d1_transcript.c:ssl_tsan_lock
Unexecuted instantiation: dtls_record_rx.c:ssl_tsan_lock
Unexecuted instantiation: pqueue.c:ssl_tsan_lock
Unexecuted instantiation: s3_enc.c:ssl_tsan_lock
Unexecuted instantiation: ssl_asn1.c:ssl_tsan_lock
Unexecuted instantiation: ssl_conf.c:ssl_tsan_lock
Unexecuted instantiation: t1_enc.c:ssl_tsan_lock
Unexecuted instantiation: quic_channel.c:ssl_tsan_lock
Unexecuted instantiation: quic_engine.c:ssl_tsan_lock
Unexecuted instantiation: quic_rx_depack.c:ssl_tsan_lock
Unexecuted instantiation: poll_immediate.c:ssl_tsan_lock
3431
3432
static ossl_unused ossl_inline void ssl_tsan_unlock(const SSL_CTX *ctx)
3433
0
{
3434
#ifdef TSAN_REQUIRES_LOCKING
3435
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
3436
#endif
3437
0
}
Unexecuted instantiation: methods.c:ssl_tsan_unlock
Unexecuted instantiation: s3_lib.c:ssl_tsan_unlock
Unexecuted instantiation: s3_msg.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_cert.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_ciph.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_init.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_lib.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_mcnf.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_rsa.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_sess.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_stat.c:ssl_tsan_unlock
Unexecuted instantiation: t1_lib.c:ssl_tsan_unlock
Unexecuted instantiation: tls13_enc.c:ssl_tsan_unlock
Unexecuted instantiation: tls_depr.c:ssl_tsan_unlock
Unexecuted instantiation: tls_srp.c:ssl_tsan_unlock
Unexecuted instantiation: quic_impl.c:ssl_tsan_unlock
Unexecuted instantiation: quic_method.c:ssl_tsan_unlock
Unexecuted instantiation: quic_obj.c:ssl_tsan_unlock
Unexecuted instantiation: quic_port.c:ssl_tsan_unlock
Unexecuted instantiation: quic_record_rx.c:ssl_tsan_unlock
Unexecuted instantiation: quic_record_shared.c:ssl_tsan_unlock
Unexecuted instantiation: quic_record_tx.c:ssl_tsan_unlock
Unexecuted instantiation: quic_record_util.c:ssl_tsan_unlock
Unexecuted instantiation: quic_thread_assist.c:ssl_tsan_unlock
Unexecuted instantiation: quic_tls.c:ssl_tsan_unlock
Unexecuted instantiation: rec_layer_d1.c:ssl_tsan_unlock
Unexecuted instantiation: rec_layer_s3.c:ssl_tsan_unlock
Unexecuted instantiation: dtls_meth.c:ssl_tsan_unlock
Unexecuted instantiation: tls13_meth.c:ssl_tsan_unlock
Unexecuted instantiation: tls1_meth.c:ssl_tsan_unlock
Unexecuted instantiation: tls_common.c:ssl_tsan_unlock
Unexecuted instantiation: tls_multib.c:ssl_tsan_unlock
Unexecuted instantiation: tlsany_meth.c:ssl_tsan_unlock
Unexecuted instantiation: extensions.c:ssl_tsan_unlock
Unexecuted instantiation: extensions_clnt.c:ssl_tsan_unlock
Unexecuted instantiation: extensions_cust.c:ssl_tsan_unlock
Unexecuted instantiation: extensions_srvr.c:ssl_tsan_unlock
Unexecuted instantiation: statem.c:ssl_tsan_unlock
Unexecuted instantiation: statem_clnt.c:ssl_tsan_unlock
Unexecuted instantiation: statem_dtls.c:ssl_tsan_unlock
Unexecuted instantiation: statem_lib.c:ssl_tsan_unlock
Unexecuted instantiation: statem_srvr.c:ssl_tsan_unlock
Unexecuted instantiation: ech_helper.c:ssl_tsan_unlock
Unexecuted instantiation: ech_internal.c:ssl_tsan_unlock
Unexecuted instantiation: ech_store.c:ssl_tsan_unlock
Unexecuted instantiation: d1_lib.c:ssl_tsan_unlock
Unexecuted instantiation: d1_msg.c:ssl_tsan_unlock
Unexecuted instantiation: d1_srtp.c:ssl_tsan_unlock
Unexecuted instantiation: d1_transcript.c:ssl_tsan_unlock
Unexecuted instantiation: dtls_record_rx.c:ssl_tsan_unlock
Unexecuted instantiation: pqueue.c:ssl_tsan_unlock
Unexecuted instantiation: s3_enc.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_asn1.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_conf.c:ssl_tsan_unlock
Unexecuted instantiation: t1_enc.c:ssl_tsan_unlock
Unexecuted instantiation: quic_channel.c:ssl_tsan_unlock
Unexecuted instantiation: quic_engine.c:ssl_tsan_unlock
Unexecuted instantiation: quic_rx_depack.c:ssl_tsan_unlock
Unexecuted instantiation: poll_immediate.c:ssl_tsan_unlock
3438
3439
static ossl_unused ossl_inline void ssl_tsan_counter(const SSL_CTX *ctx,
3440
    TSAN_QUALIFIER int *stat)
3441
0
{
3442
0
    if (ssl_tsan_lock(ctx)) {
3443
0
        tsan_counter(stat);
3444
0
        ssl_tsan_unlock(ctx);
3445
0
    }
3446
0
}
Unexecuted instantiation: methods.c:ssl_tsan_counter
Unexecuted instantiation: s3_lib.c:ssl_tsan_counter
Unexecuted instantiation: s3_msg.c:ssl_tsan_counter
Unexecuted instantiation: ssl_cert.c:ssl_tsan_counter
Unexecuted instantiation: ssl_ciph.c:ssl_tsan_counter
Unexecuted instantiation: ssl_init.c:ssl_tsan_counter
Unexecuted instantiation: ssl_lib.c:ssl_tsan_counter
Unexecuted instantiation: ssl_mcnf.c:ssl_tsan_counter
Unexecuted instantiation: ssl_rsa.c:ssl_tsan_counter
Unexecuted instantiation: ssl_sess.c:ssl_tsan_counter
Unexecuted instantiation: ssl_stat.c:ssl_tsan_counter
Unexecuted instantiation: t1_lib.c:ssl_tsan_counter
Unexecuted instantiation: tls13_enc.c:ssl_tsan_counter
Unexecuted instantiation: tls_depr.c:ssl_tsan_counter
Unexecuted instantiation: tls_srp.c:ssl_tsan_counter
Unexecuted instantiation: quic_impl.c:ssl_tsan_counter
Unexecuted instantiation: quic_method.c:ssl_tsan_counter
Unexecuted instantiation: quic_obj.c:ssl_tsan_counter
Unexecuted instantiation: quic_port.c:ssl_tsan_counter
Unexecuted instantiation: quic_record_rx.c:ssl_tsan_counter
Unexecuted instantiation: quic_record_shared.c:ssl_tsan_counter
Unexecuted instantiation: quic_record_tx.c:ssl_tsan_counter
Unexecuted instantiation: quic_record_util.c:ssl_tsan_counter
Unexecuted instantiation: quic_thread_assist.c:ssl_tsan_counter
Unexecuted instantiation: quic_tls.c:ssl_tsan_counter
Unexecuted instantiation: rec_layer_d1.c:ssl_tsan_counter
Unexecuted instantiation: rec_layer_s3.c:ssl_tsan_counter
Unexecuted instantiation: dtls_meth.c:ssl_tsan_counter
Unexecuted instantiation: tls13_meth.c:ssl_tsan_counter
Unexecuted instantiation: tls1_meth.c:ssl_tsan_counter
Unexecuted instantiation: tls_common.c:ssl_tsan_counter
Unexecuted instantiation: tls_multib.c:ssl_tsan_counter
Unexecuted instantiation: tlsany_meth.c:ssl_tsan_counter
Unexecuted instantiation: extensions.c:ssl_tsan_counter
Unexecuted instantiation: extensions_clnt.c:ssl_tsan_counter
Unexecuted instantiation: extensions_cust.c:ssl_tsan_counter
Unexecuted instantiation: extensions_srvr.c:ssl_tsan_counter
Unexecuted instantiation: statem.c:ssl_tsan_counter
Unexecuted instantiation: statem_clnt.c:ssl_tsan_counter
Unexecuted instantiation: statem_dtls.c:ssl_tsan_counter
Unexecuted instantiation: statem_lib.c:ssl_tsan_counter
Unexecuted instantiation: statem_srvr.c:ssl_tsan_counter
Unexecuted instantiation: ech_helper.c:ssl_tsan_counter
Unexecuted instantiation: ech_internal.c:ssl_tsan_counter
Unexecuted instantiation: ech_store.c:ssl_tsan_counter
Unexecuted instantiation: d1_lib.c:ssl_tsan_counter
Unexecuted instantiation: d1_msg.c:ssl_tsan_counter
Unexecuted instantiation: d1_srtp.c:ssl_tsan_counter
Unexecuted instantiation: d1_transcript.c:ssl_tsan_counter
Unexecuted instantiation: dtls_record_rx.c:ssl_tsan_counter
Unexecuted instantiation: pqueue.c:ssl_tsan_counter
Unexecuted instantiation: s3_enc.c:ssl_tsan_counter
Unexecuted instantiation: ssl_asn1.c:ssl_tsan_counter
Unexecuted instantiation: ssl_conf.c:ssl_tsan_counter
Unexecuted instantiation: t1_enc.c:ssl_tsan_counter
Unexecuted instantiation: quic_channel.c:ssl_tsan_counter
Unexecuted instantiation: quic_engine.c:ssl_tsan_counter
Unexecuted instantiation: quic_rx_depack.c:ssl_tsan_counter
Unexecuted instantiation: poll_immediate.c:ssl_tsan_counter
3447
3448
int ossl_comp_has_alg(int a);
3449
size_t ossl_calculate_comp_expansion(int alg, size_t length);
3450
3451
void ossl_ssl_set_custom_record_layer(SSL_CONNECTION *s,
3452
    const OSSL_RECORD_METHOD *meth,
3453
    void *rlarg);
3454
3455
long ossl_ctrl_internal(SSL *s, int cmd, long larg, void *parg, int no_quic);
3456
3457
/*
3458
 * Options which no longer have any effect, but which can be implemented
3459
 * as no-ops for QUIC.
3460
 */
3461
#define OSSL_LEGACY_SSL_OPTIONS \
3462
0
    (SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG | SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER | SSL_OP_SSLEAY_080_CLIENT_DH_BUG | SSL_OP_TLS_D5_BUG | SSL_OP_TLS_BLOCK_PADDING_BUG | SSL_OP_MSIE_SSLV2_RSA_PADDING | SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG | SSL_OP_MICROSOFT_SESS_ID_BUG | SSL_OP_NETSCAPE_CHALLENGE_BUG | SSL_OP_PKCS1_CHECK_1 | SSL_OP_PKCS1_CHECK_2 | SSL_OP_SINGLE_DH_USE | SSL_OP_SINGLE_ECDH_USE | SSL_OP_EPHEMERAL_RSA)
3463
3464
/* This option is undefined in public headers with no-dtls1-method. */
3465
#ifndef SSL_OP_CISCO_ANYCONNECT
3466
#define SSL_OP_CISCO_ANYCONNECT 0
3467
#endif
3468
/*
3469
 * Options which are no-ops under QUIC or TLSv1.3 and which are therefore
3470
 * allowed but ignored under QUIC.
3471
 */
3472
#define OSSL_TLS1_2_OPTIONS \
3473
0
    (SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS | SSL_OP_ALLOW_CLIENT_RENEGOTIATION | SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION | SSL_OP_NO_COMPRESSION | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2 | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_CISCO_ANYCONNECT | SSL_OP_NO_RENEGOTIATION | SSL_OP_NO_EXTENDED_MASTER_SECRET | SSL_OP_NO_ENCRYPT_THEN_MAC | SSL_OP_COOKIE_EXCHANGE | SSL_OP_LEGACY_SERVER_CONNECT | SSL_OP_IGNORE_UNEXPECTED_EOF)
3474
3475
/* Total mask of connection-level options permitted or ignored under QUIC. */
3476
#define OSSL_QUIC_PERMITTED_OPTIONS_CONN \
3477
0
    (OSSL_LEGACY_SSL_OPTIONS | OSSL_TLS1_2_OPTIONS | SSL_OP_SERVER_PREFERENCE | SSL_OP_DISABLE_TLSEXT_CA_NAMES | SSL_OP_NO_TX_CERTIFICATE_COMPRESSION | SSL_OP_NO_RX_CERTIFICATE_COMPRESSION | SSL_OP_PRIORITIZE_CHACHA | SSL_OP_NO_QUERY_MTU | SSL_OP_NO_TICKET | SSL_OP_NO_ANTI_REPLAY)
3478
3479
/* Total mask of stream-level options permitted or ignored under QUIC. */
3480
#define OSSL_QUIC_PERMITTED_OPTIONS_STREAM \
3481
0
    (OSSL_LEGACY_SSL_OPTIONS | OSSL_TLS1_2_OPTIONS | SSL_OP_CLEANSE_PLAINTEXT)
3482
3483
/* Total mask of options permitted on either connections or streams. */
3484
#define OSSL_QUIC_PERMITTED_OPTIONS \
3485
0
    (OSSL_QUIC_PERMITTED_OPTIONS_CONN | OSSL_QUIC_PERMITTED_OPTIONS_STREAM)
3486
3487
/* Total mask of domain flags supported on a QUIC SSL_CTX. */
3488
#define OSSL_QUIC_SUPPORTED_DOMAIN_FLAGS \
3489
0
    (SSL_DOMAIN_FLAG_SINGLE_THREAD | SSL_DOMAIN_FLAG_MULTI_THREAD | SSL_DOMAIN_FLAG_THREAD_ASSISTED | SSL_DOMAIN_FLAG_BLOCKING | SSL_DOMAIN_FLAG_LEGACY_BLOCKING)
3490
3491
#endif