Coverage Report

Created: 2026-10-16 07:31

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
            /* Client identity awaiting verification */
1511
            STACK_OF(X509) *pending_peer_chain;
1512
            EVP_PKEY *pending_peer_rpk;
1513
            /*
1514
             * signature algorithms peer reports: e.g. supported signature
1515
             * algorithms extension for server or as part of a certificate
1516
             * request for client.
1517
             * Keep track of the algorithms for TLS and X.509 usage separately.
1518
             */
1519
            uint16_t *peer_sigalgs;
1520
            uint16_t *peer_cert_sigalgs;
1521
            /* Size of above arrays */
1522
            size_t peer_sigalgslen;
1523
            size_t peer_cert_sigalgslen;
1524
            /* Sigalg peer actually uses */
1525
            const struct sigalg_lookup_st *peer_sigalg;
1526
            /*
1527
             * Set if corresponding CERT_PKEY can be used with current
1528
             * SSL session: e.g. appropriate curve, signature algorithms etc.
1529
             * If zero it can't be used at all.
1530
             */
1531
            uint32_t *valid_flags;
1532
            /*
1533
             * For servers the following masks are for the key and auth algorithms
1534
             * that are supported by the certs below. For clients they are masks of
1535
             * *disabled* algorithms based on the current session.
1536
             */
1537
            uint32_t mask_k;
1538
            uint32_t mask_a;
1539
            /*
1540
             * The following are used by the client to see if a cipher is allowed or
1541
             * not.  It contains the minimum and maximum version the client's using
1542
             * based on what it knows so far.
1543
             */
1544
            int min_ver;
1545
            int max_ver;
1546
        } tmp;
1547
1548
        /* Connection binding to prevent renegotiation attacks */
1549
        unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1550
        size_t previous_client_finished_len;
1551
        unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1552
        size_t previous_server_finished_len;
1553
        int send_connection_binding;
1554
1555
#ifndef OPENSSL_NO_NEXTPROTONEG
1556
        /*
1557
         * Set if we saw the Next Protocol Negotiation extension from our peer.
1558
         */
1559
        int npn_seen;
1560
#endif
1561
1562
        /*
1563
         * ALPN information (we are in the process of transitioning from NPN to
1564
         * ALPN.)
1565
         */
1566
1567
        /*
1568
         * In a server these point to the selected ALPN protocol after the
1569
         * ClientHello has been processed. In a client these contain the protocol
1570
         * that the server selected once the ServerHello has been processed.
1571
         */
1572
        unsigned char *alpn_selected;
1573
        size_t alpn_selected_len;
1574
        /* used by the server to know what options were proposed */
1575
        unsigned char *alpn_proposed;
1576
        size_t alpn_proposed_len;
1577
        /* used by the client to know if it actually sent alpn */
1578
        int alpn_sent;
1579
1580
        /*
1581
         * This is set to true if we believe that this is a version of Safari
1582
         * running on OS X 10.6 or newer. We wish to know this because Safari on
1583
         * 10.8 .. 10.8.3 has broken ECDHE-ECDSA support.
1584
         */
1585
        char is_probably_safari;
1586
1587
        /*
1588
         * Track whether we did a key exchange this handshake or not, so
1589
         * SSL_get_negotiated_group() knows whether to fall back to the
1590
         * value in the SSL_SESSION.
1591
         */
1592
        char did_kex;
1593
        /* For clients: peer temporary key */
1594
        /* The group_id for the key exchange key */
1595
        uint16_t group_id;
1596
        EVP_PKEY *peer_tmp;
1597
        /* The cached group_id candidate for the key exchange key */
1598
        uint16_t group_id_candidate;
1599
    } s3;
1600
1601
    struct dtls1_state_st *d1; /* DTLSv1 variables */
1602
#ifndef OPENSSL_NO_DTLS
1603
    /* Stable alias for d1->rx while SSL_clear() resets or replaces d1. */
1604
    DTLS_RX *listener_rx;
1605
    /*
1606
     * Set when this connection is being driven by dtls_listener_drive_pending().
1607
     * Used to prevent multiple threads from driving the same connection
1608
     * concurrently and to allow the demux pump to be called without holding
1609
     * the listener mutex.
1610
     */
1611
    unsigned int listener_being_driven;
1612
    /*
1613
     * Set while the listener itself is driving this connection's handshake, to
1614
     * stop it blocking. The listener drives pending connections from inside its
1615
     * own tick, so a connection which blocked there would stop the listener
1616
     * making any further progress, including the progress being waited for.
1617
     */
1618
    unsigned int listener_force_nonblocking;
1619
#endif
1620
    /* callback that allows applications to peek at protocol messages */
1621
    void (*msg_callback)(int write_p, int version, int content_type,
1622
        const void *buf, size_t len, SSL *ssl, void *arg);
1623
    void *msg_callback_arg;
1624
    int hit; /* reusing a previous session */
1625
    X509_VERIFY_PARAM *param;
1626
    /* Per connection DANE state */
1627
    SSL_DANE dane;
1628
    /* crypto */
1629
    STACK_OF(SSL_CIPHER) *peer_ciphers;
1630
    STACK_OF(SSL_CIPHER) *cipher_list;
1631
    STACK_OF(SSL_CIPHER) *cipher_list_by_id;
1632
    /* TLSv1.3 specific ciphersuites */
1633
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
1634
    /*
1635
     * These are the ones being used, the ones in SSL_SESSION are the ones to
1636
     * be 'copied' into these ones
1637
     */
1638
    uint32_t mac_flags;
1639
    /*
1640
     * The TLS1.3 secrets.
1641
     */
1642
    unsigned char early_secret[EVP_MAX_MD_SIZE];
1643
    unsigned char handshake_secret[EVP_MAX_MD_SIZE];
1644
    unsigned char master_secret[EVP_MAX_MD_SIZE];
1645
    unsigned char resumption_master_secret[EVP_MAX_MD_SIZE];
1646
    unsigned char client_finished_secret[EVP_MAX_MD_SIZE];
1647
    unsigned char server_finished_secret[EVP_MAX_MD_SIZE];
1648
    unsigned char server_finished_hash[EVP_MAX_MD_SIZE];
1649
    unsigned char handshake_traffic_hash[EVP_MAX_MD_SIZE];
1650
    unsigned char client_app_traffic_secret[EVP_MAX_MD_SIZE];
1651
    unsigned char server_app_traffic_secret[EVP_MAX_MD_SIZE];
1652
    unsigned char exporter_master_secret[EVP_MAX_MD_SIZE];
1653
    unsigned char early_exporter_master_secret[EVP_MAX_MD_SIZE];
1654
1655
    /* session info */
1656
    /* client cert? */
1657
    /* This is used to hold the server certificate used */
1658
    struct cert_st /* CERT */ *cert;
1659
1660
    /*
1661
     * The hash of all messages prior to the CertificateVerify, and the length
1662
     * of that hash.
1663
     */
1664
    unsigned char cert_verify_hash[EVP_MAX_MD_SIZE];
1665
    size_t cert_verify_hash_len;
1666
1667
    /* Flag to indicate whether we should send a HelloRetryRequest or not */
1668
    enum { SSL_HRR_NONE = 0,
1669
        SSL_HRR_PENDING,
1670
        SSL_HRR_COMPLETE } hello_retry_request;
1671
1672
    /*
1673
     * the session_id_context is used to ensure sessions are only reused in
1674
     * the appropriate context
1675
     */
1676
    size_t sid_ctx_length;
1677
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1678
    /* This can also be in the session once a session is established */
1679
    SSL_SESSION *session;
1680
    /* TLSv1.3 PSK session */
1681
    SSL_SESSION *psksession;
1682
    unsigned char *psksession_id;
1683
    size_t psksession_id_len;
1684
    /* Default generate session ID callback. */
1685
    GEN_SESSION_CB generate_session_id;
1686
    /*
1687
     * The temporary TLSv1.3 session id. This isn't really a session id at all
1688
     * but is a random value sent in the legacy session id field.
1689
     */
1690
    unsigned char tmp_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
1691
    size_t tmp_session_id_len;
1692
    /* Used in SSL3 */
1693
    /*
1694
     * 0 don't care about verify failure.
1695
     * 1 fail if verify fails
1696
     */
1697
    uint32_t verify_mode;
1698
    /* fail if callback returns 0 */
1699
    int (*verify_callback)(int ok, X509_STORE_CTX *ctx);
1700
    /* optional informational callback */
1701
    void (*info_callback)(const SSL *ssl, int type, int val);
1702
    /* error bytes to be written */
1703
    int error;
1704
    /* actual code */
1705
    int error_code;
1706
#ifndef OPENSSL_NO_PSK
1707
    SSL_psk_client_cb_func psk_client_callback;
1708
    SSL_psk_server_cb_func psk_server_callback;
1709
#endif
1710
    SSL_psk_find_session_cb_func psk_find_session_cb;
1711
    SSL_psk_use_session_cb_func psk_use_session_cb;
1712
1713
    /* Verified chain of peer */
1714
    STACK_OF(X509) *verified_chain;
1715
    long verify_result;
1716
    /*
1717
     * What we put in certificate_authorities extension for TLS 1.3
1718
     * (ClientHello and CertificateRequest) or just client cert requests for
1719
     * earlier versions. If client_ca_names is populated then it is only used
1720
     * for client cert requests, and in preference to ca_names.
1721
     */
1722
    STACK_OF(X509_NAME) *ca_names;
1723
    STACK_OF(X509_NAME) *client_ca_names;
1724
    /* protocol behaviour */
1725
    uint64_t options;
1726
    /* API behaviour */
1727
    uint32_t mode;
1728
    int min_proto_version;
1729
    int max_proto_version;
1730
    size_t max_cert_list;
1731
    int first_packet;
1732
    /*
1733
     * What was passed in ClientHello.legacy_version. Used for RSA pre-master
1734
     * secret and (D)TLS (<=1.2) rollback check
1735
     */
1736
    int client_version;
1737
    /*
1738
     * If we're using more than one pipeline how should we divide the data
1739
     * up between the pipes?
1740
     */
1741
    size_t split_send_fragment;
1742
    /*
1743
     * Maximum amount of data to send in one fragment. actual record size can
1744
     * be more than this due to padding and MAC overheads.
1745
     */
1746
    size_t max_send_fragment;
1747
    /* Up to how many pipelines should we use? If 0 then 1 is assumed */
1748
    size_t max_pipelines;
1749
1750
    struct {
1751
        /* Built-in extension flags */
1752
        uint8_t extflags[TLSEXT_IDX_num_builtins];
1753
        /* TLS extension debug callback */
1754
        void (*debug_cb)(SSL *s, int client_server, int type,
1755
            const unsigned char *data, int len, void *arg);
1756
        void *debug_arg;
1757
        char *hostname;
1758
        /* certificate status request info */
1759
        /* Status type or -1 if no status type */
1760
        int status_type;
1761
        /* Raw extension data, if seen */
1762
        unsigned char *scts;
1763
        /* Length of raw extension data, if seen */
1764
        uint16_t scts_len;
1765
1766
        struct {
1767
            /* OCSP status request only */
1768
            STACK_OF(OCSP_RESPID) *ids;
1769
            X509_EXTENSIONS *exts;
1770
            /* OCSP response received or to be sent */
1771
            unsigned char *resp;
1772
            size_t resp_len;
1773
            STACK_OF(OCSP_RESPONSE) *resp_ex;
1774
        } ocsp;
1775
1776
        /* TLS 1.3 tickets requested by the application. */
1777
        int extra_tickets_expected;
1778
1779
        /*
1780
         * Peer's advertised ec_point_formats list (TLS 1.2 and below),
1781
         * retained as received so SSL_get0_ec_point_formats() can return
1782
         * it verbatim.  Point format no longer influences cert selection
1783
         * or acceptance; the parse hook validates RFC 4492/8422 section
1784
         * 5.1.2 ("uncompressed" must be present) inline.
1785
         */
1786
        size_t peer_ecpointformats_len;
1787
        unsigned char *peer_ecpointformats;
1788
1789
        /* our list */
1790
        size_t supportedgroups_len;
1791
        uint16_t *supportedgroups;
1792
        /* peer's list */
1793
        size_t peer_supportedgroups_len;
1794
        uint16_t *peer_supportedgroups;
1795
1796
        /* key shares */
1797
        size_t keyshares_len;
1798
        uint16_t *keyshares;
1799
        /* supported groups tuples */
1800
        size_t tuples_len;
1801
        size_t *tuples;
1802
1803
        /* TLS Session Ticket extension override */
1804
        TLS_SESSION_TICKET_EXT *session_ticket;
1805
        /* TLS Session Ticket extension callback */
1806
        tls_session_ticket_ext_cb_fn session_ticket_cb;
1807
        void *session_ticket_cb_arg;
1808
        /* TLS pre-shared secret session resumption */
1809
        tls_session_secret_cb_fn session_secret_cb;
1810
        void *session_secret_cb_arg;
1811
        /*
1812
         * For a client, this contains the list of supported protocols in wire
1813
         * format.
1814
         */
1815
        unsigned char *alpn;
1816
        size_t alpn_len;
1817
        /*
1818
         * Next protocol negotiation. For the client, this is the protocol that
1819
         * we sent in NextProtocol and is set when handling ServerHello
1820
         * extensions. For a server, this is the client's selected_protocol from
1821
         * NextProtocol and is set when handling the NextProtocol message, before
1822
         * the Finished message.
1823
         */
1824
        unsigned char *npn;
1825
        size_t npn_len;
1826
1827
        /* The available PSK key exchange modes */
1828
        int psk_kex_mode;
1829
1830
        /* Are we expecting to receive early data? */
1831
        int early_data;
1832
1833
        /* May be sent by a server in HRR. Must be echoed back in ClientHello */
1834
        unsigned char *tls13_cookie;
1835
        size_t tls13_cookie_len;
1836
1837
        /*
1838
         * Maximum Fragment Length as per RFC 4366.
1839
         * If this member contains one of the allowed values (1-4)
1840
         * then we should include Maximum Fragment Length Negotiation
1841
         * extension in Client Hello.
1842
         * Please note that value of this member does not have direct
1843
         * effect. The actual (binding) value is stored in SSL_SESSION,
1844
         * as this extension is optional on server side.
1845
         */
1846
        uint8_t max_fragment_len_mode;
1847
1848
        /*
1849
         * On the client side the number of ticket identities we sent in the
1850
         * ClientHello. On the server side the identity of the ticket we
1851
         * selected.
1852
         */
1853
        int tick_identity;
1854
1855
        /*
1856
         * Cached result of the resumption ticket age/lifetime check for the
1857
         * ClientHello under construction. Time-dependent, double-checked
1858
         * within the same flight (see tls13_check_tick_lifetime_hint()).
1859
         */
1860
        uint32_t tick_age_ms;
1861
1862
        /*
1863
         * The first-offered PSK, the one that keys any 0-RTT, recorded while
1864
         * the ClientHello is built -- the resumption session when we offer it,
1865
         * else the external psksession; NULL when no 0-RTT is offered. Held
1866
         * (up-ref'd) so it stays valid across the post-ServerHello swap, and
1867
         * read by the binder, the early-key derivation, the early exporter and
1868
         * the byte-budget lookup. Freed at handshake reset and connection free.
1869
         */
1870
        SSL_SESSION *early_data_session;
1871
1872
        /* This is the list of algorithms the peer supports that we also support */
1873
        int compress_certificate_from_peer[TLSEXT_comp_cert_limit];
1874
1875
        uint8_t client_cert_type;
1876
        uint8_t client_cert_type_ctos;
1877
        uint8_t server_cert_type;
1878
        uint8_t server_cert_type_ctos;
1879
1880
#ifndef OPENSSL_NO_ECH
1881
        OSSL_ECH_CONN ech;
1882
#endif
1883
1884
        /* RFC 8701 GREASE */
1885
        uint8_t grease_seed[OSSL_GREASE_LAST_INDEX + 1];
1886
1887
        /* "bool" fields go last, for slightly better packing */
1888
        bool grease_seeded;
1889
1890
        /* Expect OCSP CertificateStatus message */
1891
        bool status_expected;
1892
1893
        /* RFC4507 session ticket expected to be received or sent */
1894
        bool ticket_expected;
1895
1896
        /* Set to one if we have negotiated ETM */
1897
        bool use_etm;
1898
1899
        /* Is the session perhaps suitable for early data? */
1900
        bool early_data_ok;
1901
1902
        /* Was the session found unsuitable for early data? */
1903
        bool early_data_suppressed;
1904
1905
        /*
1906
         * Cached result of the resumption ticket age/lifetime check for the
1907
         * ClientHello under construction. Time-dependent, double-checked
1908
         * within the same flight (see tls13_check_tick_lifetime_hint()).
1909
         */
1910
        bool tick_age_checked;
1911
        bool tick_age_ok;
1912
1913
        /*
1914
         * Client-only. Whether the loaded resumption ticket (s->session)
1915
         * qualifies as an offered PSK for the ClientHello under construction.
1916
         * Frozen once by tls_construct_ctos_early_data() (the first consumer,
1917
         * which also decides 0-RTT from it) so tls_construct_ctos_psk() offers
1918
         * exactly the same identity 0 -- never re-evaluating the SECOP-dependent
1919
         * tls13_digest_offered() a second time, which could otherwise drop the
1920
         * ticket after early_data was already committed and leave the early
1921
         * secret underived.
1922
         */
1923
        bool psk_resumption_offered;
1924
1925
        /*
1926
         * Client-only. Set in tls_psk_do_binder() when the first-offered PSK's
1927
         * binder derives s->early_secret for the current ClientHello flight;
1928
         * reset at the top of tls_construct_ctos_early_data(). The early-write
1929
         * key install (tls13_change_cipher_state()) refuses to proceed unless it
1930
         * is set, so 0-RTT can never be keyed off an underived (all-zero)
1931
         * s->early_secret even if the offer and early_data decisions somehow
1932
         * diverge.
1933
         */
1934
        bool early_secret_derived;
1935
1936
        /*
1937
         * Records that an early exporter secret actually exists.  It may not
1938
         * yet be computed if the CH1 write blocks early enough.  Remains
1939
         * unchanged after CH2.
1940
         */
1941
        bool early_exporter_ready;
1942
1943
        /* Have we received a cookie from the client? */
1944
        bool cookieok;
1945
1946
        /* indicate that we sent the extension, so we'll accept it */
1947
        bool compress_certificate_sent;
1948
    } ext;
1949
1950
    /*
1951
     * Parsed form of the ClientHello, kept around across client_hello_cb
1952
     * calls.
1953
     */
1954
    CLIENTHELLO_MSG *clienthello;
1955
1956
    /*-
1957
     * no further mod of servername
1958
     * 0 : call the servername extension callback.
1959
     * 1 : prepare 2, allow last ack just after in server callback.
1960
     * 2 : don't call servername callback, no ack in server hello
1961
     */
1962
    int servername_done;
1963
#ifndef OPENSSL_NO_CT
1964
    /*
1965
     * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
1966
     * If they are not, the connection should be aborted.
1967
     */
1968
    ssl_ct_validation_cb ct_validation_callback;
1969
    /* User-supplied argument that is passed to the ct_validation_callback */
1970
    void *ct_validation_callback_arg;
1971
    /*
1972
     * Consolidated stack of SCTs from all sources.
1973
     * Lazily populated by CT_get_peer_scts(SSL*)
1974
     */
1975
    STACK_OF(SCT) *scts;
1976
    /* Have we attempted to find/parse SCTs yet? */
1977
    int scts_parsed;
1978
#endif
1979
    SSL_CTX *session_ctx; /* initial ctx, used to store sessions */
1980
#ifndef OPENSSL_NO_SRTP
1981
    /* What we'll do */
1982
    STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
1983
    /* What's been chosen */
1984
    SRTP_PROTECTION_PROFILE *srtp_profile;
1985
#endif
1986
    /*-
1987
     * 1 if we are renegotiating.
1988
     * 2 if we are a server and are inside a handshake
1989
     * (i.e. not just sending a HelloRequest)
1990
     */
1991
    int renegotiate;
1992
    /* If sending a KeyUpdate is pending */
1993
    int key_update;
1994
    /* Post-handshake authentication state */
1995
    SSL_PHA_STATE post_handshake_auth;
1996
    int pha_enabled;
1997
    uint8_t *pha_context;
1998
    size_t pha_context_len;
1999
    int certreqs_sent;
2000
    EVP_MD_CTX *pha_dgst; /* this is just the digest through ClientFinished */
2001
2002
#ifndef OPENSSL_NO_SRP
2003
    /* ctx for SRP authentication */
2004
    SRP_CTX srp_ctx;
2005
#endif
2006
    /*
2007
     * Callback for disabling session caching and ticket support on a session
2008
     * basis, depending on the chosen cipher.
2009
     */
2010
    int (*not_resumable_session_cb)(SSL *ssl, int is_forward_secure);
2011
2012
    /* Record layer data */
2013
    RECORD_LAYER rlayer;
2014
2015
    /* Default password callback. */
2016
    pem_password_cb *default_passwd_callback;
2017
    /* Default password callback user data. */
2018
    void *default_passwd_callback_userdata;
2019
    /* Async Job info */
2020
    ASYNC_JOB *job;
2021
    ASYNC_WAIT_CTX *waitctx;
2022
    size_t asyncrw;
2023
2024
    /*
2025
     * The maximum number of bytes advertised in session tickets that can be
2026
     * sent as early data.
2027
     */
2028
    uint32_t max_early_data;
2029
    /*
2030
     * The maximum number of bytes of early data that a server will tolerate
2031
     * (which should be at least as much as max_early_data).
2032
     */
2033
    uint32_t recv_max_early_data;
2034
2035
    /*
2036
     * The number of bytes of early data received so far. If we accepted early
2037
     * data then this is a count of the plaintext bytes. If we rejected it then
2038
     * this is a count of the ciphertext bytes.
2039
     */
2040
    uint32_t early_data_count;
2041
2042
    /* The number of TLS1.3 tickets to automatically send */
2043
    size_t num_tickets;
2044
    /* The number of TLS1.3 tickets actually sent so far */
2045
    size_t sent_tickets;
2046
    /* The next nonce value to use when we send a ticket on this connection */
2047
    uint64_t next_ticket_nonce;
2048
2049
    /* Callback to determine if early_data is acceptable or not */
2050
    SSL_allow_early_data_cb_fn allow_early_data_cb;
2051
    void *allow_early_data_cb_data;
2052
2053
    /* Callback for SSL async handling */
2054
    SSL_async_callback_fn async_cb;
2055
    void *async_cb_arg;
2056
2057
    /*
2058
     * Signature algorithms shared by client and server: cached because these
2059
     * are used most often.
2060
     */
2061
    const struct sigalg_lookup_st **shared_sigalgs;
2062
    size_t shared_sigalgslen;
2063
2064
#ifndef OPENSSL_NO_COMP_ALG
2065
    /* certificate compression preferences */
2066
    int cert_comp_prefs[TLSEXT_comp_cert_limit];
2067
#endif
2068
2069
    /* Certificate Type stuff - for RPK vs X.509 */
2070
    unsigned char *client_cert_type;
2071
    size_t client_cert_type_len;
2072
    unsigned char *server_cert_type;
2073
    size_t server_cert_type_len;
2074
2075
    /* DTLS 1.3 needs to know when we have processed the Client/Server Hello */
2076
    int dtls13_process_hello;
2077
};
2078
2079
/*
2080
 * Structure containing table entry of values associated with the signature
2081
 * algorithms (signature scheme) extension
2082
 */
2083
typedef struct sigalg_lookup_st {
2084
    /* TLS 1.3 signature scheme name */
2085
    const char *name;
2086
    /* TLS 1.2 signature scheme name */
2087
    const char *name12;
2088
    /* Raw value used in extension */
2089
    uint16_t sigalg;
2090
    /* NID of hash algorithm or NID_undef if no hash */
2091
    int hash;
2092
    /* Index of hash algorithm or -1 if no hash algorithm */
2093
    int hash_idx;
2094
    /* NID of signature algorithm */
2095
    int sig;
2096
    /* Index of signature algorithm */
2097
    int sig_idx;
2098
    /* Combined hash and signature NID, if any */
2099
    int sigandhash;
2100
    /* Required public key curve (ECDSA only) */
2101
    int curve;
2102
    /* Whether this signature algorithm is actually available for use */
2103
    int available;
2104
    /* Whether this signature algorithm is by default advertised */
2105
    int advertise;
2106
    /* Supported protocol ranges */
2107
    int mintls;
2108
    int maxtls;
2109
    int mindtls;
2110
    int maxdtls;
2111
} SIGALG_LOOKUP;
2112
2113
typedef enum downgrade_en {
2114
    DOWNGRADE_NONE,
2115
    DOWNGRADE_TO_1_2,
2116
    DOWNGRADE_TO_1_1
2117
} DOWNGRADE;
2118
2119
/* DTLS structures */
2120
2121
#ifndef OPENSSL_NO_SCTP
2122
#define DTLS1_SCTP_AUTH_LABEL "EXPORTER_DTLS_OVER_SCTP"
2123
#endif
2124
2125
/* Max MTU overhead we know about so far is 40 for IPv6 + 8 for UDP */
2126
0
#define DTLS1_MAX_MTU_OVERHEAD 48
2127
2128
struct dtls1_retransmit_state {
2129
    const OSSL_RECORD_METHOD *wrlmethod;
2130
    OSSL_RECORD_LAYER *wrl;
2131
};
2132
2133
struct hm_header_st {
2134
    unsigned char type;
2135
    size_t msg_len;
2136
    unsigned short seq;
2137
    size_t frag_off;
2138
    size_t frag_len;
2139
};
2140
2141
typedef struct hm_fragment_st {
2142
    struct hm_header_st msg_header;
2143
    unsigned char *fragment;
2144
    unsigned char *reassembly;
2145
} hm_fragment;
2146
2147
typedef struct pqueue_st pqueue;
2148
typedef struct pitem_st pitem;
2149
2150
struct pqueue_st {
2151
    pitem *items;
2152
    int count;
2153
};
2154
2155
struct pitem_st {
2156
    unsigned char priority[8]; /* 64-bit value in big-endian encoding */
2157
    void *data;
2158
    pitem *next;
2159
};
2160
2161
typedef struct pitem_st *piterator;
2162
2163
pitem *pitem_new(unsigned char *prio64be, void *data);
2164
pitem *pitem_new_u64(uint64_t prio, void *data);
2165
void pitem_free(pitem *item);
2166
pqueue *pqueue_new(void);
2167
void pqueue_free(pqueue *pq);
2168
pitem *pqueue_insert(pqueue *pq, pitem *item);
2169
pitem *pqueue_peek(pqueue *pq);
2170
pitem *pqueue_pop(pqueue *pq);
2171
pitem *pqueue_find(pqueue *pq, unsigned char *prio64be);
2172
pitem *pqueue_find_u64(pqueue *pq, uint64_t prio);
2173
pitem *pqueue_iterator(pqueue *pq);
2174
pitem *pqueue_next(piterator *iter);
2175
size_t pqueue_size(pqueue *pq);
2176
2177
typedef struct dtls_msg_info_st {
2178
    unsigned char record_type;
2179
    unsigned char msg_type;
2180
    size_t msg_body_len;
2181
    unsigned short msg_seq;
2182
} dtls_msg_info;
2183
2184
/* RFC 9147, section 4: a 64-bit epoch and a 64-bit sequence number. */
2185
0
#define DTLS13_RECORD_NUMBER_LEN 16
2186
/* RFC 9147, section 7: the ACK vector's two-byte length prefix. */
2187
0
#define DTLS13_ACK_HEADER_LEN 2
2188
/* A nonempty ACK contains the prefix and at least one record number. */
2189
#define DTLS13_ACK_MIN_NONEMPTY_LEN \
2190
0
    (DTLS13_ACK_HEADER_LEN + DTLS13_RECORD_NUMBER_LEN)
2191
2192
/* rfc9147, section 4 */
2193
typedef struct dtls1_record_number_st DTLS1_RECORD_NUMBER;
2194
2195
struct dtls1_record_number_st {
2196
    uint64_t epoch;
2197
    uint64_t seqnum;
2198
    /*
2199
     * Byte range within the message this record number's transmission
2200
     * covered. Only meaningful for entries on a dtls_sent_msg's rec_nums;
2201
     * unused (left 0) for entries on the incoming ack_rec_num list.
2202
     */
2203
    size_t frag_off;
2204
    size_t frag_len;
2205
    OSSL_LIST_MEMBER(record_number, DTLS1_RECORD_NUMBER);
2206
};
2207
2208
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
2209
0
2210
0
DTLS1_RECORD_NUMBER *dtls1_record_number_new(uint64_t epoch, uint64_t seqnum,
2211
0
    size_t frag_off, size_t frag_len);
2212
0
2213
0
void ossl_list_record_number_elem_free(OSSL_LIST(record_number) *p_list);
2214
0
2215
0
typedef struct dtls_sent_msg_st {
2216
0
    dtls_msg_info msg_info;
2217
0
    OSSL_LIST(record_number)
2218
0
    rec_nums;
2219
0
    unsigned char *msg_buf;
2220
0
    /*
2221
0
     * Bitmask of msg_info.msg_body_len bytes, one bit per byte, tracking
2222
0
     * which byte ranges of the message have been acknowledged so far --
2223
0
     * across every transmission round, not just the most recent one. A
2224
0
     * trailing allocation off the end of this struct (see
2225
0
     * dtls1_sent_msg_new()), mirroring how hm_fragment tracks receive-side
2226
0
     * reassembly. NULL when msg_info.msg_body_len == 0 (nothing to cover).
2227
0
     */
2228
0
    unsigned char *covered;
2229
0
    struct dtls1_retransmit_state saved_retransmit_state;
2230
0
} dtls_sent_msg;
2231
0
2232
0
int dtls_any_sent_messages_are_missing_acknowledge(SSL_CONNECTION *s);
2233
0
2234
0
static ossl_inline int dtls_msg_needs_ack(int sentbyserver, unsigned char msgtype)
2235
0
{
2236
0
    switch (msgtype) {
2237
0
    case SSL3_MT_NEWSESSION_TICKET:
2238
0
    case SSL3_MT_KEY_UPDATE:
2239
0
        return 1;
2240
2241
0
    case SSL3_MT_CERTIFICATE:
2242
0
    case SSL3_MT_COMPRESSED_CERTIFICATE:
2243
0
    case SSL3_MT_CERTIFICATE_VERIFY:
2244
0
    case SSL3_MT_FINISHED:
2245
0
        if (!sentbyserver)
2246
0
            return 1;
2247
        /* fall-through */
2248
0
    default:
2249
0
        return 0;
2250
0
    }
2251
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
2252
2253
typedef struct dtls1_state_st {
2254
    unsigned char cookie[DTLS1_COOKIE_LENGTH];
2255
    size_t cookie_len;
2256
    unsigned int cookie_verified;
2257
    /* handshake message numbers */
2258
    unsigned short handshake_write_seq;
2259
    unsigned short next_handshake_write_seq;
2260
    unsigned short handshake_read_seq;
2261
    /* Buffered received handshake messages */
2262
    pqueue rcvd_messages;
2263
    /* Buffered (sent) handshake records */
2264
    pqueue sent_messages;
2265
    /* Flag to indicate current HelloVerifyRequest status */
2266
    enum { SSL_HVR_NONE = 0,
2267
        SSL_HVR_RECEIVED,
2268
        SSL_HVR_SENT } hello_verify_request;
2269
    DOWNGRADE downgrade_after_hvr; /* Only used by a stateful server */
2270
    size_t link_mtu; /* max on-the-wire DTLS packet size */
2271
    size_t mtu; /* max DTLS packet size */
2272
    dtls_msg_info w_msg;
2273
    /*
2274
     * Byte range of the handshake fragment currently being written by
2275
     * dtls1_do_write(), read back by do_dtls1_write() (rec_layer_d1.c) when
2276
     * recording this write's record number on the buffered sent message.
2277
     */
2278
    size_t w_frag_off;
2279
    size_t w_frag_len;
2280
    unsigned short r_msg_seq;
2281
    /* Number of alerts received so far */
2282
    unsigned int timeout_num_alerts;
2283
    /*
2284
     * Indicates when the last handshake msg sent will timeout
2285
     */
2286
    OSSL_TIME next_timeout;
2287
    /* Timeout duration */
2288
    unsigned int timeout_duration_us;
2289
2290
    unsigned int retransmitting;
2291
    unsigned int has_change_cipher_spec;
2292
#ifndef OPENSSL_NO_SCTP
2293
    int shutdown_received;
2294
#endif
2295
2296
    /* Sequence numbers that are to be acknowledged */
2297
    OSSL_LIST(record_number)
2298
    ack_rec_num;
2299
2300
    DTLS_timer_cb timer_cb;
2301
2302
#ifndef OPENSSL_NO_SOCK
2303
    /*
2304
     * Peer address for listener-created connections. When set, the record
2305
     * layer will use BIO_sendmmsg() with this address for writes instead
2306
     * of BIO_write(). This allows multiple connections to share the
2307
     * listener's network BIO.
2308
     */
2309
    BIO_ADDR peer_addr;
2310
#endif
2311
2312
#ifndef OPENSSL_NO_DTLS
2313
    /*
2314
     * DTLS_RX structure is used by the DTLS Listener and
2315
     * contains the DGRAM_DEMUX and DGRAM_URXE_LIST of
2316
     * pending packets.
2317
     */
2318
    DTLS_RX *rx;
2319
2320
    /*
2321
     * Reference to the parent listener for connections created via
2322
     * SSL_accept_connection(). This allows the connection to trigger
2323
     * the listener's demux pump when reading data.
2324
     */
2325
    SSL *listener;
2326
2327
    /*
2328
     * Timestamp when this connection was created (for listener-created
2329
     * connections). Used to detect and clean up stale pending connections
2330
     * that haven't completed their handshake within the timeout period.
2331
     */
2332
    OSSL_TIME created_at;
2333
2334
    /*
2335
     * Blocking mode requested for this connection, as a DTLS_BLOCKING_MODE.
2336
     * Defaults to inheriting from the listener it came from.
2337
     */
2338
    unsigned int req_blocking_mode : 2;
2339
#endif
2340
2341
} DTLS1_STATE;
2342
2343
#if !defined(OPENSSL_NO_DTLS) && !defined(OPENSSL_NO_SOCK)
2344
/*
2345
 * Blocking mode of a DTLS listener or of a connection created from one.
2346
 *
2347
 * A connection set to INHERIT follows its listener, and a listener set to
2348
 * INHERIT means blocking, so blocking is the default throughout unless an
2349
 * application asks otherwise. This mirrors QUIC_BLOCKING_MODE.
2350
 */
2351
enum {
2352
    DTLS_BLOCKING_MODE_INHERIT,
2353
    DTLS_BLOCKING_MODE_NONBLOCKING,
2354
    DTLS_BLOCKING_MODE_BLOCKING
2355
};
2356
2357
/*
2358
 * Define stack of SSL for DTLS listener incoming connections.
2359
 */
2360
DEFINE_STACK_OF(SSL)
2361
2362
/*
2363
 * Default maximum number of pending connections for DTLS listeners.
2364
 */
2365
0
#define DTLS_LISTENER_DEFAULT_MAX_PENDING_CONNS 256
2366
2367
/*
2368
 * Default maximum size in bytes of a datagram a DTLS listener will receive.
2369
 * A DTLS 1.3 ClientHello carrying large (e.g. post-quantum) key shares can
2370
 * exceed the 1500-byte Ethernet MTU; default a little above it so that such a
2371
 * ClientHello, when sent unfragmented, is received whole rather than truncated.
2372
 * Applied to the listener's demuxer.
2373
 */
2374
0
#define DTLS_LISTENER_DEFAULT_MAX_DGRAM_SIZE 2000
2375
2376
/*
2377
 * Upper bound for the DTLS listener receive datagram size: nothing larger than
2378
 * the maximum UDP payload can ever arrive. It may be raised up to this ceiling
2379
 * via SSL_set_value_uint(SSL_VALUE_DTLS_LISTENER_MAX_DGRAM_SIZE).
2380
 */
2381
0
#define DTLS_LISTENER_MAX_DGRAM_SIZE 65535
2382
2383
/*
2384
 * DTLS listener SSL object type. This implements the API personality
2385
 * layer for DTLS listener objects, providing server-side connection
2386
 * demultiplexing for DTLS 1.3.
2387
 */
2388
typedef struct dtls_listener_st {
2389
    /* SSL object common header. */
2390
    struct ssl_st ssl;
2391
2392
    /*
2393
     * Mutex protecting listener-owned data structures accessed across threads:
2394
     * - pending_conns: pending connection lookup table
2395
     * - established_conns: established connection lookup table
2396
     * - incoming_connections: queue of completed connections awaiting accept
2397
     *
2398
     * Accessed from:
2399
     * - Listener thread: packet handling, driving handshakes
2400
     * - Connection thread: unregistering via SSL_free -> dtls1_free
2401
     */
2402
    CRYPTO_MUTEX *mutex;
2403
2404
    /* Datagram demultiplexer for incoming connections. */
2405
    DGRAM_DEMUX *demux;
2406
2407
    /* The network BIOs for sending and receiving datagrams. */
2408
    BIO *net_rbio;
2409
    BIO *net_wbio;
2410
2411
    /* Queue of incoming connections awaiting accept. */
2412
    STACK_OF(SSL) *incoming_connections;
2413
2414
    /*
2415
     * Use DGRAM_CONN_LOOKUP to find pending connections.
2416
     */
2417
    DGRAM_CONN_LOOKUP *pending_conns;
2418
2419
    /*
2420
     * Use DGRAM_CONN_LOOKUP to keep track of established connections.
2421
     */
2422
    DGRAM_CONN_LOOKUP *established_conns;
2423
2424
    /* Have we started listening yet? */
2425
    TSAN_QUALIFIER int listening;
2426
2427
    /*
2428
     * Set by ossl_dtls_tick() when the network BIO returns a hard error.
2429
     * Once set, ossl_dtls_accept_connection() returns NULL immediately.
2430
     */
2431
    int fatal;
2432
2433
    /* Require HelloVerifyRequest + cookie for DTLS 1.0/1.2 */
2434
    unsigned int require_hvr_cookie : 1;
2435
2436
    /* Require HelloRetryRequest + cookie for DTLS 1.3 */
2437
    unsigned int require_hrr_cookie : 1;
2438
2439
    /* Using the notifier architecture */
2440
    unsigned int have_notifier : 1;
2441
2442
    /* Notifier has been signalled */
2443
    int signalled_notifier;
2444
2445
    /*
2446
     * Time callback for customizable time source (primarily for testing).
2447
     * If NULL, ossl_time_now() is used.
2448
     */
2449
    OSSL_TIME (*now_cb)(void *arg);
2450
    void *now_cb_arg;
2451
2452
    /*
2453
     * Timeout for pending connections. Connections that haven't completed
2454
     * their handshake within this duration are considered stale and removed.
2455
     * Default: 30 seconds. Set to ossl_time_infinite() to disable.
2456
     */
2457
    OSSL_TIME pending_timeout;
2458
2459
    /*
2460
     * Maximum number of listener-owned connections allowed, counting both
2461
     * the pending table and the accept queue.
2462
     * When this limit is reached, new connection attempts are rejected.
2463
     *
2464
     * Default: DTLS_LISTENER_DEFAULT_MAX_PENDING_CONNS
2465
     * This limit cannot be disabled.
2466
     */
2467
    size_t max_pending_conns;
2468
2469
    /*
2470
     * Largest datagram the listener will receive, chosen by the application.
2471
     *
2472
     * Default: DTLS_LISTENER_DEFAULT_MAX_DGRAM_SIZE
2473
     */
2474
    size_t max_dgram_size;
2475
2476
    CRYPTO_CONDVAR *notifier_cv;
2477
2478
    /*
2479
     * Notifier for signaling events related to this listener.
2480
     */
2481
    RIO_NOTIFIER notifier;
2482
2483
    /*
2484
     * Count of threads currently blocked waiting in poll().
2485
     */
2486
    size_t cur_blocking_waiters;
2487
2488
    /*
2489
     * Blocking mode requested for this listener, as a DTLS_BLOCKING_MODE.
2490
     * INHERIT here means blocking, there being nothing further to inherit
2491
     * from.
2492
     */
2493
    unsigned int req_blocking_mode : 2;
2494
} DTLS_LISTENER;
2495
2496
#endif /* !OPENSSL_NO_DTLS && !OPENSSL_NO_SOCK */
2497
2498
/*
2499
 * From ECC-TLS draft, used in encoding the curve type in ECParameters
2500
 */
2501
#define EXPLICIT_PRIME_CURVE_TYPE 1
2502
#define EXPLICIT_CHAR2_CURVE_TYPE 2
2503
0
#define NAMED_CURVE_TYPE 3
2504
2505
#ifndef OPENSSL_NO_COMP_ALG
2506
struct ossl_comp_cert_st {
2507
    unsigned char *data;
2508
    size_t len;
2509
    size_t orig_len;
2510
    CRYPTO_REF_COUNT references;
2511
    int alg;
2512
};
2513
typedef struct ossl_comp_cert_st OSSL_COMP_CERT;
2514
2515
void OSSL_COMP_CERT_free(OSSL_COMP_CERT *c);
2516
int OSSL_COMP_CERT_up_ref(OSSL_COMP_CERT *c);
2517
#endif
2518
2519
struct cert_pkey_st {
2520
    X509 *x509;
2521
    EVP_PKEY *privatekey;
2522
    /* Chain for this certificate */
2523
    STACK_OF(X509) *chain;
2524
    /*-
2525
     * serverinfo data for this certificate.  The data is in TLS Extension
2526
     * wire format, specifically it's a series of records like:
2527
     *   uint16_t extension_type; // (RFC 5246, 7.4.1.4, Extension)
2528
     *   uint16_t length;
2529
     *   uint8_t data[length];
2530
     */
2531
    unsigned char *serverinfo;
2532
    size_t serverinfo_length;
2533
#ifndef OPENSSL_NO_COMP_ALG
2534
    /* Compressed certificate data - index 0 is unused */
2535
    OSSL_COMP_CERT *comp_cert[TLSEXT_comp_cert_limit];
2536
    int cert_comp_used;
2537
#endif
2538
};
2539
/* Retrieve Suite B flags */
2540
0
#define tls1_suiteb(s) (s->cert->cert_flags & SSL_CERT_FLAG_SUITEB_128_LOS)
2541
/* Uses to check strict mode: suite B modes are always strict */
2542
#define SSL_CERT_FLAGS_CHECK_TLS_STRICT \
2543
0
    (SSL_CERT_FLAG_SUITEB_128_LOS | SSL_CERT_FLAG_TLS_STRICT)
2544
2545
typedef enum {
2546
    ENDPOINT_CLIENT = 0,
2547
    ENDPOINT_SERVER,
2548
    ENDPOINT_BOTH
2549
} ENDPOINT;
2550
2551
typedef struct {
2552
    unsigned short ext_type;
2553
    ENDPOINT role;
2554
    /* The context which this extension applies to */
2555
    unsigned int context;
2556
    /*
2557
     * Per-connection flags relating to this extension type: not used if
2558
     * part of an SSL_CTX structure.
2559
     */
2560
    uint32_t ext_flags;
2561
    SSL_custom_ext_add_cb_ex add_cb;
2562
    SSL_custom_ext_free_cb_ex free_cb;
2563
    void *add_arg;
2564
    SSL_custom_ext_parse_cb_ex parse_cb;
2565
    void *parse_arg;
2566
} custom_ext_method;
2567
2568
/* ext_flags values */
2569
2570
/*
2571
 * Indicates an extension has been received. Used to check for unsolicited or
2572
 * duplicate extensions.
2573
 */
2574
0
#define SSL_EXT_FLAG_RECEIVED 0x1
2575
/*
2576
 * Indicates an extension has been sent: used to enable sending of
2577
 * corresponding ServerHello extension.
2578
 */
2579
0
#define SSL_EXT_FLAG_SENT 0x2
2580
/*
2581
 * Indicates an extension that was set on SSL object and needs to be
2582
 * preserved when switching SSL contexts.
2583
 */
2584
0
#define SSL_EXT_FLAG_CONN 0x4
2585
2586
typedef struct {
2587
    custom_ext_method *meths;
2588
    size_t meths_count;
2589
} custom_ext_methods;
2590
2591
typedef struct cert_st {
2592
    /* Current active set */
2593
    /*
2594
     * ALWAYS points to an element of the pkeys array
2595
     * Probably it would make more sense to store
2596
     * an index, not a pointer.
2597
     */
2598
    CERT_PKEY *key;
2599
2600
    EVP_PKEY *dh_tmp;
2601
    DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
2602
    int dh_tmp_auto;
2603
    /* Flags related to certificates */
2604
    uint32_t cert_flags;
2605
    CERT_PKEY *pkeys;
2606
    size_t ssl_pkey_num;
2607
    /* Custom certificate types sent in certificate request message. */
2608
    uint8_t *ctype;
2609
    size_t ctype_len;
2610
    /*
2611
     * supported signature algorithms. When set on a client this is sent in
2612
     * the client hello as the supported signature algorithms extension. For
2613
     * servers it represents the signature algorithms we are willing to use.
2614
     */
2615
    uint16_t *conf_sigalgs;
2616
    /* Size of above array */
2617
    size_t conf_sigalgslen;
2618
    /*
2619
     * Client authentication signature algorithms, if not set then uses
2620
     * conf_sigalgs. On servers these will be the signature algorithms sent
2621
     * to the client in a certificate request for TLS 1.2. On a client this
2622
     * represents the signature algorithms we are willing to use for client
2623
     * authentication.
2624
     */
2625
    uint16_t *client_sigalgs;
2626
    /* Size of above array */
2627
    size_t client_sigalgslen;
2628
    /*
2629
     * Certificate setup callback: if set is called whenever a certificate
2630
     * may be required (client or server). the callback can then examine any
2631
     * appropriate parameters and setup any certificates required. This
2632
     * allows advanced applications to select certificates on the fly: for
2633
     * example based on supported signature algorithms or curves.
2634
     */
2635
    int (*cert_cb)(SSL *ssl, void *arg);
2636
    void *cert_cb_arg;
2637
    /*
2638
     * Optional X509_STORE for chain building or certificate validation If
2639
     * NULL the parent SSL_CTX store is used instead.
2640
     */
2641
    X509_STORE *chain_store;
2642
    X509_STORE *verify_store;
2643
    /* Custom extensions */
2644
    custom_ext_methods custext;
2645
    /* Security callback */
2646
    int (*sec_cb)(const SSL *s, const SSL_CTX *ctx, int op, int bits, int nid,
2647
        void *other, void *ex);
2648
    /* Security level */
2649
    int sec_level;
2650
    void *sec_ex;
2651
#ifndef OPENSSL_NO_PSK
2652
    /* If not NULL psk identity hint to use for servers */
2653
    char *psk_identity_hint;
2654
#endif
2655
    CRYPTO_REF_COUNT references; /* >1 only if SSL_copy_session_id is used */
2656
} CERT;
2657
2658
/*
2659
 * This is for the TLSv1.0 differences in crypto/hash stuff.
2660
 */
2661
typedef struct ssl3_enc_method {
2662
    int (*setup_key_block)(SSL_CONNECTION *);
2663
    int (*generate_master_secret)(SSL_CONNECTION *, unsigned char *,
2664
        unsigned char *, size_t, size_t *);
2665
    int (*change_cipher_state)(SSL_CONNECTION *, int);
2666
    size_t (*final_finish_mac)(SSL_CONNECTION *, const char *, size_t,
2667
        unsigned char *);
2668
    const char *client_finished_label;
2669
    size_t client_finished_label_len;
2670
    const char *server_finished_label;
2671
    size_t server_finished_label_len;
2672
    int (*alert_value)(int);
2673
    int (*export_keying_material)(SSL_CONNECTION *, unsigned char *, size_t,
2674
        const char *, size_t,
2675
        const unsigned char *, size_t,
2676
        int use_context);
2677
    /* Various flags indicating protocol version requirements */
2678
    uint32_t enc_flags;
2679
    /* Set the handshake header */
2680
    int (*set_handshake_header)(SSL_CONNECTION *s, WPACKET *pkt, int type);
2681
    /* Close construction of the handshake message */
2682
    int (*close_construct_packet)(SSL_CONNECTION *s, WPACKET *pkt, int htype);
2683
    /* Write out handshake message */
2684
    int (*do_write)(SSL_CONNECTION *s);
2685
} SSL3_ENC_METHOD;
2686
2687
#define ssl_set_handshake_header(s, pkt, htype) \
2688
0
    SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->set_handshake_header((s), (pkt), (htype))
2689
#define ssl_close_construct_packet(s, pkt, htype) \
2690
0
    SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->close_construct_packet((s), (pkt), (htype))
2691
0
#define ssl_do_write(s) SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->do_write(s)
2692
2693
/* Values for enc_flags */
2694
2695
/* Uses signature algorithms extension */
2696
0
#define SSL_ENC_FLAG_SIGALGS 0x2
2697
/* Uses SHA256 default PRF */
2698
0
#define SSL_ENC_FLAG_SHA256_PRF 0x4
2699
/* Is DTLS */
2700
0
#define SSL_ENC_FLAG_DTLS 0x8
2701
/*
2702
 * Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2: may
2703
 * apply to others in future.
2704
 */
2705
0
#define SSL_ENC_FLAG_TLS1_2_CIPHERS 0x10
2706
2707
/*
2708
 * Dummy status type for the status_type extension. Indicates no status type
2709
 * set
2710
 */
2711
0
#define TLSEXT_STATUSTYPE_nothing -1
2712
2713
/* Known PSK key exchange modes */
2714
0
#define TLSEXT_KEX_MODE_KE 0x00
2715
0
#define TLSEXT_KEX_MODE_KE_DHE 0x01
2716
2717
/*
2718
 * Internal representations of key exchange modes
2719
 */
2720
0
#define TLSEXT_KEX_MODE_FLAG_NONE 0
2721
0
#define TLSEXT_KEX_MODE_FLAG_KE 1
2722
0
#define TLSEXT_KEX_MODE_FLAG_KE_DHE 2
2723
2724
0
#define SSL_USE_PSS(s) (s->s3.tmp.peer_sigalg != NULL && s->s3.tmp.peer_sigalg->sig == EVP_PKEY_RSA_PSS)
2725
2726
/* TLSv1.3 downgrade protection sentinel values */
2727
extern const unsigned char tls11downgrade[8];
2728
extern const unsigned char tls12downgrade[8];
2729
2730
extern const SSL3_ENC_METHOD ssl3_undef_enc_method;
2731
2732
__owur const SSL_METHOD *tlsv1_method(void);
2733
__owur const SSL_METHOD *tlsv1_server_method(void);
2734
__owur const SSL_METHOD *tlsv1_client_method(void);
2735
__owur const SSL_METHOD *tlsv1_1_method(void);
2736
__owur const SSL_METHOD *tlsv1_1_server_method(void);
2737
__owur const SSL_METHOD *tlsv1_1_client_method(void);
2738
__owur const SSL_METHOD *tlsv1_2_method(void);
2739
__owur const SSL_METHOD *tlsv1_2_server_method(void);
2740
__owur const SSL_METHOD *tlsv1_2_client_method(void);
2741
__owur const SSL_METHOD *tlsv1_3_method(void);
2742
__owur const SSL_METHOD *tlsv1_3_server_method(void);
2743
__owur const SSL_METHOD *tlsv1_3_client_method(void);
2744
__owur const SSL_METHOD *dtlsv1_method(void);
2745
__owur const SSL_METHOD *dtlsv1_server_method(void);
2746
__owur const SSL_METHOD *dtlsv1_client_method(void);
2747
__owur const SSL_METHOD *dtls_bad_ver_client_method(void);
2748
__owur const SSL_METHOD *dtlsv1_2_method(void);
2749
__owur const SSL_METHOD *dtlsv1_2_server_method(void);
2750
__owur const SSL_METHOD *dtlsv1_2_client_method(void);
2751
__owur const SSL_METHOD *dtlsv1_3_method(void);
2752
__owur const SSL_METHOD *dtlsv1_3_server_method(void);
2753
__owur const SSL_METHOD *dtlsv1_3_client_method(void);
2754
2755
extern const SSL3_ENC_METHOD TLSv1_enc_data;
2756
extern const SSL3_ENC_METHOD TLSv1_1_enc_data;
2757
extern const SSL3_ENC_METHOD TLSv1_2_enc_data;
2758
extern const SSL3_ENC_METHOD TLSv1_3_enc_data;
2759
extern const SSL3_ENC_METHOD DTLSv1_enc_data;
2760
extern const SSL3_ENC_METHOD DTLSv1_2_enc_data;
2761
extern const SSL3_ENC_METHOD DTLSv1_3_enc_data;
2762
2763
/*
2764
 * Flags for SSL methods
2765
 */
2766
#define SSL_METHOD_NO_FIPS (1U << 0)
2767
0
#define SSL_METHOD_NO_SUITEB (1U << 1)
2768
2769
#define IMPLEMENT_tls_meth_func(version, flags, mask, func_name, s_accept, \
2770
    s_connect, enc_data)                                                   \
2771
    const SSL_METHOD *func_name(void)                                      \
2772
0
    {                                                                      \
2773
0
        static const SSL_METHOD func_name##_data = {                       \
2774
0
            version,                                                       \
2775
0
            flags,                                                         \
2776
0
            mask,                                                          \
2777
0
            ossl_ssl_connection_new,                                       \
2778
0
            ossl_ssl_connection_free,                                      \
2779
0
            ossl_ssl_connection_reset,                                     \
2780
0
            tls1_new,                                                      \
2781
0
            tls1_clear,                                                    \
2782
0
            tls1_free,                                                     \
2783
0
            s_accept,                                                      \
2784
0
            s_connect,                                                     \
2785
0
            ssl3_read,                                                     \
2786
0
            ssl3_peek,                                                     \
2787
0
            ssl3_write,                                                    \
2788
0
            ssl3_shutdown,                                                 \
2789
0
            ssl3_renegotiate,                                              \
2790
0
            ssl3_renegotiate_check,                                        \
2791
0
            ssl3_read_bytes,                                               \
2792
0
            ssl3_write_bytes,                                              \
2793
0
            ssl3_dispatch_alert,                                           \
2794
0
            ssl3_ctrl,                                                     \
2795
0
            ssl3_ctx_ctrl,                                                 \
2796
0
            ssl3_get_cipher_by_char,                                       \
2797
0
            ssl3_put_cipher_by_char,                                       \
2798
0
            ssl3_pending,                                                  \
2799
0
            ssl3_num_ciphers,                                              \
2800
0
            ssl3_get_cipher,                                               \
2801
0
            tls1_default_timeout,                                          \
2802
0
            &enc_data,                                                     \
2803
0
            ssl_undefined_void_function,                                   \
2804
0
            ssl3_callback_ctrl,                                            \
2805
0
            ssl3_ctx_callback_ctrl,                                        \
2806
0
        };                                                                 \
2807
0
        return &func_name##_data;                                          \
2808
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
2809
2810
#define IMPLEMENT_dtls1_meth_func(version, flags, mask, func_name, s_accept, \
2811
    s_connect, enc_data)                                                     \
2812
    const SSL_METHOD *func_name(void)                                        \
2813
0
    {                                                                        \
2814
0
        static const SSL_METHOD func_name##_data = {                         \
2815
0
            version,                                                         \
2816
0
            flags,                                                           \
2817
0
            mask,                                                            \
2818
0
            ossl_ssl_connection_new,                                         \
2819
0
            ossl_ssl_connection_free,                                        \
2820
0
            ossl_ssl_connection_reset,                                       \
2821
0
            dtls1_new,                                                       \
2822
0
            dtls1_clear,                                                     \
2823
0
            dtls1_free,                                                      \
2824
0
            s_accept,                                                        \
2825
0
            s_connect,                                                       \
2826
0
            ssl3_read,                                                       \
2827
0
            ssl3_peek,                                                       \
2828
0
            ssl3_write,                                                      \
2829
0
            dtls1_shutdown,                                                  \
2830
0
            ssl3_renegotiate,                                                \
2831
0
            ssl3_renegotiate_check,                                          \
2832
0
            dtls1_read_bytes,                                                \
2833
0
            dtls1_write_app_data_bytes,                                      \
2834
0
            dtls1_dispatch_alert,                                            \
2835
0
            dtls1_ctrl,                                                      \
2836
0
            ssl3_ctx_ctrl,                                                   \
2837
0
            ssl3_get_cipher_by_char,                                         \
2838
0
            ssl3_put_cipher_by_char,                                         \
2839
0
            ssl3_pending,                                                    \
2840
0
            ssl3_num_ciphers,                                                \
2841
0
            ssl3_get_cipher,                                                 \
2842
0
            dtls1_default_timeout,                                           \
2843
0
            &enc_data,                                                       \
2844
0
            ssl_undefined_void_function,                                     \
2845
0
            ssl3_callback_ctrl,                                              \
2846
0
            ssl3_ctx_callback_ctrl,                                          \
2847
0
        };                                                                   \
2848
0
        return &func_name##_data;                                            \
2849
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
2850
2851
struct openssl_ssl_test_functions {
2852
    int (*p_ssl_init_wbio_buffer)(SSL_CONNECTION *s);
2853
};
2854
2855
const char *ssl_protocol_to_string(int version);
2856
2857
static ossl_inline int tls12_rpk_and_privkey(const SSL_CONNECTION *sc, int idx)
2858
0
{
2859
    /*
2860
     * This is to check for special cases when using RPK with just
2861
     * a private key, and NO CERTIFICATE
2862
     */
2863
0
    return ((sc->server && sc->ext.server_cert_type == TLSEXT_cert_type_rpk)
2864
0
               || (!sc->server && sc->ext.client_cert_type == TLSEXT_cert_type_rpk))
2865
0
        && sc->cert->pkeys[idx].privatekey != NULL
2866
0
        && sc->cert->pkeys[idx].x509 == NULL;
2867
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
2868
2869
static ossl_inline int ssl_has_cert_type(const SSL_CONNECTION *sc, unsigned char ct)
2870
0
{
2871
0
    unsigned char *ptr;
2872
0
    size_t len;
2873
2874
0
    if (sc->server) {
2875
0
        ptr = sc->server_cert_type;
2876
0
        len = sc->server_cert_type_len;
2877
0
    } else {
2878
0
        ptr = sc->client_cert_type;
2879
0
        len = sc->client_cert_type_len;
2880
0
    }
2881
2882
0
    if (ptr == NULL)
2883
0
        return 0;
2884
2885
0
    return memchr(ptr, ct, len) != NULL;
2886
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
2887
2888
/* Returns true if certificate and private key for 'idx' are present */
2889
static ossl_inline int ssl_has_cert(const SSL_CONNECTION *s, int idx)
2890
0
{
2891
0
    if (idx < 0 || idx >= (int)s->ssl_pkey_num)
2892
0
        return 0;
2893
2894
    /* If RPK is enabled for this SSL... only require private key */
2895
0
    if (ssl_has_cert_type(s, TLSEXT_cert_type_rpk))
2896
0
        return s->cert->pkeys[idx].privatekey != NULL;
2897
2898
0
    return s->cert->pkeys[idx].x509 != NULL
2899
0
        && s->cert->pkeys[idx].privatekey != NULL;
2900
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
2901
2902
static ossl_inline void tls1_get_peer_groups(SSL_CONNECTION *s,
2903
    const uint16_t **pgroups,
2904
    size_t *pgroupslen)
2905
0
{
2906
0
    *pgroups = s->ext.peer_supportedgroups;
2907
0
    *pgroupslen = s->ext.peer_supportedgroups_len;
2908
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
2909
2910
#ifndef OPENSSL_UNIT_TEST
2911
2912
__owur int ossl_ssl_init(SSL *ssl, SSL_CTX *ctx, const SSL_METHOD *method,
2913
    int type);
2914
__owur SSL *ossl_ssl_connection_new_int(SSL_CTX *ctx, SSL *user_ssl,
2915
    const SSL_METHOD *method);
2916
__owur SSL *ossl_ssl_connection_new(SSL_CTX *ctx);
2917
void ossl_ssl_connection_free(SSL *ssl);
2918
__owur int ossl_ssl_connection_reset(SSL *ssl);
2919
2920
__owur int ssl_read_internal(SSL *s, void *buf, size_t num, size_t *readbytes);
2921
__owur int ssl_write_internal(SSL *s, const void *buf, size_t num,
2922
    uint64_t flags, size_t *written);
2923
int ssl_clear_bad_session(SSL_CONNECTION *s);
2924
__owur CERT *ssl_cert_new(size_t ssl_pkey_num);
2925
__owur CERT *ssl_cert_dup(CERT *cert);
2926
void ssl_cert_clear_certs(CERT *c);
2927
void ssl_cert_free(CERT *c);
2928
__owur int ssl_generate_session_id(SSL_CONNECTION *s, SSL_SESSION *ss);
2929
__owur int ssl_get_new_session(SSL_CONNECTION *s, int session);
2930
__owur SSL_SESSION *lookup_sess_in_cache(SSL_CONNECTION *s,
2931
    const unsigned char *sess_id,
2932
    size_t sess_id_len);
2933
__owur int ssl_get_prev_session(SSL_CONNECTION *s, CLIENTHELLO_MSG *hello);
2934
__owur SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket);
2935
void ossl_session_set0_peer(SSL_SESSION *sess, STACK_OF(X509) *peer_chain,
2936
    EVP_PKEY *peer_rpk, long verify_result);
2937
__owur int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
2938
DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
2939
__owur int ssl_cipher_ptr_id_cmp(const SSL_CIPHER *const *ap,
2940
    const SSL_CIPHER *const *bp);
2941
__owur STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,
2942
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites,
2943
    STACK_OF(SSL_CIPHER) **cipher_list,
2944
    STACK_OF(SSL_CIPHER) **cipher_list_by_id,
2945
    const char *rule_str,
2946
    CERT *c);
2947
__owur int ssl_cache_cipherlist(SSL_CONNECTION *s, PACKET *cipher_suites);
2948
__owur int ossl_bytes_to_cipher_list(SSL_CONNECTION *s, PACKET *cipher_suites,
2949
    STACK_OF(SSL_CIPHER) **skp,
2950
    STACK_OF(SSL_CIPHER) **scsvs,
2951
    int fatal);
2952
void ssl_update_cache(SSL_CONNECTION *s, int mode);
2953
__owur int ssl_cipher_get_evp_cipher(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2954
    const EVP_CIPHER **enc);
2955
__owur int ssl_cipher_get_evp_cipher_sn(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2956
    const EVP_CIPHER **enc);
2957
__owur int ssl_cipher_get_evp_md_mac(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2958
    const EVP_MD **md,
2959
    int *mac_pkey_type, size_t *mac_secret_size);
2960
__owur int ssl_cipher_get_evp(SSL_CTX *ctx, const SSL_SESSION *s,
2961
    const EVP_CIPHER **snenc,
2962
    const EVP_CIPHER **enc,
2963
    const EVP_MD **md,
2964
    int *mac_pkey_type, size_t *mac_secret_size,
2965
    SSL_COMP **comp, int use_etm);
2966
__owur int ssl_cipher_get_overhead(const SSL_CIPHER *c, int version,
2967
    size_t *mac_overhead, size_t *int_overhead,
2968
    size_t *blocksize, size_t *ext_overhead);
2969
__owur int ssl_cert_is_disabled(SSL_CTX *ctx, size_t idx);
2970
__owur const SSL_CIPHER *ssl_get_cipher_by_char(SSL_CONNECTION *ssl,
2971
    const unsigned char *ptr,
2972
    int all);
2973
__owur int ssl_cert_set0_chain(SSL_CONNECTION *s, SSL_CTX *ctx,
2974
    STACK_OF(X509) *chain);
2975
__owur int ssl_cert_set1_chain(SSL_CONNECTION *s, SSL_CTX *ctx,
2976
    STACK_OF(X509) *chain);
2977
__owur int ssl_cert_add0_chain_cert(SSL_CONNECTION *s, SSL_CTX *ctx, X509 *x);
2978
__owur int ssl_cert_add1_chain_cert(SSL_CONNECTION *s, SSL_CTX *ctx, X509 *x);
2979
__owur int ssl_cert_select_current(CERT *c, X509 *x);
2980
__owur int ssl_cert_set_current(CERT *c, long arg);
2981
void ssl_cert_set_cert_cb(CERT *c, int (*cb)(SSL *ssl, void *arg), void *arg);
2982
2983
__owur int ssl_verify_cert_chain(SSL_CONNECTION *s, STACK_OF(X509) *sk);
2984
__owur int ssl_verify_rpk(SSL_CONNECTION *s, EVP_PKEY *rpk);
2985
__owur int ssl_build_cert_chain(SSL_CONNECTION *s, SSL_CTX *ctx, int flags);
2986
__owur int ssl_cert_set_cert_store(CERT *c, X509_STORE *store, int chain,
2987
    int ref);
2988
__owur int ssl_cert_get_cert_store(CERT *c, X509_STORE **pstore, int chain);
2989
2990
__owur int ssl_security(const SSL_CONNECTION *s, int op, int bits, int nid,
2991
    void *other);
2992
__owur int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid,
2993
    void *other);
2994
int ssl_get_security_level_bits(const SSL *s, const SSL_CTX *ctx, int *levelp);
2995
2996
__owur int ssl_cert_lookup_by_nid(int nid, size_t *pidx, SSL_CTX *ctx);
2997
__owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_pkey(const EVP_PKEY *pk,
2998
    size_t *pidx,
2999
    SSL_CTX *ctx);
3000
__owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_idx(size_t idx, SSL_CTX *ctx);
3001
3002
int ssl_undefined_function(SSL *s);
3003
__owur int ssl_undefined_void_function(void);
3004
__owur int ssl_get_server_cert_serverinfo(SSL_CONNECTION *s,
3005
    const unsigned char **serverinfo,
3006
    size_t *serverinfo_length);
3007
void ssl_set_masks(SSL_CONNECTION *s);
3008
__owur STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL_CONNECTION *sc);
3009
__owur int ssl_x509err2alert(int type);
3010
void ssl_sort_cipher_list(void);
3011
int ssl_load_ciphers(SSL_CTX *ctx);
3012
int ssl_cipher_list_to_bytes(SSL_CONNECTION *s, STACK_OF(SSL_CIPHER) *sk,
3013
    WPACKET *pkt);
3014
uint16_t ossl_grease_value(SSL_CONNECTION *s, int index);
3015
static ossl_inline int ossl_is_grease_value(uint16_t val)
3016
0
{
3017
0
    return (val & 0x0f0f) == 0x0a0a && (val >> 8) == (val & 0xff);
3018
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
3019
__owur int ssl_setup_sigalgs(SSL_CTX *ctx);
3020
int ssl_load_groups(SSL_CTX *ctx);
3021
int ssl_load_sigalgs(SSL_CTX *ctx);
3022
__owur int ssl_fill_hello_random(SSL_CONNECTION *s, int server,
3023
    unsigned char *field, size_t len,
3024
    DOWNGRADE dgrd);
3025
__owur int ssl_generate_master_secret(SSL_CONNECTION *s, unsigned char *pms,
3026
    size_t pmslen, int free_pms);
3027
__owur EVP_PKEY *ssl_generate_pkey(SSL_CONNECTION *s, EVP_PKEY *pm);
3028
__owur int ssl_gensecret(SSL_CONNECTION *s, unsigned char *pms, size_t pmslen);
3029
__owur int ssl_derive(SSL_CONNECTION *s, EVP_PKEY *privkey, EVP_PKEY *pubkey,
3030
    int genmaster);
3031
__owur int ssl_decapsulate(SSL_CONNECTION *s, EVP_PKEY *privkey,
3032
    const unsigned char *ct, size_t ctlen,
3033
    int gensecret);
3034
__owur int ssl_encapsulate(SSL_CONNECTION *s, EVP_PKEY *pubkey,
3035
    unsigned char **ctp, size_t *ctlenp,
3036
    int gensecret);
3037
__owur EVP_PKEY *ssl_dh_to_pkey(DH *dh);
3038
__owur int ssl_set_tmp_ecdh_groups(uint16_t **pext, size_t *pextlen,
3039
    uint16_t **ksext, size_t *ksextlen,
3040
    size_t **tplext, size_t *tplextlen,
3041
    void *key);
3042
__owur unsigned int ssl_get_max_send_fragment(const SSL_CONNECTION *sc);
3043
__owur unsigned int ssl_get_split_send_fragment(const SSL_CONNECTION *sc);
3044
3045
__owur const SSL_CIPHER *ssl3_get_cipher_by_id(uint32_t id);
3046
__owur const SSL_CIPHER *ssl3_get_cipher_by_std_name(const char *stdname);
3047
__owur const SSL_CIPHER *ssl3_get_tls13_cipher_by_std_name(const char *stdname);
3048
__owur const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
3049
__owur int ssl3_put_cipher_by_char(const SSL_CIPHER *c, WPACKET *pkt,
3050
    size_t *len);
3051
int ssl3_init_finished_mac(SSL_CONNECTION *s);
3052
void ssl3_cleanup_key_block(SSL_CONNECTION *s);
3053
__owur int ssl3_do_write(SSL_CONNECTION *s, uint8_t type);
3054
int ssl3_send_alert(SSL_CONNECTION *s, int level, int desc);
3055
__owur int ssl3_get_req_cert_type(SSL_CONNECTION *s, WPACKET *pkt);
3056
__owur int ssl3_num_ciphers(void);
3057
__owur const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
3058
int ssl3_renegotiate(SSL *ssl);
3059
int ssl3_renegotiate_check(SSL *ssl, int initok);
3060
__owur int ssl3_dispatch_alert(SSL *s);
3061
__owur int ssl3_finish_mac(SSL_CONNECTION *s, const unsigned char *buf,
3062
    size_t len);
3063
void ssl3_free_digest_list(SSL_CONNECTION *s);
3064
__owur unsigned long ssl3_output_cert_chain(SSL_CONNECTION *s, WPACKET *pkt,
3065
    CERT_PKEY *cpk, int for_comp);
3066
__owur const SSL_CIPHER *ssl3_choose_cipher(SSL_CONNECTION *s,
3067
    STACK_OF(SSL_CIPHER) *clnt,
3068
    STACK_OF(SSL_CIPHER) *srvr);
3069
__owur int ssl3_digest_cached_records(SSL_CONNECTION *s, int keep);
3070
__owur int ssl3_new(SSL *s);
3071
void ssl3_free(SSL *s);
3072
__owur int ssl3_read(SSL *s, void *buf, size_t len, size_t *readbytes);
3073
__owur int ssl3_peek(SSL *s, void *buf, size_t len, size_t *readbytes);
3074
__owur int ssl3_write(SSL *s, const void *buf, size_t len, size_t *written);
3075
__owur int ssl3_shutdown(SSL *s);
3076
int ssl3_clear(SSL *s);
3077
__owur long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
3078
__owur long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
3079
__owur long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
3080
__owur long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
3081
3082
__owur int ssl3_do_change_cipher_spec(SSL_CONNECTION *s);
3083
3084
__owur int ssl3_set_handshake_header(SSL_CONNECTION *s, WPACKET *pkt,
3085
    int htype);
3086
__owur int tls_close_construct_packet(SSL_CONNECTION *s, WPACKET *pkt, int htype);
3087
__owur int tls_setup_handshake(SSL_CONNECTION *s);
3088
__owur int dtls1_set_handshake_header(SSL_CONNECTION *s, WPACKET *pkt, int htype);
3089
__owur int dtls1_close_construct_packet(SSL_CONNECTION *s, WPACKET *pkt, int htype);
3090
__owur int ssl3_handshake_write(SSL_CONNECTION *s);
3091
3092
__owur int ssl_allow_compression(SSL_CONNECTION *s);
3093
3094
__owur int ssl_version_cmp(const SSL_CONNECTION *s, int versiona, int versionb);
3095
__owur int ssl_version_supported(const SSL_CONNECTION *s, int version,
3096
    const SSL_METHOD **meth);
3097
3098
__owur int ssl_set_client_hello_version(SSL_CONNECTION *s);
3099
__owur int ssl_check_version_downgrade(SSL_CONNECTION *s);
3100
__owur int ssl_set_version_bound(int method_version, int version, int *bound);
3101
__owur int ssl_choose_server_version(SSL_CONNECTION *s, CLIENTHELLO_MSG *hello,
3102
    DOWNGRADE *dgrd);
3103
__owur int ssl_choose_client_version(SSL_CONNECTION *s, int version,
3104
    RAW_EXTENSION *extensions);
3105
__owur int ssl_get_min_max_version(const SSL_CONNECTION *s, int *min_version,
3106
    int *max_version, int *real_max);
3107
3108
__owur OSSL_TIME tls1_default_timeout(void);
3109
__owur int dtls1_do_write(SSL_CONNECTION *s, uint8_t recordtype);
3110
3111
int dtls1_write_app_data_bytes(SSL *s, uint8_t type, const void *buf_,
3112
    size_t len, size_t *written);
3113
int dtls13_transcript_hash_update(EVP_MD_CTX *mdctx,
3114
    const unsigned char *buf, size_t len);
3115
3116
__owur int dtls1_read_failed(SSL_CONNECTION *s, int code);
3117
__owur int dtls1_buffer_sent_message(SSL_CONNECTION *s, int record_type);
3118
__owur int dtls1_retransmit_message(SSL_CONNECTION *s, dtls_sent_msg *sent_msg);
3119
void dtls1_get_queue_priority(unsigned char *prio64be, unsigned short seq,
3120
    int record_type);
3121
int dtls1_retransmit_sent_messages(SSL_CONNECTION *s);
3122
void dtls1_clear_received_buffer(SSL_CONNECTION *s);
3123
void dtls1_clear_sent_buffer(SSL_CONNECTION *s, int keep_unacked_msgs);
3124
void dtls1_acknowledge_sent_buffer(SSL_CONNECTION *s, uint64_t before_epoch);
3125
__owur OSSL_TIME dtls1_default_timeout(void);
3126
__owur int dtls1_get_timeout(const SSL_CONNECTION *s, OSSL_TIME *timeleft);
3127
__owur int dtls1_check_timeout_num(SSL_CONNECTION *s);
3128
__owur int dtls1_handle_timeout(SSL_CONNECTION *s);
3129
void dtls1_start_timer(SSL_CONNECTION *s);
3130
void dtls1_stop_timer(SSL_CONNECTION *s);
3131
__owur int dtls1_is_timer_expired(SSL_CONNECTION *s);
3132
void dtls1_clear_current_wrl_from_sent_buffer(SSL_CONNECTION *s);
3133
__owur int dtls_raw_hello_verify_request(WPACKET *pkt, unsigned char *cookie,
3134
    size_t cookie_len);
3135
__owur size_t dtls1_min_mtu(SSL_CONNECTION *s);
3136
void dtls1_hm_fragment_free(hm_fragment *frag);
3137
void dtls1_sent_msg_free(dtls_sent_msg *msg);
3138
__owur int dtls1_query_mtu(SSL_CONNECTION *s);
3139
3140
#if !defined(OPENSSL_NO_DTLS) && !defined(OPENSSL_NO_SOCK)
3141
SSL *ossl_dtls_new_listener(SSL_CTX *ctx, uint64_t flags);
3142
void ossl_dtls_listener_free(SSL *ssl);
3143
SSL *ossl_dtls_get0_listener(const SSL *ssl);
3144
int ossl_dtls_listen(SSL *ssl);
3145
SSL *ossl_dtls_accept_connection(SSL *ssl, uint64_t flags);
3146
void ossl_dtls_listener_set0_net_rbio(SSL *s, BIO *bio);
3147
void ossl_dtls_listener_set0_net_wbio(SSL *s, BIO *bio);
3148
BIO *ossl_dtls_listener_get_net_rbio(const SSL *s);
3149
BIO *ossl_dtls_listener_get_net_wbio(const SSL *s);
3150
3151
/* Established connections API - these handle their own locking */
3152
SSL *ossl_dtls_listener_find_established_conn(DTLS_LISTENER *dl,
3153
    const DGRAM_URXE *urxe);
3154
void ossl_dtls_listener_unregister_established_conn(SSL *s,
3155
    const BIO_ADDR *peer_addr);
3156
void ossl_dtls_listener_clear_established_conns(DTLS_LISTENER *dl);
3157
3158
size_t ossl_dtls_get_accept_connection_queue_len(SSL *ssl);
3159
int ossl_dtls_listener_set_override_now_cb(SSL *s,
3160
    OSSL_TIME (*now_cb)(void *arg),
3161
    void *now_cb_arg);
3162
3163
int ossl_dtls_get_value_uint(SSL *s, uint32_t class_, uint32_t id, uint64_t *value);
3164
int ossl_dtls_set_value_uint(SSL *s, uint32_t class_, uint32_t id, uint64_t value);
3165
3166
/* DTLS poll event functions - used by SSL_poll() */
3167
int ossl_dtls_listener_poll_events(SSL *s, uint64_t events, int do_tick,
3168
    uint64_t *revents);
3169
int ossl_dtls_conn_poll_events(SSL *s, uint64_t events, int do_tick,
3170
    uint64_t *revents);
3171
void ossl_dtls_listener_enter_blocking_section(SSL *s);
3172
void ossl_dtls_listener_leave_blocking_section(SSL *s);
3173
int ossl_dtls_block_until_ready(SSL *ssl, uint64_t events, OSSL_TIME deadline,
3174
    int bound_by_event_timeout);
3175
int ossl_dtls_blocking(const SSL *s);
3176
int ossl_dtls_set_blocking_mode(SSL *s, int blocking);
3177
int ossl_dtls_get_blocking_mode(const SSL *s);
3178
int ossl_dtls_conn_wait_for_datagram(SSL *s);
3179
int ossl_dtls_conn_wait_for_write(SSL *s);
3180
int ossl_dtls_tick(DTLS_LISTENER *dl);
3181
3182
/* DTLS Listener internal cookie callbacks */
3183
int ossl_dtls_listener_gen_cookie_cb(SSL *ssl, unsigned char *cookie,
3184
    unsigned int *cookie_len);
3185
int ossl_dtls_listener_verify_cookie_cb(SSL *ssl, const unsigned char *cookie,
3186
    unsigned int cookie_len);
3187
int ossl_dtls_listener_gen_stateless_cookie_cb(SSL *ssl, unsigned char *cookie,
3188
    size_t *cookie_len);
3189
int ossl_dtls_listener_verify_stateless_cookie_cb(SSL *ssl,
3190
    const unsigned char *cookie,
3191
    size_t cookie_len);
3192
int dtls_listener_cookie_hmac(SSL *ssl, uint64_t timestamp,
3193
    unsigned char *hmac_out);
3194
#endif /* !OPENSSL_NO_DTLS && !OPENSSL_NO_SOCK */
3195
3196
__owur int tls1_new(SSL *s);
3197
void tls1_free(SSL *s);
3198
int tls1_clear(SSL *s);
3199
3200
__owur int dtls1_new(SSL *s);
3201
void dtls1_free(SSL *s);
3202
int dtls1_clear(SSL *s);
3203
long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
3204
__owur int dtls1_shutdown(SSL *s);
3205
3206
__owur int dtls1_dispatch_alert(SSL *s);
3207
3208
__owur int ssl_init_wbio_buffer(SSL_CONNECTION *s);
3209
int ssl_free_wbio_buffer(SSL_CONNECTION *s);
3210
3211
__owur int tls1_change_cipher_state(SSL_CONNECTION *s, int which);
3212
__owur int tls1_setup_key_block(SSL_CONNECTION *s);
3213
__owur size_t tls1_final_finish_mac(SSL_CONNECTION *s, const char *str,
3214
    size_t slen, unsigned char *p);
3215
__owur int tls1_generate_master_secret(SSL_CONNECTION *s, unsigned char *out,
3216
    unsigned char *p, size_t len,
3217
    size_t *secret_size);
3218
__owur int tls13_setup_key_block(SSL_CONNECTION *s);
3219
__owur size_t tls13_final_finish_mac(SSL_CONNECTION *s, const char *str, size_t slen,
3220
    unsigned char *p);
3221
__owur int tls13_store_handshake_traffic_hash(SSL_CONNECTION *s);
3222
__owur int tls13_store_server_finished_hash(SSL_CONNECTION *s);
3223
__owur int tls13_change_cipher_state(SSL_CONNECTION *s, int which);
3224
__owur int tls13_update_key(SSL_CONNECTION *s, int send);
3225
__owur int tls13_hkdf_expand(SSL_CONNECTION *s,
3226
    const EVP_MD *md,
3227
    const unsigned char *secret,
3228
    const unsigned char *label, size_t labellen,
3229
    const unsigned char *data, size_t datalen,
3230
    unsigned char *out, size_t outlen, int fatal);
3231
__owur int tls13_hkdf_expand_ex(OSSL_LIB_CTX *libctx, const char *propq,
3232
    const EVP_MD *md,
3233
    const unsigned char *secret,
3234
    const unsigned char *label, size_t labellen,
3235
    const unsigned char *data, size_t datalen,
3236
    unsigned char *out, size_t outlen,
3237
    int raise_error);
3238
__owur int tls13_derive_key(SSL_CONNECTION *s, const EVP_MD *md,
3239
    const unsigned char *secret, unsigned char *key,
3240
    size_t keylen);
3241
__owur int tls13_derive_iv(SSL_CONNECTION *s, const EVP_MD *md,
3242
    const unsigned char *secret, unsigned char *iv,
3243
    size_t ivlen);
3244
__owur int tls13_derive_finishedkey(SSL_CONNECTION *s, const EVP_MD *md,
3245
    const unsigned char *secret,
3246
    unsigned char *fin, size_t finlen);
3247
int tls13_generate_secret(SSL_CONNECTION *s, const EVP_MD *md,
3248
    const unsigned char *prevsecret,
3249
    const unsigned char *insecret,
3250
    size_t insecretlen,
3251
    unsigned char *outsecret);
3252
__owur int tls13_generate_handshake_secret(SSL_CONNECTION *s,
3253
    const unsigned char *insecret,
3254
    size_t insecretlen);
3255
__owur int tls13_generate_master_secret(SSL_CONNECTION *s, unsigned char *out,
3256
    unsigned char *prev, size_t prevlen,
3257
    size_t *secret_size);
3258
__owur int tls1_export_keying_material(SSL_CONNECTION *s,
3259
    unsigned char *out, size_t olen,
3260
    const char *label, size_t llen,
3261
    const unsigned char *p, size_t plen,
3262
    int use_context);
3263
__owur int tls13_export_keying_material(SSL_CONNECTION *s,
3264
    unsigned char *out, size_t olen,
3265
    const char *label, size_t llen,
3266
    const unsigned char *context,
3267
    size_t contextlen, int use_context);
3268
__owur int tls13_export_keying_material_early(SSL_CONNECTION *s,
3269
    unsigned char *out, size_t olen,
3270
    const char *label, size_t llen,
3271
    const unsigned char *context,
3272
    size_t contextlen);
3273
__owur int tls1_alert_code(int code);
3274
__owur int tls13_alert_code(int code);
3275
3276
__owur int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL_CONNECTION *s);
3277
3278
SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
3279
3280
0
#define TLS1_GROUPS_RETURN_NUMBER -1
3281
0
#define TLS1_GROUPS_RETURN_TMP_ID -2
3282
0
#define TLS1_GROUPS_FFDHE_GROUPS 0
3283
0
#define TLS1_GROUPS_NON_FFDHE_GROUPS 1
3284
0
#define TLS1_GROUPS_ALL_GROUPS 2
3285
3286
__owur const TLS_GROUP_INFO *tls1_group_id_lookup(SSL_CTX *ctx, uint16_t curve_id);
3287
__owur const char *tls1_group_id2name(SSL_CTX *ctx, uint16_t group_id);
3288
__owur int tls1_group_id2nid(uint16_t group_id, int include_unknown);
3289
__owur uint16_t tls1_nid2group_id(int nid);
3290
__owur int tls1_check_group_id(SSL_CONNECTION *s, uint16_t group_id,
3291
    int check_own_curves);
3292
__owur int tls1_get0_implemented_groups(int min_proto_version,
3293
    int max_proto_version,
3294
    TLS_GROUP_INFO *grps,
3295
    size_t num, long all,
3296
    STACK_OF(OPENSSL_CSTRING) *out);
3297
__owur uint16_t tls1_shared_group(SSL_CONNECTION *s, int nmatch, int groups);
3298
__owur int tls1_set_groups(uint16_t **grpext, size_t *grpextlen,
3299
    uint16_t **ksext, size_t *ksextlen,
3300
    size_t **tplext, size_t *tplextlen,
3301
    int *curves, size_t ncurves);
3302
__owur int tls1_set_groups_list(SSL_CTX *ctx,
3303
    uint16_t **grpext, size_t *grpextlen,
3304
    uint16_t **ksext, size_t *ksextlen,
3305
    size_t **tplext, size_t *tplextlen,
3306
    const char *str);
3307
__owur EVP_PKEY *ssl_generate_pkey_group(SSL_CONNECTION *s, uint16_t id);
3308
__owur int tls_valid_group(SSL_CONNECTION *s, uint16_t group_id, int minversion,
3309
    int maxversion, int *okfortls13, const TLS_GROUP_INFO **giptr);
3310
__owur EVP_PKEY *ssl_generate_param_group(SSL_CONNECTION *s, uint16_t id);
3311
void tls1_get_formatlist(SSL_CONNECTION *s, const unsigned char **pformats,
3312
    size_t *num_formats);
3313
__owur int tls1_check_ffdhe_tmp_key(SSL_CONNECTION *s, unsigned long id);
3314
__owur int tls1_check_ec_tmp_key(SSL_CONNECTION *s, unsigned long id);
3315
3316
__owur int tls_group_allowed(SSL_CONNECTION *s, uint16_t curve, int op);
3317
void tls1_get_supported_groups(SSL_CONNECTION *s, const uint16_t **pgroups,
3318
    size_t *pgroupslen);
3319
void tls1_get_requested_keyshare_groups(SSL_CONNECTION *s, const uint16_t **pgroups,
3320
    size_t *pgroupslen);
3321
void tls1_get_group_tuples(SSL_CONNECTION *s, const size_t **ptuples,
3322
    size_t *ptupleslen);
3323
3324
__owur int tls1_set_server_sigalgs(SSL_CONNECTION *s);
3325
3326
__owur SSL_TICKET_STATUS tls_get_ticket_from_client(SSL_CONNECTION *s,
3327
    CLIENTHELLO_MSG *hello,
3328
    SSL_SESSION **ret);
3329
__owur SSL_TICKET_STATUS tls_decrypt_ticket(SSL_CONNECTION *s,
3330
    const unsigned char *etick,
3331
    size_t eticklen,
3332
    const unsigned char *sess_id,
3333
    size_t sesslen, SSL_SESSION **psess);
3334
3335
__owur int tls_use_ticket(SSL_CONNECTION *s);
3336
3337
void ssl_set_sig_mask(uint32_t *pmask_a, SSL_CONNECTION *s, int op);
3338
3339
__owur int tls1_set_sigalgs_list(SSL_CTX *ctx, CERT *c, const char *str, int client);
3340
__owur int tls1_set_raw_sigalgs(CERT *c, const uint16_t *psigs, size_t salglen,
3341
    int client);
3342
__owur int tls1_set_sigalgs(CERT *c, const int *salg, size_t salglen,
3343
    int client);
3344
int tls1_check_chain(SSL_CONNECTION *s, X509 *x, EVP_PKEY *pk,
3345
    STACK_OF(X509) *chain, int idx);
3346
void tls1_set_cert_validity(SSL_CONNECTION *s);
3347
3348
#ifndef OPENSSL_NO_CT
3349
__owur int ssl_validate_ct(SSL_CONNECTION *s);
3350
#endif
3351
3352
__owur EVP_PKEY *ssl_get_auto_dh(SSL_CONNECTION *s);
3353
3354
__owur int ssl_security_cert(SSL_CONNECTION *s, SSL_CTX *ctx, X509 *x, int is_ee);
3355
__owur int ssl_security_cert_chain(SSL_CONNECTION *s, STACK_OF(X509) *sk,
3356
    X509 *ex);
3357
3358
int tls_choose_sigalg(SSL_CONNECTION *s, int fatalerrs);
3359
3360
__owur long ssl_get_algorithm2(SSL_CONNECTION *s);
3361
__owur int tls12_copy_sigalgs(SSL_CONNECTION *s, WPACKET *pkt,
3362
    const uint16_t *psig, size_t psiglen);
3363
__owur int tls1_save_u16(PACKET *pkt, uint16_t **pdest, size_t *pdestlen, size_t maxnum);
3364
__owur int tls1_save_sigalgs(SSL_CONNECTION *s, PACKET *pkt, int cert);
3365
__owur int tls1_process_sigalgs(SSL_CONNECTION *s);
3366
__owur int tls1_set_peer_legacy_sigalg(SSL_CONNECTION *s, const EVP_PKEY *pkey);
3367
__owur int tls1_lookup_md(SSL_CTX *ctx, const SIGALG_LOOKUP *lu,
3368
    const EVP_MD **pmd);
3369
__owur size_t tls12_get_psigalgs(SSL_CONNECTION *s, int sent,
3370
    const uint16_t **psigs);
3371
__owur int tls_check_sigalg_curve(const SSL_CONNECTION *s, int curve);
3372
__owur int tls12_check_peer_sigalg(SSL_CONNECTION *s, uint16_t, EVP_PKEY *pkey);
3373
__owur int ssl_set_client_disabled(SSL_CONNECTION *s);
3374
__owur int ssl_cipher_disabled(const SSL_CONNECTION *s, const SSL_CIPHER *c,
3375
    int op);
3376
3377
__owur int ssl_handshake_hash(SSL_CONNECTION *s,
3378
    unsigned char *out, size_t outlen,
3379
    size_t *hashlen);
3380
__owur const EVP_MD *ssl_md(SSL_CTX *ctx, int idx);
3381
__owur int ssl_cipher_get_handshake_digest_nid(const SSL_CIPHER *c);
3382
int ssl_get_md_idx(int md_nid);
3383
__owur const EVP_MD *ssl_handshake_md(SSL_CONNECTION *s);
3384
__owur const EVP_MD *ssl_prf_md(SSL_CONNECTION *s);
3385
3386
__owur int ossl_adjust_domain_flags(uint64_t domain_flags,
3387
    uint64_t *p_domain_flags);
3388
3389
/*
3390
 * ssl_log_rsa_client_key_exchange logs |premaster| to the SSL_CTX associated
3391
 * with |ssl|, if logging is enabled. It returns one on success and zero on
3392
 * failure. The entry is identified by the first 8 bytes of
3393
 * |encrypted_premaster|.
3394
 */
3395
__owur int ssl_log_rsa_client_key_exchange(SSL_CONNECTION *s,
3396
    const uint8_t *encrypted_premaster,
3397
    size_t encrypted_premaster_len,
3398
    const uint8_t *premaster,
3399
    size_t premaster_len);
3400
3401
/*
3402
 * ssl_log_secret logs |secret| to the SSL_CTX associated with |ssl|, if
3403
 * logging is available. It returns one on success and zero on failure. It tags
3404
 * the entry with |label|.
3405
 */
3406
__owur int ssl_log_secret(SSL_CONNECTION *s, const char *label,
3407
    const uint8_t *secret, size_t secret_len);
3408
3409
0
#define MASTER_SECRET_LABEL "CLIENT_RANDOM"
3410
0
#define CLIENT_EARLY_LABEL "CLIENT_EARLY_TRAFFIC_SECRET"
3411
0
#define CLIENT_HANDSHAKE_LABEL "CLIENT_HANDSHAKE_TRAFFIC_SECRET"
3412
0
#define SERVER_HANDSHAKE_LABEL "SERVER_HANDSHAKE_TRAFFIC_SECRET"
3413
0
#define CLIENT_APPLICATION_LABEL "CLIENT_TRAFFIC_SECRET_0"
3414
0
#define CLIENT_APPLICATION_N_LABEL "CLIENT_TRAFFIC_SECRET_N"
3415
0
#define SERVER_APPLICATION_LABEL "SERVER_TRAFFIC_SECRET_0"
3416
0
#define SERVER_APPLICATION_N_LABEL "SERVER_TRAFFIC_SECRET_N"
3417
0
#define EARLY_EXPORTER_SECRET_LABEL "EARLY_EXPORTER_SECRET"
3418
0
#define EXPORTER_SECRET_LABEL "EXPORTER_SECRET"
3419
3420
__owur int srp_generate_server_master_secret(SSL_CONNECTION *s);
3421
__owur int srp_generate_client_master_secret(SSL_CONNECTION *s);
3422
__owur int srp_verify_server_param(SSL_CONNECTION *s);
3423
3424
/* statem/statem_srvr.c */
3425
3426
__owur int send_certificate_request(SSL_CONNECTION *s);
3427
3428
OCSP_RESPONSE *ossl_get_ocsp_response(SSL_CONNECTION *s, int chainidx);
3429
3430
/* statem/extensions_cust.c */
3431
3432
custom_ext_method *custom_ext_find(const custom_ext_methods *exts,
3433
    ENDPOINT role, unsigned int ext_type,
3434
    size_t *idx);
3435
3436
void custom_ext_init(custom_ext_methods *meths);
3437
3438
int ossl_tls_add_custom_ext_intern(SSL_CTX *ctx, custom_ext_methods *exts,
3439
    ENDPOINT role, unsigned int ext_type,
3440
    unsigned int context,
3441
    SSL_custom_ext_add_cb_ex add_cb,
3442
    SSL_custom_ext_free_cb_ex free_cb,
3443
    void *add_arg,
3444
    SSL_custom_ext_parse_cb_ex parse_cb,
3445
    void *parse_arg);
3446
__owur int custom_ext_parse(SSL_CONNECTION *s, unsigned int context,
3447
    unsigned int ext_type,
3448
    const unsigned char *ext_data, size_t ext_size,
3449
    X509 *x, size_t chainidx);
3450
__owur int custom_ext_add(SSL_CONNECTION *s, int context, WPACKET *pkt, X509 *x,
3451
    size_t chainidx, int maxversion);
3452
3453
__owur int custom_exts_copy(custom_ext_methods *dst,
3454
    const custom_ext_methods *src);
3455
__owur int custom_exts_copy_conn(custom_ext_methods *dst,
3456
    const custom_ext_methods *src);
3457
__owur int custom_exts_copy_flags(custom_ext_methods *dst,
3458
    const custom_ext_methods *src);
3459
void custom_exts_free(custom_ext_methods *exts);
3460
3461
/* ssl_mcnf.c */
3462
int ssl_ctx_system_config(SSL_CTX *ctx);
3463
3464
const EVP_CIPHER *ssl_evp_cipher_fetch(OSSL_LIB_CTX *libctx,
3465
    const char *name,
3466
    const char *properties);
3467
int ssl_evp_cipher_up_ref(const EVP_CIPHER *cipher);
3468
void ssl_evp_cipher_free(const EVP_CIPHER *cipher);
3469
int ssl_evp_md_up_ref(const EVP_MD *md);
3470
void ssl_evp_md_free(const EVP_MD *md);
3471
3472
SSL_HMAC *ssl_hmac_old_construct(SSL_HMAC *ret);
3473
void ssl_hmac_old_destruct(SSL_HMAC *ctx);
3474
int ssl_hmac_old_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
3475
int ssl_hmac_old_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
3476
int ssl_hmac_old_final(SSL_HMAC *ctx, unsigned char *md, size_t *len);
3477
size_t ssl_hmac_old_size(const SSL_HMAC *ctx);
3478
3479
int ssl_ctx_srp_ctx_free_intern(SSL_CTX *ctx);
3480
int ssl_ctx_srp_ctx_init_intern(SSL_CTX *ctx);
3481
int ssl_srp_ctx_free_intern(SSL_CONNECTION *s);
3482
int ssl_srp_ctx_init_intern(SSL_CONNECTION *s);
3483
3484
int ssl_srp_calc_a_param_intern(SSL_CONNECTION *s);
3485
int ssl_srp_server_param_with_username_intern(SSL_CONNECTION *s, int *ad);
3486
3487
void ssl_session_calculate_timeout(SSL_SESSION *ss);
3488
3489
#else /* OPENSSL_UNIT_TEST */
3490
3491
#define ssl_init_wbio_buffer SSL_test_functions()->p_ssl_init_wbio_buffer
3492
3493
#endif
3494
3495
/* Some helper routines to support TSAN operations safely */
3496
static ossl_unused ossl_inline int ssl_tsan_lock(const SSL_CTX *ctx)
3497
0
{
3498
#ifdef TSAN_REQUIRES_LOCKING
3499
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
3500
        return 0;
3501
#endif
3502
0
    return 1;
3503
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
3504
3505
static ossl_unused ossl_inline void ssl_tsan_unlock(const SSL_CTX *ctx)
3506
0
{
3507
#ifdef TSAN_REQUIRES_LOCKING
3508
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
3509
#endif
3510
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
3511
3512
static ossl_unused ossl_inline void ssl_tsan_counter(const SSL_CTX *ctx,
3513
    TSAN_QUALIFIER int *stat)
3514
0
{
3515
0
    if (ssl_tsan_lock(ctx)) {
3516
0
        tsan_counter(stat);
3517
0
        ssl_tsan_unlock(ctx);
3518
0
    }
3519
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
3520
3521
int ossl_comp_has_alg(int a);
3522
size_t ossl_calculate_comp_expansion(int alg, size_t length);
3523
3524
void ossl_ssl_set_custom_record_layer(SSL_CONNECTION *s,
3525
    const OSSL_RECORD_METHOD *meth,
3526
    void *rlarg);
3527
3528
long ossl_ctrl_internal(SSL *s, int cmd, long larg, void *parg, int no_quic);
3529
3530
/*
3531
 * Options which no longer have any effect, but which can be implemented
3532
 * as no-ops for QUIC.
3533
 */
3534
#define OSSL_LEGACY_SSL_OPTIONS \
3535
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)
3536
3537
/* This option is undefined in public headers with no-dtls1-method. */
3538
#ifndef SSL_OP_CISCO_ANYCONNECT
3539
#define SSL_OP_CISCO_ANYCONNECT 0
3540
#endif
3541
/*
3542
 * Options which are no-ops under QUIC or TLSv1.3 and which are therefore
3543
 * allowed but ignored under QUIC.
3544
 */
3545
#define OSSL_TLS1_2_OPTIONS \
3546
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)
3547
3548
/* Total mask of connection-level options permitted or ignored under QUIC. */
3549
#define OSSL_QUIC_PERMITTED_OPTIONS_CONN \
3550
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)
3551
3552
/* Total mask of stream-level options permitted or ignored under QUIC. */
3553
#define OSSL_QUIC_PERMITTED_OPTIONS_STREAM \
3554
0
    (OSSL_LEGACY_SSL_OPTIONS | OSSL_TLS1_2_OPTIONS | SSL_OP_CLEANSE_PLAINTEXT)
3555
3556
/* Total mask of options permitted on either connections or streams. */
3557
#define OSSL_QUIC_PERMITTED_OPTIONS \
3558
0
    (OSSL_QUIC_PERMITTED_OPTIONS_CONN | OSSL_QUIC_PERMITTED_OPTIONS_STREAM)
3559
3560
/* Total mask of domain flags supported on a QUIC SSL_CTX. */
3561
#define OSSL_QUIC_SUPPORTED_DOMAIN_FLAGS \
3562
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)
3563
3564
#endif