Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/ssl/ssl_local.h
Line
Count
Source
1
/*
2
 * Copyright 1995-2022 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 "e_os.h" /* struct timeval for DTLS */
16
#include <stdlib.h>
17
#include <time.h>
18
#include <string.h>
19
#include <errno.h>
20
21
#include <openssl/buffer.h>
22
#include <openssl/comp.h>
23
#include <openssl/bio.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 "record/record.h"
31
#include "statem/statem.h"
32
#include "internal/packet.h"
33
#include "internal/dane.h"
34
#include "internal/refcount.h"
35
#include "internal/tsan_assist.h"
36
#include "internal/bio.h"
37
#include "internal/ktls.h"
38
39
#ifdef OPENSSL_BUILD_SHLIBSSL
40
#undef OPENSSL_EXTERN
41
#define OPENSSL_EXTERN OPENSSL_EXPORT
42
#endif
43
44
#define c2l(c, l) (l = ((unsigned long)(*((c)++))), \
45
    l |= (((unsigned long)(*((c)++))) << 8),        \
46
    l |= (((unsigned long)(*((c)++))) << 16),       \
47
    l |= (((unsigned long)(*((c)++))) << 24))
48
49
/* NOTE - c is not incremented as per c2l */
50
#define c2ln(c, l1, l2, n)                           \
51
    {                                                \
52
        c += n;                                      \
53
        l1 = l2 = 0;                                 \
54
        switch (n) {                                 \
55
        case 8:                                      \
56
            l2 = ((unsigned long)(*(--(c)))) << 24;  \
57
        case 7:                                      \
58
            l2 |= ((unsigned long)(*(--(c)))) << 16; \
59
        case 6:                                      \
60
            l2 |= ((unsigned long)(*(--(c)))) << 8;  \
61
        case 5:                                      \
62
            l2 |= ((unsigned long)(*(--(c))));       \
63
        case 4:                                      \
64
            l1 = ((unsigned long)(*(--(c)))) << 24;  \
65
        case 3:                                      \
66
            l1 |= ((unsigned long)(*(--(c)))) << 16; \
67
        case 2:                                      \
68
            l1 |= ((unsigned long)(*(--(c)))) << 8;  \
69
        case 1:                                      \
70
            l1 |= ((unsigned long)(*(--(c))));       \
71
        }                                            \
72
    }
73
74
#define l2c(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
75
    *((c)++) = (unsigned char)(((l) >> 8) & 0xff),           \
76
    *((c)++) = (unsigned char)(((l) >> 16) & 0xff),          \
77
    *((c)++) = (unsigned char)(((l) >> 24) & 0xff))
78
79
#define n2l(c, l) (l = ((unsigned long)(*((c)++))) << 24, \
80
    l |= ((unsigned long)(*((c)++))) << 16,               \
81
    l |= ((unsigned long)(*((c)++))) << 8,                \
82
    l |= ((unsigned long)(*((c)++))))
83
84
0
#define n2l8(c, l) (l = ((uint64_t)(*((c)++))) << 56, \
85
0
    l |= ((uint64_t)(*((c)++))) << 48,                \
86
0
    l |= ((uint64_t)(*((c)++))) << 40,                \
87
0
    l |= ((uint64_t)(*((c)++))) << 32,                \
88
0
    l |= ((uint64_t)(*((c)++))) << 24,                \
89
0
    l |= ((uint64_t)(*((c)++))) << 16,                \
90
0
    l |= ((uint64_t)(*((c)++))) << 8,                 \
91
0
    l |= ((uint64_t)(*((c)++))))
92
93
0
#define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24) & 0xff), \
94
0
    *((c)++) = (unsigned char)(((l) >> 16) & 0xff),                \
95
0
    *((c)++) = (unsigned char)(((l) >> 8) & 0xff),                 \
96
0
    *((c)++) = (unsigned char)(((l)) & 0xff))
97
98
#define l2n6(l, c) (*((c)++) = (unsigned char)(((l) >> 40) & 0xff), \
99
    *((c)++) = (unsigned char)(((l) >> 32) & 0xff),                 \
100
    *((c)++) = (unsigned char)(((l) >> 24) & 0xff),                 \
101
    *((c)++) = (unsigned char)(((l) >> 16) & 0xff),                 \
102
    *((c)++) = (unsigned char)(((l) >> 8) & 0xff),                  \
103
    *((c)++) = (unsigned char)(((l)) & 0xff))
104
105
#define l2n8(l, c) (*((c)++) = (unsigned char)(((l) >> 56) & 0xff), \
106
    *((c)++) = (unsigned char)(((l) >> 48) & 0xff),                 \
107
    *((c)++) = (unsigned char)(((l) >> 40) & 0xff),                 \
108
    *((c)++) = (unsigned char)(((l) >> 32) & 0xff),                 \
109
    *((c)++) = (unsigned char)(((l) >> 24) & 0xff),                 \
110
    *((c)++) = (unsigned char)(((l) >> 16) & 0xff),                 \
111
    *((c)++) = (unsigned char)(((l) >> 8) & 0xff),                  \
112
    *((c)++) = (unsigned char)(((l)) & 0xff))
113
114
/* NOTE - c is not incremented as per l2c */
115
#define l2cn(l1, l2, c, n)                                   \
116
    {                                                        \
117
        c += n;                                              \
118
        switch (n) {                                         \
119
        case 8:                                              \
120
            *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
121
        case 7:                                              \
122
            *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
123
        case 6:                                              \
124
            *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff);  \
125
        case 5:                                              \
126
            *(--(c)) = (unsigned char)(((l2)) & 0xff);       \
127
        case 4:                                              \
128
            *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
129
        case 3:                                              \
130
            *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
131
        case 2:                                              \
132
            *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff);  \
133
        case 1:                                              \
134
            *(--(c)) = (unsigned char)(((l1)) & 0xff);       \
135
        }                                                    \
136
    }
137
138
137k
#define n2s(c, s) ((s = (((unsigned int)((c)[0])) << 8) | (((unsigned int)((c)[1])))), (c) += 2)
139
214k
#define s2n(s, c) (((c)[0] = (unsigned char)(((s) >> 8) & 0xff), \
140
214k
                       (c)[1] = (unsigned char)(((s)) & 0xff)),  \
141
214k
    (c) += 2)
142
143
676k
#define n2l3(c, l) ((l = (((unsigned long)((c)[0])) << 16) | (((unsigned long)((c)[1])) << 8) | (((unsigned long)((c)[2])))), (c) += 3)
144
145
642k
#define l2n3(l, c) (((c)[0] = (unsigned char)(((l) >> 16) & 0xff),   \
146
642k
                        (c)[1] = (unsigned char)(((l) >> 8) & 0xff), \
147
642k
                        (c)[2] = (unsigned char)(((l)) & 0xff)),     \
148
642k
    (c) += 3)
149
150
45.8k
#define TLS_MAX_VERSION_INTERNAL TLS1_3_VERSION
151
#define DTLS_MAX_VERSION_INTERNAL DTLS1_2_VERSION
152
153
/*
154
 * DTLS version numbers are strange because they're inverted. Except for
155
 * DTLS1_BAD_VER, which should be considered "lower" than the rest.
156
 */
157
22.6k
#define dtls_ver_ordinal(v1) (((v1) == DTLS1_BAD_VER) ? 0xff00 : (v1))
158
0
#define DTLS_VERSION_GT(v1, v2) (dtls_ver_ordinal(v1) < dtls_ver_ordinal(v2))
159
11.3k
#define DTLS_VERSION_GE(v1, v2) (dtls_ver_ordinal(v1) <= dtls_ver_ordinal(v2))
160
0
#define DTLS_VERSION_LT(v1, v2) (dtls_ver_ordinal(v1) > dtls_ver_ordinal(v2))
161
0
#define DTLS_VERSION_LE(v1, v2) (dtls_ver_ordinal(v1) >= dtls_ver_ordinal(v2))
162
163
/*
164
 * Define the Bitmasks for SSL_CIPHER.algorithms.
165
 * This bits are used packed as dense as possible. If new methods/ciphers
166
 * etc will be added, the bits a likely to change, so this information
167
 * is for internal library use only, even though SSL_CIPHER.algorithms
168
 * can be publicly accessed.
169
 * Use the according functions for cipher management instead.
170
 *
171
 * The bit mask handling in the selection and sorting scheme in
172
 * ssl_create_cipher_list() has only limited capabilities, reflecting
173
 * that the different entities within are mutually exclusive:
174
 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
175
 */
176
177
/* Bits for algorithm_mkey (key exchange algorithm) */
178
/* RSA key exchange */
179
60.8k
#define SSL_kRSA 0x00000001U
180
/* tmp DH key no DH cert */
181
145k
#define SSL_kDHE 0x00000002U
182
/* synonym */
183
#define SSL_kEDH SSL_kDHE
184
/* ephemeral ECDH */
185
440k
#define SSL_kECDHE 0x00000004U
186
/* synonym */
187
#define SSL_kEECDH SSL_kECDHE
188
/* PSK */
189
591k
#define SSL_kPSK 0x00000008U
190
/* GOST key exchange */
191
43.0k
#define SSL_kGOST 0x00000010U
192
/* SRP */
193
828k
#define SSL_kSRP 0x00000020U
194
195
582k
#define SSL_kRSAPSK 0x00000040U
196
779k
#define SSL_kECDHEPSK 0x00000080U
197
588k
#define SSL_kDHEPSK 0x00000100U
198
/* GOST KDF key exchange, draft-smyshlyaev-tls12-gost-suites */
199
59.5k
#define SSL_kGOST18 0x00000200U
200
201
/* all PSK */
202
203
503k
#define SSL_PSK (SSL_kPSK | SSL_kRSAPSK | SSL_kECDHEPSK | SSL_kDHEPSK)
204
205
/* Any appropriate key exchange algorithm (for TLS 1.3 ciphersuites) */
206
0
#define SSL_kANY 0x00000000U
207
208
/* Bits for algorithm_auth (server authentication) */
209
/* RSA auth */
210
372k
#define SSL_aRSA 0x00000001U
211
/* DSS auth */
212
367k
#define SSL_aDSS 0x00000002U
213
/* no auth (i.e. use ADH or AECDH) */
214
75.9k
#define SSL_aNULL 0x00000004U
215
/* ECDSA auth*/
216
557k
#define SSL_aECDSA 0x00000008U
217
/* PSK auth */
218
388k
#define SSL_aPSK 0x00000010U
219
/* GOST R 34.10-2001 signature auth */
220
133k
#define SSL_aGOST01 0x00000020U
221
/* SRP auth */
222
404k
#define SSL_aSRP 0x00000040U
223
/* GOST R 34.10-2012 signature auth */
224
305k
#define SSL_aGOST12 0x00000080U
225
/* Any appropriate signature auth (for TLS 1.3 ciphersuites) */
226
0
#define SSL_aANY 0x00000000U
227
/* All bits requiring a certificate */
228
#define SSL_aCERT \
229
3.69k
    (SSL_aRSA | SSL_aDSS | SSL_aECDSA | SSL_aGOST01 | SSL_aGOST12)
230
231
/* Bits for algorithm_enc (symmetric encryption) */
232
0
#define SSL_DES 0x00000001U
233
0
#define SSL_3DES 0x00000002U
234
53.4k
#define SSL_RC4 0x00000004U
235
0
#define SSL_RC2 0x00000008U
236
0
#define SSL_IDEA 0x00000010U
237
347
#define SSL_eNULL 0x00000020U
238
60.8k
#define SSL_AES128 0x00000040U
239
58.6k
#define SSL_AES256 0x00000080U
240
0
#define SSL_CAMELLIA128 0x00000100U
241
0
#define SSL_CAMELLIA256 0x00000200U
242
10.6k
#define SSL_eGOST2814789CNT 0x00000400U
243
0
#define SSL_SEED 0x00000800U
244
99.0k
#define SSL_AES128GCM 0x00001000U
245
99.0k
#define SSL_AES256GCM 0x00002000U
246
80.0k
#define SSL_AES128CCM 0x00004000U
247
80.0k
#define SSL_AES256CCM 0x00008000U
248
80.1k
#define SSL_AES128CCM8 0x00010000U
249
80.1k
#define SSL_AES256CCM8 0x00020000U
250
10.6k
#define SSL_eGOST2814789CNT12 0x00040000U
251
33.9k
#define SSL_CHACHA20POLY1305 0x00080000U
252
0
#define SSL_ARIA128GCM 0x00100000U
253
0
#define SSL_ARIA256GCM 0x00200000U
254
10.6k
#define SSL_MAGMA 0x00400000U
255
4.34k
#define SSL_KUZNYECHIK 0x00800000U
256
257
99.0k
#define SSL_AESGCM (SSL_AES128GCM | SSL_AES256GCM)
258
80.0k
#define SSL_AESCCM (SSL_AES128CCM | SSL_AES256CCM | SSL_AES128CCM8 | SSL_AES256CCM8)
259
22.9k
#define SSL_AES (SSL_AES128 | SSL_AES256 | SSL_AESGCM | SSL_AESCCM)
260
#define SSL_CAMELLIA (SSL_CAMELLIA128 | SSL_CAMELLIA256)
261
33.9k
#define SSL_CHACHA20 (SSL_CHACHA20POLY1305)
262
0
#define SSL_ARIAGCM (SSL_ARIA128GCM | SSL_ARIA256GCM)
263
#define SSL_ARIA (SSL_ARIAGCM)
264
#define SSL_CBC (SSL_DES | SSL_3DES | SSL_RC2 | SSL_IDEA \
265
    | SSL_AES128 | SSL_AES256 | SSL_CAMELLIA128          \
266
    | SSL_CAMELLIA256 | SSL_SEED)
267
268
/* Bits for algorithm_mac (symmetric authentication) */
269
270
22.9k
#define SSL_MD5 0x00000001U
271
1.48k
#define SSL_SHA1 0x00000002U
272
0
#define SSL_GOST94 0x00000004U
273
43.0k
#define SSL_GOST89MAC 0x00000008U
274
948
#define SSL_SHA256 0x00000010U
275
0
#define SSL_SHA384 0x00000020U
276
/* Not a real MAC, just an indication it is part of cipher */
277
65.7k
#define SSL_AEAD 0x00000040U
278
0
#define SSL_GOST12_256 0x00000080U
279
43.0k
#define SSL_GOST89MAC12 0x00000100U
280
0
#define SSL_GOST12_512 0x00000200U
281
43.0k
#define SSL_MAGMAOMAC 0x00000400U
282
43.0k
#define SSL_KUZNYECHIKOMAC 0x00000800U
283
284
/*
285
 * When adding new digest in the ssl_ciph.c and increment SSL_MD_NUM_IDX make
286
 * sure to update this constant too
287
 */
288
289
3.05M
#define SSL_MD_MD5_IDX 0
290
3.09M
#define SSL_MD_SHA1_IDX 1
291
#define SSL_MD_GOST94_IDX 2
292
86.1k
#define SSL_MD_GOST89MAC_IDX 3
293
93.2k
#define SSL_MD_SHA256_IDX 4
294
0
#define SSL_MD_SHA384_IDX 5
295
#define SSL_MD_GOST12_256_IDX 6
296
86.1k
#define SSL_MD_GOST89MAC12_IDX 7
297
#define SSL_MD_GOST12_512_IDX 8
298
870k
#define SSL_MD_MD5_SHA1_IDX 9
299
1.19M
#define SSL_MD_SHA224_IDX 10
300
#define SSL_MD_SHA512_IDX 11
301
86.1k
#define SSL_MD_MAGMAOMAC_IDX 12
302
86.1k
#define SSL_MD_KUZNYECHIKOMAC_IDX 13
303
4.98M
#define SSL_MAX_DIGEST 14
304
305
4.98M
#define SSL_MD_NUM_IDX SSL_MAX_DIGEST
306
307
/* Bits for algorithm2 (handshake digests and other extra flags) */
308
309
/* Bits 0-7 are handshake MAC */
310
4.23M
#define SSL_HANDSHAKE_MAC_MASK 0xFF
311
429k
#define SSL_HANDSHAKE_MAC_MD5_SHA1 SSL_MD_MD5_SHA1_IDX
312
46.6k
#define SSL_HANDSHAKE_MAC_SHA256 SSL_MD_SHA256_IDX
313
0
#define SSL_HANDSHAKE_MAC_SHA384 SSL_MD_SHA384_IDX
314
#define SSL_HANDSHAKE_MAC_GOST94 SSL_MD_GOST94_IDX
315
#define SSL_HANDSHAKE_MAC_GOST12_256 SSL_MD_GOST12_256_IDX
316
#define SSL_HANDSHAKE_MAC_GOST12_512 SSL_MD_GOST12_512_IDX
317
429k
#define SSL_HANDSHAKE_MAC_DEFAULT SSL_HANDSHAKE_MAC_MD5_SHA1
318
319
/* Bits 8-15 bits are PRF */
320
544k
#define TLS1_PRF_DGST_SHIFT 8
321
#define TLS1_PRF_SHA1_MD5 (SSL_MD_MD5_SHA1_IDX << TLS1_PRF_DGST_SHIFT)
322
46.6k
#define TLS1_PRF_SHA256 (SSL_MD_SHA256_IDX << TLS1_PRF_DGST_SHIFT)
323
0
#define TLS1_PRF_SHA384 (SSL_MD_SHA384_IDX << TLS1_PRF_DGST_SHIFT)
324
#define TLS1_PRF_GOST94 (SSL_MD_GOST94_IDX << TLS1_PRF_DGST_SHIFT)
325
#define TLS1_PRF_GOST12_256 (SSL_MD_GOST12_256_IDX << TLS1_PRF_DGST_SHIFT)
326
#define TLS1_PRF_GOST12_512 (SSL_MD_GOST12_512_IDX << TLS1_PRF_DGST_SHIFT)
327
429k
#define TLS1_PRF (SSL_MD_MD5_SHA1_IDX << TLS1_PRF_DGST_SHIFT)
328
329
/*
330
 * Stream MAC for GOST ciphersuites from cryptopro draft (currently this also
331
 * goes into algorithm2)
332
 */
333
2.08k
#define TLS1_STREAM_MAC 0x10000
334
/*
335
 * TLSTREE cipher/mac key derivation from draft-smyshlyaev-tls12-gost-suites
336
 * (currently this also  goes into algorithm2)
337
 */
338
2.08k
#define TLS1_TLSTREE 0x20000
339
340
243M
#define SSL_STRONG_MASK 0x0000001FU
341
262M
#define SSL_DEFAULT_MASK 0X00000020U
342
343
#define SSL_STRONG_NONE 0x00000001U
344
#define SSL_LOW 0x00000002U
345
#define SSL_MEDIUM 0x00000004U
346
#define SSL_HIGH 0x00000008U
347
#define SSL_FIPS 0x00000010U
348
#define SSL_NOT_DEFAULT 0x00000020U
349
350
/* we have used 0000003f - 26 bits left to go */
351
352
/* Flag used on OpenSSL ciphersuite ids to indicate they are for SSLv3+ */
353
7.47M
#define SSL3_CK_CIPHERSUITE_FLAG 0x03000000
354
355
/* Check if an SSL structure is using DTLS */
356
79.5M
#define SSL_IS_DTLS(s) (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS)
357
358
/* Check if we are using TLSv1.3 */
359
16.9M
#define SSL_IS_TLS13(s) (!SSL_IS_DTLS(s)      \
360
11.2M
    && (s)->method->version >= TLS1_3_VERSION \
361
16.9M
    && (s)->method->version != TLS_ANY_VERSION)
362
363
#define SSL_TREAT_AS_TLS13(s)                                              \
364
188k
    (SSL_IS_TLS13(s) || (s)->early_data_state == SSL_EARLY_DATA_CONNECTING \
365
130k
        || (s)->early_data_state == SSL_EARLY_DATA_CONNECT_RETRY           \
366
130k
        || (s)->early_data_state == SSL_EARLY_DATA_WRITING                 \
367
130k
        || (s)->early_data_state == SSL_EARLY_DATA_WRITE_RETRY             \
368
188k
        || (s)->hello_retry_request == SSL_HRR_PENDING)
369
370
432k
#define SSL_IS_FIRST_HANDSHAKE(S) ((s)->s3.tmp.finish_md_len == 0 \
371
432k
    || (s)->s3.tmp.peer_finish_md_len == 0)
372
373
/* See if we need explicit IV */
374
#define SSL_USE_EXPLICIT_IV(s) \
375
118k
    (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_EXPLICIT_IV)
376
/*
377
 * See if we use signature algorithms extension and signature algorithm
378
 * before signatures.
379
 */
380
#define SSL_USE_SIGALGS(s) \
381
519k
    (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_SIGALGS)
382
/*
383
 * Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2: may
384
 * apply to others in future.
385
 */
386
#define SSL_USE_TLS1_2_CIPHERS(s) \
387
    (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)
388
/*
389
 * Determine if a client can use TLS 1.2 ciphersuites: can't rely on method
390
 * flags because it may not be set to correct version yet.
391
 */
392
#define SSL_CLIENT_USE_TLS1_2_CIPHERS(s) \
393
52.6k
    ((!SSL_IS_DTLS(s) && s->client_version >= TLS1_2_VERSION) || (SSL_IS_DTLS(s) && DTLS_VERSION_GE(s->client_version, DTLS1_2_VERSION)))
394
/*
395
 * Determine if a client should send signature algorithms extension:
396
 * as with TLS1.2 cipher we can't rely on method flags.
397
 */
398
#define SSL_CLIENT_USE_SIGALGS(s) \
399
52.6k
    SSL_CLIENT_USE_TLS1_2_CIPHERS(s)
400
401
#define IS_MAX_FRAGMENT_LENGTH_EXT_VALID(value) \
402
1.07M
    (((value) >= TLSEXT_max_fragment_length_512) && ((value) <= TLSEXT_max_fragment_length_4096))
403
#define USE_MAX_FRAGMENT_LENGTH_EXT(session) \
404
836k
    IS_MAX_FRAGMENT_LENGTH_EXT_VALID(session->ext.max_fragment_len_mode)
405
#define GET_MAX_FRAGMENT_LENGTH(session) \
406
16.4k
    (512U << (session->ext.max_fragment_len_mode - 1))
407
408
125k
#define SSL_READ_ETM(s) (s->s3.flags & TLS1_FLAGS_ENCRYPT_THEN_MAC_READ)
409
136k
#define SSL_WRITE_ETM(s) (s->s3.flags & TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE)
410
411
/* Mostly for SSLv3 */
412
112k
#define SSL_PKEY_RSA 0
413
28.6k
#define SSL_PKEY_RSA_PSS_SIGN 1
414
30.9k
#define SSL_PKEY_DSA_SIGN 2
415
198k
#define SSL_PKEY_ECC 3
416
71.8k
#define SSL_PKEY_GOST01 4
417
51.4k
#define SSL_PKEY_GOST12_256 5
418
30.9k
#define SSL_PKEY_GOST12_512 6
419
29.3k
#define SSL_PKEY_ED25519 7
420
29.3k
#define SSL_PKEY_ED448 8
421
4.16M
#define SSL_PKEY_NUM 9
422
423
#define SSL_ENC_DES_IDX 0
424
#define SSL_ENC_3DES_IDX 1
425
#define SSL_ENC_RC4_IDX 2
426
#define SSL_ENC_RC2_IDX 3
427
#define SSL_ENC_IDEA_IDX 4
428
51.2k
#define SSL_ENC_NULL_IDX 5
429
#define SSL_ENC_AES128_IDX 6
430
#define SSL_ENC_AES256_IDX 7
431
#define SSL_ENC_CAMELLIA128_IDX 8
432
#define SSL_ENC_CAMELLIA256_IDX 9
433
#define SSL_ENC_GOST89_IDX 10
434
#define SSL_ENC_SEED_IDX 11
435
#define SSL_ENC_AES128GCM_IDX 12
436
#define SSL_ENC_AES256GCM_IDX 13
437
#define SSL_ENC_AES128CCM_IDX 14
438
#define SSL_ENC_AES256CCM_IDX 15
439
#define SSL_ENC_AES128CCM8_IDX 16
440
#define SSL_ENC_AES256CCM8_IDX 17
441
#define SSL_ENC_GOST8912_IDX 18
442
#define SSL_ENC_CHACHA_IDX 19
443
#define SSL_ENC_ARIA128GCM_IDX 20
444
#define SSL_ENC_ARIA256GCM_IDX 21
445
#define SSL_ENC_MAGMA_IDX 22
446
#define SSL_ENC_KUZNYECHIK_IDX 23
447
1.36M
#define SSL_ENC_NUM_IDX 24
448
449
/*-
450
 * SSL_kRSA <- RSA_ENC
451
 * SSL_kDH  <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
452
 * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
453
 * SSL_aRSA <- RSA_ENC | RSA_SIGN
454
 * SSL_aDSS <- DSA_SIGN
455
 */
456
457
/*-
458
#define CERT_INVALID            0
459
#define CERT_PUBLIC_KEY         1
460
#define CERT_PRIVATE_KEY        2
461
*/
462
463
/* Post-Handshake Authentication state */
464
typedef enum {
465
    SSL_PHA_NONE = 0,
466
    SSL_PHA_EXT_SENT, /* client-side only: extension sent */
467
    SSL_PHA_EXT_RECEIVED, /* server-side only: extension received */
468
    SSL_PHA_REQUEST_PENDING, /* server-side only: request pending */
469
    SSL_PHA_REQUESTED /* request received by client, or sent by server */
470
} SSL_PHA_STATE;
471
472
/* CipherSuite length. SSLv3 and all TLS versions. */
473
378k
#define TLS_CIPHER_LEN 2
474
/* used to hold info on the particular ciphers used */
475
struct ssl_cipher_st {
476
    uint32_t valid;
477
    const char *name; /* text name */
478
    const char *stdname; /* RFC name */
479
    uint32_t id; /* id, 4 bytes, first is version */
480
    /*
481
     * changed in 1.0.0: these four used to be portions of a single value
482
     * 'algorithms'
483
     */
484
    uint32_t algorithm_mkey; /* key exchange algorithm */
485
    uint32_t algorithm_auth; /* server authentication */
486
    uint32_t algorithm_enc; /* symmetric encryption */
487
    uint32_t algorithm_mac; /* symmetric authentication */
488
    int min_tls; /* minimum SSL/TLS protocol version */
489
    int max_tls; /* maximum SSL/TLS protocol version */
490
    int min_dtls; /* minimum DTLS protocol version */
491
    int max_dtls; /* maximum DTLS protocol version */
492
    uint32_t algo_strength; /* strength and export flags */
493
    uint32_t algorithm2; /* Extra flags */
494
    int32_t strength_bits; /* Number of bits really used */
495
    uint32_t alg_bits; /* Number of bits for algorithm */
496
};
497
498
/* Used to hold SSL/TLS functions */
499
struct ssl_method_st {
500
    int version;
501
    unsigned flags;
502
    unsigned long mask;
503
    int (*ssl_new)(SSL *s);
504
    int (*ssl_clear)(SSL *s);
505
    void (*ssl_free)(SSL *s);
506
    int (*ssl_accept)(SSL *s);
507
    int (*ssl_connect)(SSL *s);
508
    int (*ssl_read)(SSL *s, void *buf, size_t len, size_t *readbytes);
509
    int (*ssl_peek)(SSL *s, void *buf, size_t len, size_t *readbytes);
510
    int (*ssl_write)(SSL *s, const void *buf, size_t len, size_t *written);
511
    int (*ssl_shutdown)(SSL *s);
512
    int (*ssl_renegotiate)(SSL *s);
513
    int (*ssl_renegotiate_check)(SSL *s, int);
514
    int (*ssl_read_bytes)(SSL *s, int type, int *recvd_type,
515
        unsigned char *buf, size_t len, int peek,
516
        size_t *readbytes);
517
    int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, size_t len,
518
        size_t *written);
519
    int (*ssl_dispatch_alert)(SSL *s);
520
    long (*ssl_ctrl)(SSL *s, int cmd, long larg, void *parg);
521
    long (*ssl_ctx_ctrl)(SSL_CTX *ctx, int cmd, long larg, void *parg);
522
    const SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
523
    int (*put_cipher_by_char)(const SSL_CIPHER *cipher, WPACKET *pkt,
524
        size_t *len);
525
    size_t (*ssl_pending)(const SSL *s);
526
    int (*num_ciphers)(void);
527
    const SSL_CIPHER *(*get_cipher)(unsigned ncipher);
528
    long (*get_timeout)(void);
529
    const struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
530
    int (*ssl_version)(void);
531
    long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)(void));
532
    long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)(void));
533
};
534
535
/*
536
 * Matches the length of PSK_MAX_PSK_LEN. We keep it the same value for
537
 * consistency, even in the event of OPENSSL_NO_PSK being defined.
538
 */
539
560
#define TLS13_MAX_RESUMPTION_PSK_LENGTH 512
540
541
/*-
542
 * Lets make this into an ASN.1 type structure as follows
543
 * SSL_SESSION_ID ::= SEQUENCE {
544
 *      version                 INTEGER,        -- structure version number
545
 *      SSLversion              INTEGER,        -- SSL version number
546
 *      Cipher                  OCTET STRING,   -- the 3 byte cipher ID
547
 *      Session_ID              OCTET STRING,   -- the Session ID
548
 *      Master_key              OCTET STRING,   -- the master key
549
 *      Key_Arg [ 0 ] IMPLICIT  OCTET STRING,   -- the optional Key argument
550
 *      Time [ 1 ] EXPLICIT     INTEGER,        -- optional Start Time
551
 *      Timeout [ 2 ] EXPLICIT  INTEGER,        -- optional Timeout ins seconds
552
 *      Peer [ 3 ] EXPLICIT     X509,           -- optional Peer Certificate
553
 *      Session_ID_context [ 4 ] EXPLICIT OCTET STRING,   -- the Session ID context
554
 *      Verify_result [ 5 ] EXPLICIT INTEGER,   -- X509_V_... code for `Peer'
555
 *      HostName [ 6 ] EXPLICIT OCTET STRING,   -- optional HostName from servername TLS extension
556
 *      PSK_identity_hint [ 7 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
557
 *      PSK_identity [ 8 ] EXPLICIT OCTET STRING,  -- optional PSK identity
558
 *      Ticket_lifetime_hint [9] EXPLICIT INTEGER, -- server's lifetime hint for session ticket
559
 *      Ticket [10]             EXPLICIT OCTET STRING, -- session ticket (clients only)
560
 *      Compression_meth [11]   EXPLICIT OCTET STRING, -- optional compression method
561
 *      SRP_username [ 12 ] EXPLICIT OCTET STRING -- optional SRP username
562
 *      flags [ 13 ] EXPLICIT INTEGER -- optional flags
563
 *      }
564
 * Look in ssl/ssl_asn1.c for more details
565
 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
566
 */
567
struct ssl_session_st {
568
    int ssl_version; /* what ssl version session info is being kept
569
                      * in here? */
570
    size_t master_key_length;
571
572
    /* TLSv1.3 early_secret used for external PSKs */
573
    unsigned char early_secret[EVP_MAX_MD_SIZE];
574
    /*
575
     * For <=TLS1.2 this is the master_key. For TLS1.3 this is the resumption
576
     * PSK
577
     */
578
    unsigned char master_key[TLS13_MAX_RESUMPTION_PSK_LENGTH];
579
    /* session_id - valid? */
580
    size_t session_id_length;
581
    unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
582
    /*
583
     * this is used to determine whether the session is being reused in the
584
     * appropriate context. It is up to the application to set this, via
585
     * SSL_new
586
     */
587
    size_t sid_ctx_length;
588
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
589
#ifndef OPENSSL_NO_PSK
590
    char *psk_identity_hint;
591
    char *psk_identity;
592
#endif
593
    /*
594
     * Used to indicate that session resumption is not allowed. Applications
595
     * can also set this bit for a new session via not_resumable_session_cb
596
     * to disable session caching and tickets.
597
     */
598
    int not_resumable;
599
    /* This is the cert and type for the other end. */
600
    X509 *peer;
601
    /* Certificate chain peer sent. */
602
    STACK_OF(X509) *peer_chain;
603
    /*
604
     * when app_verify_callback accepts a session where the peer's
605
     * certificate is not ok, we must remember the error for session reuse:
606
     */
607
    long verify_result; /* only for servers */
608
    CRYPTO_REF_COUNT references;
609
    time_t timeout;
610
    time_t time;
611
    time_t calc_timeout;
612
    int timeout_ovf;
613
    unsigned int compress_meth; /* Need to lookup the method */
614
    const SSL_CIPHER *cipher;
615
    unsigned long cipher_id; /* when ASN.1 loaded, this needs to be used to
616
                              * load the 'cipher' structure */
617
    unsigned int kex_group; /* TLS group from key exchange */
618
    CRYPTO_EX_DATA ex_data; /* application specific data */
619
    /*
620
     * These are used to make removal of session-ids more efficient and to
621
     * implement a maximum cache size.
622
     */
623
    struct ssl_session_st *prev, *next;
624
625
    struct {
626
        char *hostname;
627
        /* RFC4507 info */
628
        unsigned char *tick; /* Session ticket */
629
        size_t ticklen; /* Session ticket length */
630
        /* Session lifetime hint in seconds */
631
        unsigned long tick_lifetime_hint;
632
        uint32_t tick_age_add;
633
        /* Max number of bytes that can be sent as early data */
634
        uint32_t max_early_data;
635
        /* The ALPN protocol selected for this session */
636
        unsigned char *alpn_selected;
637
        size_t alpn_selected_len;
638
        /*
639
         * Maximum Fragment Length as per RFC 4366.
640
         * If this value does not contain RFC 4366 allowed values (1-4) then
641
         * either the Maximum Fragment Length Negotiation failed or was not
642
         * performed at all.
643
         */
644
        uint8_t max_fragment_len_mode;
645
    } ext;
646
#ifndef OPENSSL_NO_SRP
647
    char *srp_username;
648
#endif
649
    unsigned char *ticket_appdata;
650
    size_t ticket_appdata_len;
651
    uint32_t flags;
652
    SSL_CTX *owner;
653
    CRYPTO_RWLOCK *lock;
654
};
655
656
/* Extended master secret support */
657
38.3k
#define SSL_SESS_FLAG_EXTMS 0x1
658
659
#ifndef OPENSSL_NO_SRP
660
661
typedef struct srp_ctx_st {
662
    /* param for all the callbacks */
663
    void *SRP_cb_arg;
664
    /* set client Hello login callback */
665
    int (*TLS_ext_srp_username_callback)(SSL *, int *, void *);
666
    /* set SRP N/g param callback for verification */
667
    int (*SRP_verify_param_callback)(SSL *, void *);
668
    /* set SRP client passwd callback */
669
    char *(*SRP_give_srp_client_pwd_callback)(SSL *, void *);
670
    char *login;
671
    BIGNUM *N, *g, *s, *B, *A;
672
    BIGNUM *a, *b, *v;
673
    char *info;
674
    int strength;
675
    unsigned long srp_Mask;
676
} SRP_CTX;
677
678
#endif
679
680
typedef enum {
681
    SSL_EARLY_DATA_NONE = 0,
682
    SSL_EARLY_DATA_CONNECT_RETRY,
683
    SSL_EARLY_DATA_CONNECTING,
684
    SSL_EARLY_DATA_WRITE_RETRY,
685
    SSL_EARLY_DATA_WRITING,
686
    SSL_EARLY_DATA_WRITE_FLUSH,
687
    SSL_EARLY_DATA_UNAUTH_WRITING,
688
    SSL_EARLY_DATA_FINISHED_WRITING,
689
    SSL_EARLY_DATA_ACCEPT_RETRY,
690
    SSL_EARLY_DATA_ACCEPTING,
691
    SSL_EARLY_DATA_READ_RETRY,
692
    SSL_EARLY_DATA_READING,
693
    SSL_EARLY_DATA_FINISHED_READING
694
} SSL_EARLY_DATA_STATE;
695
696
/*
697
 * We check that the amount of unreadable early data doesn't exceed
698
 * max_early_data. max_early_data is given in plaintext bytes. However if it is
699
 * unreadable then we only know the number of ciphertext bytes. We also don't
700
 * know how much the overhead should be because it depends on the ciphersuite.
701
 * We make a small allowance. We assume 5 records of actual data plus the end
702
 * of early data alert record. Each record has a tag and a content type byte.
703
 * The longest tag length we know of is EVP_GCM_TLS_TAG_LEN. We don't count the
704
 * content of the alert record either which is 2 bytes.
705
 */
706
28.1k
#define EARLY_DATA_CIPHERTEXT_OVERHEAD ((6 * (EVP_GCM_TLS_TAG_LEN + 1)) + 2)
707
708
/*
709
 * The allowance we have between the client's calculated ticket age and our own.
710
 * We allow for 10 seconds (units are in ms). If a ticket is presented and the
711
 * client's age calculation is different by more than this than our own then we
712
 * do not allow that ticket for early_data.
713
 */
714
4
#define TICKET_AGE_ALLOWANCE (10 * 1000)
715
716
42.6k
#define MAX_COMPRESSIONS_SIZE 255
717
718
struct ssl_comp_st {
719
    int id;
720
    const char *name;
721
    COMP_METHOD *method;
722
};
723
724
typedef struct raw_extension_st {
725
    /* Raw packet data for the extension */
726
    PACKET data;
727
    /* Set to 1 if the extension is present or 0 otherwise */
728
    int present;
729
    /* Set to 1 if we have already parsed the extension or 0 otherwise */
730
    int parsed;
731
    /* The type of this extension, i.e. a TLSEXT_TYPE_* value */
732
    unsigned int type;
733
    /* Track what order extensions are received in (0-based). */
734
    size_t received_order;
735
} RAW_EXTENSION;
736
737
typedef struct {
738
    unsigned int isv2;
739
    unsigned int legacy_version;
740
    unsigned char random[SSL3_RANDOM_SIZE];
741
    size_t session_id_len;
742
    unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
743
    size_t dtls_cookie_len;
744
    unsigned char dtls_cookie[DTLS1_COOKIE_LENGTH];
745
    PACKET ciphersuites;
746
    size_t compressions_len;
747
    unsigned char compressions[MAX_COMPRESSIONS_SIZE];
748
    PACKET extensions;
749
    size_t pre_proc_exts_len;
750
    RAW_EXTENSION *pre_proc_exts;
751
} CLIENTHELLO_MSG;
752
753
/*
754
 * Extension index values NOTE: Any updates to these defines should be mirrored
755
 * with equivalent updates to ext_defs in extensions.c
756
 */
757
typedef enum tlsext_index_en {
758
    TLSEXT_IDX_renegotiate,
759
    TLSEXT_IDX_server_name,
760
    TLSEXT_IDX_max_fragment_length,
761
    TLSEXT_IDX_srp,
762
    TLSEXT_IDX_ec_point_formats,
763
    TLSEXT_IDX_supported_groups,
764
    TLSEXT_IDX_session_ticket,
765
    TLSEXT_IDX_status_request,
766
    TLSEXT_IDX_next_proto_neg,
767
    TLSEXT_IDX_application_layer_protocol_negotiation,
768
    TLSEXT_IDX_use_srtp,
769
    TLSEXT_IDX_encrypt_then_mac,
770
    TLSEXT_IDX_signed_certificate_timestamp,
771
    TLSEXT_IDX_extended_master_secret,
772
    TLSEXT_IDX_signature_algorithms_cert,
773
    TLSEXT_IDX_post_handshake_auth,
774
    TLSEXT_IDX_signature_algorithms,
775
    TLSEXT_IDX_supported_versions,
776
    TLSEXT_IDX_psk_kex_modes,
777
    TLSEXT_IDX_key_share,
778
    TLSEXT_IDX_cookie,
779
    TLSEXT_IDX_cryptopro_bug,
780
    TLSEXT_IDX_early_data,
781
    TLSEXT_IDX_certificate_authorities,
782
    TLSEXT_IDX_padding,
783
    TLSEXT_IDX_psk,
784
    /* Dummy index - must always be the last entry */
785
    TLSEXT_IDX_num_builtins
786
} TLSEXT_INDEX;
787
788
DEFINE_LHASH_OF(SSL_SESSION);
789
/* Needed in ssl_cert.c */
790
DEFINE_LHASH_OF(X509_NAME);
791
792
10.6k
#define TLSEXT_KEYNAME_LENGTH 16
793
#define TLSEXT_TICK_KEY_LENGTH 32
794
795
typedef struct ssl_ctx_ext_secure_st {
796
    unsigned char tick_hmac_key[TLSEXT_TICK_KEY_LENGTH];
797
    unsigned char tick_aes_key[TLSEXT_TICK_KEY_LENGTH];
798
} SSL_CTX_EXT_SECURE;
799
800
/*
801
 * Helper function for HMAC
802
 * The structure should be considered opaque, it will change once the low
803
 * level deprecated calls are removed.  At that point it can be replaced
804
 * by EVP_MAC_CTX and most of the functions converted to macros or inlined
805
 * directly.
806
 */
807
typedef struct ssl_hmac_st {
808
    EVP_MAC_CTX *ctx;
809
#ifndef OPENSSL_NO_DEPRECATED_3_0
810
    HMAC_CTX *old_ctx;
811
#endif
812
} SSL_HMAC;
813
814
SSL_HMAC *ssl_hmac_new(const SSL_CTX *ctx);
815
void ssl_hmac_free(SSL_HMAC *ctx);
816
#ifndef OPENSSL_NO_DEPRECATED_3_0
817
HMAC_CTX *ssl_hmac_get0_HMAC_CTX(SSL_HMAC *ctx);
818
#endif
819
EVP_MAC_CTX *ssl_hmac_get0_EVP_MAC_CTX(SSL_HMAC *ctx);
820
int ssl_hmac_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
821
int ssl_hmac_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
822
int ssl_hmac_final(SSL_HMAC *ctx, unsigned char *md, size_t *len,
823
    size_t max_size);
824
size_t ssl_hmac_size(const SSL_HMAC *ctx);
825
826
int ssl_get_EC_curve_nid(const EVP_PKEY *pkey);
827
__owur int tls13_set_encoded_pub_key(EVP_PKEY *pkey,
828
    const unsigned char *enckey,
829
    size_t enckeylen);
830
831
typedef struct tls_group_info_st {
832
    char *tlsname; /* Curve Name as in TLS specs */
833
    char *realname; /* Curve Name according to provider */
834
    char *algorithm; /* Algorithm name to fetch */
835
    unsigned int secbits; /* Bits of security (from SP800-57) */
836
    uint16_t group_id; /* Group ID */
837
    int mintls; /* Minimum TLS version, -1 unsupported */
838
    int maxtls; /* Maximum TLS version (or 0 for undefined) */
839
    int mindtls; /* Minimum DTLS version, -1 unsupported */
840
    int maxdtls; /* Maximum DTLS version (or 0 for undefined) */
841
    char is_kem; /* Mode for this Group: 0 is KEX, 1 is KEM */
842
} TLS_GROUP_INFO;
843
844
/* flags values */
845
#define TLS_GROUP_TYPE 0x0000000FU /* Mask for group type */
846
#define TLS_GROUP_CURVE_PRIME 0x00000001U
847
#define TLS_GROUP_CURVE_CHAR2 0x00000002U
848
#define TLS_GROUP_CURVE_CUSTOM 0x00000004U
849
#define TLS_GROUP_FFDHE 0x00000008U
850
#define TLS_GROUP_ONLY_FOR_TLS1_3 0x00000010U
851
852
#define TLS_GROUP_FFDHE_FOR_TLS1_3 (TLS_GROUP_FFDHE | TLS_GROUP_ONLY_FOR_TLS1_3)
853
854
struct ssl_ctx_st {
855
    OSSL_LIB_CTX *libctx;
856
857
    const SSL_METHOD *method;
858
    STACK_OF(SSL_CIPHER) *cipher_list;
859
    /* same as above but sorted for lookup */
860
    STACK_OF(SSL_CIPHER) *cipher_list_by_id;
861
    /* TLSv1.3 specific ciphersuites */
862
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
863
    struct x509_store_st /* X509_STORE */ *cert_store;
864
    LHASH_OF(SSL_SESSION) *sessions;
865
    /*
866
     * Most session-ids that will be cached, default is
867
     * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
868
     */
869
    size_t session_cache_size;
870
    struct ssl_session_st *session_cache_head;
871
    struct ssl_session_st *session_cache_tail;
872
    /*
873
     * This can have one of 2 values, ored together, SSL_SESS_CACHE_CLIENT,
874
     * SSL_SESS_CACHE_SERVER, Default is SSL_SESSION_CACHE_SERVER, which
875
     * means only SSL_accept will cache SSL_SESSIONS.
876
     */
877
    uint32_t session_cache_mode;
878
    /*
879
     * If timeout is not 0, it is the default timeout value set when
880
     * SSL_new() is called.  This has been put in to make life easier to set
881
     * things up
882
     */
883
    long session_timeout;
884
    /*
885
     * If this callback is not null, it will be called each time a session id
886
     * is added to the cache.  If this function returns 1, it means that the
887
     * callback will do a SSL_SESSION_free() when it has finished using it.
888
     * Otherwise, on 0, it means the callback has finished with it. If
889
     * remove_session_cb is not null, it will be called when a session-id is
890
     * removed from the cache.  After the call, OpenSSL will
891
     * SSL_SESSION_free() it.
892
     */
893
    int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
894
    void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
895
    SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
896
        const unsigned char *data, int len,
897
        int *copy);
898
    struct {
899
        TSAN_QUALIFIER int sess_connect; /* SSL new conn - started */
900
        TSAN_QUALIFIER int sess_connect_renegotiate; /* SSL reneg - requested */
901
        TSAN_QUALIFIER int sess_connect_good; /* SSL new conne/reneg - finished */
902
        TSAN_QUALIFIER int sess_accept; /* SSL new accept - started */
903
        TSAN_QUALIFIER int sess_accept_renegotiate; /* SSL reneg - requested */
904
        TSAN_QUALIFIER int sess_accept_good; /* SSL accept/reneg - finished */
905
        TSAN_QUALIFIER int sess_miss; /* session lookup misses */
906
        TSAN_QUALIFIER int sess_timeout; /* reuse attempt on timeouted session */
907
        TSAN_QUALIFIER int sess_cache_full; /* session removed due to full cache */
908
        TSAN_QUALIFIER int sess_hit; /* session reuse actually done */
909
        TSAN_QUALIFIER int sess_cb_hit; /* session-id that was not in
910
                                         * the cache was passed back via
911
                                         * the callback. This indicates
912
                                         * that the application is
913
                                         * supplying session-id's from
914
                                         * other processes - spooky
915
                                         * :-) */
916
    } stats;
917
#ifdef TSAN_REQUIRES_LOCKING
918
    CRYPTO_RWLOCK *tsan_lock;
919
#endif
920
921
    CRYPTO_REF_COUNT references;
922
923
    /* if defined, these override the X509_verify_cert() calls */
924
    int (*app_verify_callback)(X509_STORE_CTX *, void *);
925
    void *app_verify_arg;
926
    /*
927
     * before OpenSSL 0.9.7, 'app_verify_arg' was ignored
928
     * ('app_verify_callback' was called with just one argument)
929
     */
930
931
    /* Default password callback. */
932
    pem_password_cb *default_passwd_callback;
933
934
    /* Default password callback user data. */
935
    void *default_passwd_callback_userdata;
936
937
    /* get client cert callback */
938
    int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
939
940
    /* cookie generate callback */
941
    int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
942
        unsigned int *cookie_len);
943
944
    /* verify cookie callback */
945
    int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie,
946
        unsigned int cookie_len);
947
948
    /* TLS1.3 app-controlled cookie generate callback */
949
    int (*gen_stateless_cookie_cb)(SSL *ssl, unsigned char *cookie,
950
        size_t *cookie_len);
951
952
    /* TLS1.3 verify app-controlled cookie callback */
953
    int (*verify_stateless_cookie_cb)(SSL *ssl, const unsigned char *cookie,
954
        size_t cookie_len);
955
956
    CRYPTO_EX_DATA ex_data;
957
958
    const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
959
    const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3-sha1' */
960
961
    STACK_OF(X509) *extra_certs;
962
    STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
963
964
    /* Default values used when no per-SSL value is defined follow */
965
966
    /* used if SSL's info_callback is NULL */
967
    void (*info_callback)(const SSL *ssl, int type, int val);
968
969
    /*
970
     * What we put in certificate_authorities extension for TLS 1.3
971
     * (ClientHello and CertificateRequest) or just client cert requests for
972
     * earlier versions. If client_ca_names is populated then it is only used
973
     * for client cert requests, and in preference to ca_names.
974
     */
975
    STACK_OF(X509_NAME) *ca_names;
976
    STACK_OF(X509_NAME) *client_ca_names;
977
978
    /*
979
     * Default values to use in SSL structures follow (these are copied by
980
     * SSL_new)
981
     */
982
983
    uint64_t options;
984
    uint32_t mode;
985
    int min_proto_version;
986
    int max_proto_version;
987
    size_t max_cert_list;
988
989
    struct cert_st /* CERT */ *cert;
990
    int read_ahead;
991
992
    /* callback that allows applications to peek at protocol messages */
993
    void (*msg_callback)(int write_p, int version, int content_type,
994
        const void *buf, size_t len, SSL *ssl, void *arg);
995
    void *msg_callback_arg;
996
997
    uint32_t verify_mode;
998
    size_t sid_ctx_length;
999
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1000
    /* called 'verify_callback' in the SSL */
1001
    int (*default_verify_callback)(int ok, X509_STORE_CTX *ctx);
1002
1003
    /* Default generate session ID callback. */
1004
    GEN_SESSION_CB generate_session_id;
1005
1006
    X509_VERIFY_PARAM *param;
1007
1008
    int quiet_shutdown;
1009
1010
#ifndef OPENSSL_NO_CT
1011
    CTLOG_STORE *ctlog_store; /* CT Log Store */
1012
    /*
1013
     * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
1014
     * If they are not, the connection should be aborted.
1015
     */
1016
    ssl_ct_validation_cb ct_validation_callback;
1017
    void *ct_validation_callback_arg;
1018
#endif
1019
1020
    /*
1021
     * If we're using more than one pipeline how should we divide the data
1022
     * up between the pipes?
1023
     */
1024
    size_t split_send_fragment;
1025
    /*
1026
     * Maximum amount of data to send in one fragment. actual record size can
1027
     * be more than this due to padding and MAC overheads.
1028
     */
1029
    size_t max_send_fragment;
1030
1031
    /* Up to how many pipelines should we use? If 0 then 1 is assumed */
1032
    size_t max_pipelines;
1033
1034
    /* The default read buffer length to use (0 means not set) */
1035
    size_t default_read_buf_len;
1036
1037
#ifndef OPENSSL_NO_ENGINE
1038
    /*
1039
     * Engine to pass requests for client certs to
1040
     */
1041
    ENGINE *client_cert_engine;
1042
#endif
1043
1044
    /* ClientHello callback.  Mostly for extensions, but not entirely. */
1045
    SSL_client_hello_cb_fn client_hello_cb;
1046
    void *client_hello_cb_arg;
1047
1048
    /* TLS extensions. */
1049
    struct {
1050
        /* TLS extensions servername callback */
1051
        int (*servername_cb)(SSL *, int *, void *);
1052
        void *servername_arg;
1053
        /* RFC 4507 session ticket keys */
1054
        unsigned char tick_key_name[TLSEXT_KEYNAME_LENGTH];
1055
        SSL_CTX_EXT_SECURE *secure;
1056
#ifndef OPENSSL_NO_DEPRECATED_3_0
1057
        /* Callback to support customisation of ticket key setting */
1058
        int (*ticket_key_cb)(SSL *ssl,
1059
            unsigned char *name, unsigned char *iv,
1060
            EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
1061
#endif
1062
        int (*ticket_key_evp_cb)(SSL *ssl,
1063
            unsigned char *name, unsigned char *iv,
1064
            EVP_CIPHER_CTX *ectx, EVP_MAC_CTX *hctx,
1065
            int enc);
1066
1067
        /* certificate status request info */
1068
        /* Callback for status request */
1069
        int (*status_cb)(SSL *ssl, void *arg);
1070
        void *status_arg;
1071
        /* ext status type used for CSR extension (OCSP Stapling) */
1072
        int status_type;
1073
        /* RFC 4366 Maximum Fragment Length Negotiation */
1074
        uint8_t max_fragment_len_mode;
1075
1076
        /* EC extension values inherited by SSL structure */
1077
        size_t ecpointformats_len;
1078
        unsigned char *ecpointformats;
1079
1080
        size_t supportedgroups_len;
1081
        uint16_t *supportedgroups;
1082
1083
        uint16_t *supported_groups_default;
1084
        size_t supported_groups_default_len;
1085
        /*
1086
         * ALPN information (we are in the process of transitioning from NPN to
1087
         * ALPN.)
1088
         */
1089
1090
        /*-
1091
         * For a server, this contains a callback function that allows the
1092
         * server to select the protocol for the connection.
1093
         *   out: on successful return, this must point to the raw protocol
1094
         *        name (without the length prefix).
1095
         *   outlen: on successful return, this contains the length of |*out|.
1096
         *   in: points to the client's list of supported protocols in
1097
         *       wire-format.
1098
         *   inlen: the length of |in|.
1099
         */
1100
        int (*alpn_select_cb)(SSL *s,
1101
            const unsigned char **out,
1102
            unsigned char *outlen,
1103
            const unsigned char *in,
1104
            unsigned int inlen, void *arg);
1105
        void *alpn_select_cb_arg;
1106
1107
        /*
1108
         * For a client, this contains the list of supported protocols in wire
1109
         * format.
1110
         */
1111
        unsigned char *alpn;
1112
        size_t alpn_len;
1113
1114
#ifndef OPENSSL_NO_NEXTPROTONEG
1115
        /* Next protocol negotiation information */
1116
1117
        /*
1118
         * For a server, this contains a callback function by which the set of
1119
         * advertised protocols can be provided.
1120
         */
1121
        SSL_CTX_npn_advertised_cb_func npn_advertised_cb;
1122
        void *npn_advertised_cb_arg;
1123
        /*
1124
         * For a client, this contains a callback function that selects the next
1125
         * protocol from the list provided by the server.
1126
         */
1127
        SSL_CTX_npn_select_cb_func npn_select_cb;
1128
        void *npn_select_cb_arg;
1129
#endif
1130
1131
        unsigned char cookie_hmac_key[SHA256_DIGEST_LENGTH];
1132
    } ext;
1133
1134
#ifndef OPENSSL_NO_PSK
1135
    SSL_psk_client_cb_func psk_client_callback;
1136
    SSL_psk_server_cb_func psk_server_callback;
1137
#endif
1138
    SSL_psk_find_session_cb_func psk_find_session_cb;
1139
    SSL_psk_use_session_cb_func psk_use_session_cb;
1140
1141
#ifndef OPENSSL_NO_SRP
1142
    SRP_CTX srp_ctx; /* ctx for SRP authentication */
1143
#endif
1144
1145
    /* Shared DANE context */
1146
    struct dane_ctx_st dane;
1147
1148
#ifndef OPENSSL_NO_SRTP
1149
    /* SRTP profiles we are willing to do from RFC 5764 */
1150
    STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
1151
#endif
1152
    /*
1153
     * Callback for disabling session caching and ticket support on a session
1154
     * basis, depending on the chosen cipher.
1155
     */
1156
    int (*not_resumable_session_cb)(SSL *ssl, int is_forward_secure);
1157
1158
    CRYPTO_RWLOCK *lock;
1159
1160
    /*
1161
     * Callback for logging key material for use with debugging tools like
1162
     * Wireshark. The callback should log `line` followed by a newline.
1163
     */
1164
    SSL_CTX_keylog_cb_func keylog_callback;
1165
1166
    /*
1167
     * The maximum number of bytes advertised in session tickets that can be
1168
     * sent as early data.
1169
     */
1170
    uint32_t max_early_data;
1171
1172
    /*
1173
     * The maximum number of bytes of early data that a server will tolerate
1174
     * (which should be at least as much as max_early_data).
1175
     */
1176
    uint32_t recv_max_early_data;
1177
1178
    /* TLS1.3 padding callback */
1179
    size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
1180
    void *record_padding_arg;
1181
    size_t block_padding;
1182
1183
    /* Session ticket appdata */
1184
    SSL_CTX_generate_session_ticket_fn generate_ticket_cb;
1185
    SSL_CTX_decrypt_session_ticket_fn decrypt_ticket_cb;
1186
    void *ticket_cb_data;
1187
1188
    /* The number of TLS1.3 tickets to automatically send */
1189
    size_t num_tickets;
1190
1191
    /* Callback to determine if early_data is acceptable or not */
1192
    SSL_allow_early_data_cb_fn allow_early_data_cb;
1193
    void *allow_early_data_cb_data;
1194
1195
    /* Do we advertise Post-handshake auth support? */
1196
    int pha_enabled;
1197
1198
    /* Callback for SSL async handling */
1199
    SSL_async_callback_fn async_cb;
1200
    void *async_cb_arg;
1201
1202
    char *propq;
1203
1204
    int ssl_mac_pkey_id[SSL_MD_NUM_IDX];
1205
    const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX];
1206
    const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX];
1207
    size_t ssl_mac_secret_size[SSL_MD_NUM_IDX];
1208
1209
    /* Cache of all sigalgs we know and whether they are available or not */
1210
    struct sigalg_lookup_st *sigalg_lookup_cache;
1211
1212
    TLS_GROUP_INFO *group_list;
1213
    size_t group_list_len;
1214
    size_t group_list_max_len;
1215
1216
    /* masks of disabled algorithms */
1217
    uint32_t disabled_enc_mask;
1218
    uint32_t disabled_mac_mask;
1219
    uint32_t disabled_mkey_mask;
1220
    uint32_t disabled_auth_mask;
1221
};
1222
1223
typedef struct cert_pkey_st CERT_PKEY;
1224
1225
struct ssl_st {
1226
    /*
1227
     * protocol version (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION,
1228
     * DTLS1_VERSION)
1229
     */
1230
    int version;
1231
    /* SSLv3 */
1232
    const SSL_METHOD *method;
1233
    /*
1234
     * There are 2 BIO's even though they are normally both the same.  This
1235
     * is so data can be read and written to different handlers
1236
     */
1237
    /* used by SSL_read */
1238
    BIO *rbio;
1239
    /* used by SSL_write */
1240
    BIO *wbio;
1241
    /* used during session-id reuse to concatenate messages */
1242
    BIO *bbio;
1243
    /*
1244
     * This holds a variable that indicates what we were doing when a 0 or -1
1245
     * is returned.  This is needed for non-blocking IO so we know what
1246
     * request needs re-doing when in SSL_accept or SSL_connect
1247
     */
1248
    int rwstate;
1249
    int (*handshake_func)(SSL *);
1250
    /*
1251
     * Imagine that here's a boolean member "init" that is switched as soon
1252
     * as SSL_set_{accept/connect}_state is called for the first time, so
1253
     * that "state" and "handshake_func" are properly initialized.  But as
1254
     * handshake_func is == 0 until then, we use this test instead of an
1255
     * "init" member.
1256
     */
1257
    /* are we the server side? */
1258
    int server;
1259
    /*
1260
     * Generate a new session or reuse an old one.
1261
     * NB: For servers, the 'new' session may actually be a previously
1262
     * cached session or even the previous session unless
1263
     * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set
1264
     */
1265
    int new_session;
1266
    /* don't send shutdown packets */
1267
    int quiet_shutdown;
1268
    /* we have shut things down, 0x01 sent, 0x02 for received */
1269
    int shutdown;
1270
    /* where we are */
1271
    OSSL_STATEM statem;
1272
    SSL_EARLY_DATA_STATE early_data_state;
1273
    BUF_MEM *init_buf; /* buffer used during init */
1274
    void *init_msg; /* pointer to handshake message body, set by
1275
                     * ssl3_get_message() */
1276
    size_t init_num; /* amount read/written */
1277
    size_t init_off; /* amount read/written */
1278
1279
    struct {
1280
        long flags;
1281
        size_t read_mac_secret_size;
1282
        unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
1283
        size_t write_mac_secret_size;
1284
        unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
1285
        unsigned char server_random[SSL3_RANDOM_SIZE];
1286
        unsigned char client_random[SSL3_RANDOM_SIZE];
1287
        /* flags for countermeasure against known-IV weakness */
1288
        int need_empty_fragments;
1289
        int empty_fragment_done;
1290
        /* used during startup, digest all incoming/outgoing packets */
1291
        BIO *handshake_buffer;
1292
        /*
1293
         * When handshake digest is determined, buffer is hashed and
1294
         * freed and MD_CTX for the required digest is stored here.
1295
         */
1296
        EVP_MD_CTX *handshake_dgst;
1297
        /*
1298
         * Set whenever an expected ChangeCipherSpec message is processed.
1299
         * Unset when the peer's Finished message is received.
1300
         * Unexpected ChangeCipherSpec messages trigger a fatal alert.
1301
         */
1302
        int change_cipher_spec;
1303
        int warn_alert;
1304
        int fatal_alert;
1305
        /*
1306
         * we allow one fatal and one warning alert to be outstanding, send close
1307
         * alert via the warning alert
1308
         */
1309
        int alert_dispatch;
1310
        unsigned char send_alert[2];
1311
        /*
1312
         * This flag is set when we should renegotiate ASAP, basically when there
1313
         * is no more data in the read or write buffers
1314
         */
1315
        int renegotiate;
1316
        int total_renegotiations;
1317
        int num_renegotiations;
1318
        int in_read_app_data;
1319
        struct {
1320
            /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
1321
            unsigned char finish_md[EVP_MAX_MD_SIZE * 2];
1322
            size_t finish_md_len;
1323
            unsigned char peer_finish_md[EVP_MAX_MD_SIZE * 2];
1324
            size_t peer_finish_md_len;
1325
            size_t message_size;
1326
            int message_type;
1327
            /* used to hold the new cipher we are going to use */
1328
            const SSL_CIPHER *new_cipher;
1329
            EVP_PKEY *pkey; /* holds short lived key exchange key */
1330
            /* used for certificate requests */
1331
            int cert_req;
1332
            /* Certificate types in certificate request message. */
1333
            uint8_t *ctype;
1334
            size_t ctype_len;
1335
            /* Certificate authorities list peer sent */
1336
            STACK_OF(X509_NAME) *peer_ca_names;
1337
            size_t key_block_length;
1338
            unsigned char *key_block;
1339
            const EVP_CIPHER *new_sym_enc;
1340
            const EVP_MD *new_hash;
1341
            int new_mac_pkey_type;
1342
            size_t new_mac_secret_size;
1343
#ifndef OPENSSL_NO_COMP
1344
            const SSL_COMP *new_compression;
1345
#else
1346
            char *new_compression;
1347
#endif
1348
            int cert_request;
1349
            /* Raw values of the cipher list from a client */
1350
            unsigned char *ciphers_raw;
1351
            size_t ciphers_rawlen;
1352
            /* Temporary storage for premaster secret */
1353
            unsigned char *pms;
1354
            size_t pmslen;
1355
#ifndef OPENSSL_NO_PSK
1356
            /* Temporary storage for PSK key */
1357
            unsigned char *psk;
1358
            size_t psklen;
1359
#endif
1360
            /* Signature algorithm we actually use */
1361
            const struct sigalg_lookup_st *sigalg;
1362
            /* Pointer to certificate we use */
1363
            CERT_PKEY *cert;
1364
            /*
1365
             * signature algorithms peer reports: e.g. supported signature
1366
             * algorithms extension for server or as part of a certificate
1367
             * request for client.
1368
             * Keep track of the algorithms for TLS and X.509 usage separately.
1369
             */
1370
            uint16_t *peer_sigalgs;
1371
            uint16_t *peer_cert_sigalgs;
1372
            /* Size of above arrays */
1373
            size_t peer_sigalgslen;
1374
            size_t peer_cert_sigalgslen;
1375
            /* Sigalg peer actually uses */
1376
            const struct sigalg_lookup_st *peer_sigalg;
1377
            /*
1378
             * Set if corresponding CERT_PKEY can be used with current
1379
             * SSL session: e.g. appropriate curve, signature algorithms etc.
1380
             * If zero it can't be used at all.
1381
             */
1382
            uint32_t valid_flags[SSL_PKEY_NUM];
1383
            /*
1384
             * For servers the following masks are for the key and auth algorithms
1385
             * that are supported by the certs below. For clients they are masks of
1386
             * *disabled* algorithms based on the current session.
1387
             */
1388
            uint32_t mask_k;
1389
            uint32_t mask_a;
1390
            /*
1391
             * The following are used by the client to see if a cipher is allowed or
1392
             * not.  It contains the minimum and maximum version the client's using
1393
             * based on what it knows so far.
1394
             */
1395
            int min_ver;
1396
            int max_ver;
1397
        } tmp;
1398
1399
        /* Connection binding to prevent renegotiation attacks */
1400
        unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1401
        size_t previous_client_finished_len;
1402
        unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1403
        size_t previous_server_finished_len;
1404
        int send_connection_binding;
1405
1406
#ifndef OPENSSL_NO_NEXTPROTONEG
1407
        /*
1408
         * Set if we saw the Next Protocol Negotiation extension from our peer.
1409
         */
1410
        int npn_seen;
1411
#endif
1412
1413
        /*
1414
         * ALPN information (we are in the process of transitioning from NPN to
1415
         * ALPN.)
1416
         */
1417
1418
        /*
1419
         * In a server these point to the selected ALPN protocol after the
1420
         * ClientHello has been processed. In a client these contain the protocol
1421
         * that the server selected once the ServerHello has been processed.
1422
         */
1423
        unsigned char *alpn_selected;
1424
        size_t alpn_selected_len;
1425
        /* used by the server to know what options were proposed */
1426
        unsigned char *alpn_proposed;
1427
        size_t alpn_proposed_len;
1428
        /* used by the client to know if it actually sent alpn */
1429
        int alpn_sent;
1430
1431
        /*
1432
         * This is set to true if we believe that this is a version of Safari
1433
         * running on OS X 10.6 or newer. We wish to know this because Safari on
1434
         * 10.8 .. 10.8.3 has broken ECDHE-ECDSA support.
1435
         */
1436
        char is_probably_safari;
1437
1438
        /*
1439
         * Track whether we did a key exchange this handshake or not, so
1440
         * SSL_get_negotiated_group() knows whether to fall back to the
1441
         * value in the SSL_SESSION.
1442
         */
1443
        char did_kex;
1444
        /* For clients: peer temporary key */
1445
        /* The group_id for the key exchange key */
1446
        uint16_t group_id;
1447
        EVP_PKEY *peer_tmp;
1448
1449
    } s3;
1450
1451
    struct dtls1_state_st *d1; /* DTLSv1 variables */
1452
    /* callback that allows applications to peek at protocol messages */
1453
    void (*msg_callback)(int write_p, int version, int content_type,
1454
        const void *buf, size_t len, SSL *ssl, void *arg);
1455
    void *msg_callback_arg;
1456
    int hit; /* reusing a previous session */
1457
    X509_VERIFY_PARAM *param;
1458
    /* Per connection DANE state */
1459
    SSL_DANE dane;
1460
    /* crypto */
1461
    STACK_OF(SSL_CIPHER) *peer_ciphers;
1462
    STACK_OF(SSL_CIPHER) *cipher_list;
1463
    STACK_OF(SSL_CIPHER) *cipher_list_by_id;
1464
    /* TLSv1.3 specific ciphersuites */
1465
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites;
1466
    /*
1467
     * These are the ones being used, the ones in SSL_SESSION are the ones to
1468
     * be 'copied' into these ones
1469
     */
1470
    uint32_t mac_flags;
1471
    /*
1472
     * The TLS1.3 secrets.
1473
     */
1474
    unsigned char early_secret[EVP_MAX_MD_SIZE];
1475
    unsigned char handshake_secret[EVP_MAX_MD_SIZE];
1476
    unsigned char master_secret[EVP_MAX_MD_SIZE];
1477
    unsigned char resumption_master_secret[EVP_MAX_MD_SIZE];
1478
    unsigned char client_finished_secret[EVP_MAX_MD_SIZE];
1479
    unsigned char server_finished_secret[EVP_MAX_MD_SIZE];
1480
    unsigned char server_finished_hash[EVP_MAX_MD_SIZE];
1481
    unsigned char handshake_traffic_hash[EVP_MAX_MD_SIZE];
1482
    unsigned char client_app_traffic_secret[EVP_MAX_MD_SIZE];
1483
    unsigned char server_app_traffic_secret[EVP_MAX_MD_SIZE];
1484
    unsigned char exporter_master_secret[EVP_MAX_MD_SIZE];
1485
    unsigned char early_exporter_master_secret[EVP_MAX_MD_SIZE];
1486
    EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
1487
    unsigned char read_iv[EVP_MAX_IV_LENGTH]; /* TLSv1.3 static read IV */
1488
    EVP_MD_CTX *read_hash; /* used for mac generation */
1489
    COMP_CTX *compress; /* compression */
1490
    COMP_CTX *expand; /* uncompress */
1491
    EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
1492
    unsigned char write_iv[EVP_MAX_IV_LENGTH]; /* TLSv1.3 static write IV */
1493
    EVP_MD_CTX *write_hash; /* used for mac generation */
1494
    /* session info */
1495
    /* client cert? */
1496
    /* This is used to hold the server certificate used */
1497
    struct cert_st /* CERT */ *cert;
1498
1499
    /*
1500
     * The hash of all messages prior to the CertificateVerify, and the length
1501
     * of that hash.
1502
     */
1503
    unsigned char cert_verify_hash[EVP_MAX_MD_SIZE];
1504
    size_t cert_verify_hash_len;
1505
1506
    /* Flag to indicate whether we should send a HelloRetryRequest or not */
1507
    enum { SSL_HRR_NONE = 0,
1508
        SSL_HRR_PENDING,
1509
        SSL_HRR_COMPLETE } hello_retry_request;
1510
1511
    /*
1512
     * the session_id_context is used to ensure sessions are only reused in
1513
     * the appropriate context
1514
     */
1515
    size_t sid_ctx_length;
1516
    unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1517
    /* This can also be in the session once a session is established */
1518
    SSL_SESSION *session;
1519
    /* TLSv1.3 PSK session */
1520
    SSL_SESSION *psksession;
1521
    unsigned char *psksession_id;
1522
    size_t psksession_id_len;
1523
    /* Default generate session ID callback. */
1524
    GEN_SESSION_CB generate_session_id;
1525
    /*
1526
     * The temporary TLSv1.3 session id. This isn't really a session id at all
1527
     * but is a random value sent in the legacy session id field.
1528
     */
1529
    unsigned char tmp_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
1530
    size_t tmp_session_id_len;
1531
    /* Used in SSL3 */
1532
    /*
1533
     * 0 don't care about verify failure.
1534
     * 1 fail if verify fails
1535
     */
1536
    uint32_t verify_mode;
1537
    /* fail if callback returns 0 */
1538
    int (*verify_callback)(int ok, X509_STORE_CTX *ctx);
1539
    /* optional informational callback */
1540
    void (*info_callback)(const SSL *ssl, int type, int val);
1541
    /* error bytes to be written */
1542
    int error;
1543
    /* actual code */
1544
    int error_code;
1545
#ifndef OPENSSL_NO_PSK
1546
    SSL_psk_client_cb_func psk_client_callback;
1547
    SSL_psk_server_cb_func psk_server_callback;
1548
#endif
1549
    SSL_psk_find_session_cb_func psk_find_session_cb;
1550
    SSL_psk_use_session_cb_func psk_use_session_cb;
1551
1552
    SSL_CTX *ctx;
1553
    /* Verified chain of peer */
1554
    STACK_OF(X509) *verified_chain;
1555
    long verify_result;
1556
    /* extra application data */
1557
    CRYPTO_EX_DATA ex_data;
1558
    /*
1559
     * What we put in certificate_authorities extension for TLS 1.3
1560
     * (ClientHello and CertificateRequest) or just client cert requests for
1561
     * earlier versions. If client_ca_names is populated then it is only used
1562
     * for client cert requests, and in preference to ca_names.
1563
     */
1564
    STACK_OF(X509_NAME) *ca_names;
1565
    STACK_OF(X509_NAME) *client_ca_names;
1566
    CRYPTO_REF_COUNT references;
1567
    /* protocol behaviour */
1568
    uint64_t options;
1569
    /* API behaviour */
1570
    uint32_t mode;
1571
    int min_proto_version;
1572
    int max_proto_version;
1573
    size_t max_cert_list;
1574
    int first_packet;
1575
    /*
1576
     * What was passed in ClientHello.legacy_version. Used for RSA pre-master
1577
     * secret and SSLv3/TLS (<=1.2) rollback check
1578
     */
1579
    int client_version;
1580
    /*
1581
     * If we're using more than one pipeline how should we divide the data
1582
     * up between the pipes?
1583
     */
1584
    size_t split_send_fragment;
1585
    /*
1586
     * Maximum amount of data to send in one fragment. actual record size can
1587
     * be more than this due to padding and MAC overheads.
1588
     */
1589
    size_t max_send_fragment;
1590
    /* Up to how many pipelines should we use? If 0 then 1 is assumed */
1591
    size_t max_pipelines;
1592
1593
    struct {
1594
        /* Built-in extension flags */
1595
        uint8_t extflags[TLSEXT_IDX_num_builtins];
1596
        /* TLS extension debug callback */
1597
        void (*debug_cb)(SSL *s, int client_server, int type,
1598
            const unsigned char *data, int len, void *arg);
1599
        void *debug_arg;
1600
        char *hostname;
1601
        /* certificate status request info */
1602
        /* Status type or -1 if no status type */
1603
        int status_type;
1604
        /* Raw extension data, if seen */
1605
        unsigned char *scts;
1606
        /* Length of raw extension data, if seen */
1607
        uint16_t scts_len;
1608
        /* Expect OCSP CertificateStatus message */
1609
        int status_expected;
1610
1611
        struct {
1612
            /* OCSP status request only */
1613
            STACK_OF(OCSP_RESPID) *ids;
1614
            X509_EXTENSIONS *exts;
1615
            /* OCSP response received or to be sent */
1616
            unsigned char *resp;
1617
            size_t resp_len;
1618
        } ocsp;
1619
1620
        /* RFC4507 session ticket expected to be received or sent */
1621
        int ticket_expected;
1622
        /* TLS 1.3 tickets requested by the application. */
1623
        int extra_tickets_expected;
1624
        size_t ecpointformats_len;
1625
        /* our list */
1626
        unsigned char *ecpointformats;
1627
1628
        size_t peer_ecpointformats_len;
1629
        /* peer's list */
1630
        unsigned char *peer_ecpointformats;
1631
        size_t supportedgroups_len;
1632
        /* our list */
1633
        uint16_t *supportedgroups;
1634
1635
        size_t peer_supportedgroups_len;
1636
        /* peer's list */
1637
        uint16_t *peer_supportedgroups;
1638
1639
        /* TLS Session Ticket extension override */
1640
        TLS_SESSION_TICKET_EXT *session_ticket;
1641
        /* TLS Session Ticket extension callback */
1642
        tls_session_ticket_ext_cb_fn session_ticket_cb;
1643
        void *session_ticket_cb_arg;
1644
        /* TLS pre-shared secret session resumption */
1645
        tls_session_secret_cb_fn session_secret_cb;
1646
        void *session_secret_cb_arg;
1647
        /*
1648
         * For a client, this contains the list of supported protocols in wire
1649
         * format.
1650
         */
1651
        unsigned char *alpn;
1652
        size_t alpn_len;
1653
        /*
1654
         * Next protocol negotiation. For the client, this is the protocol that
1655
         * we sent in NextProtocol and is set when handling ServerHello
1656
         * extensions. For a server, this is the client's selected_protocol from
1657
         * NextProtocol and is set when handling the NextProtocol message, before
1658
         * the Finished message.
1659
         */
1660
        unsigned char *npn;
1661
        size_t npn_len;
1662
1663
        /* The available PSK key exchange modes */
1664
        int psk_kex_mode;
1665
1666
        /* Set to one if we have negotiated ETM */
1667
        int use_etm;
1668
1669
        /* Are we expecting to receive early data? */
1670
        int early_data;
1671
        /* Is the session suitable for early data? */
1672
        int early_data_ok;
1673
1674
        /* May be sent by a server in HRR. Must be echoed back in ClientHello */
1675
        unsigned char *tls13_cookie;
1676
        size_t tls13_cookie_len;
1677
        /* Have we received a cookie from the client? */
1678
        int cookieok;
1679
1680
        /*
1681
         * Maximum Fragment Length as per RFC 4366.
1682
         * If this member contains one of the allowed values (1-4)
1683
         * then we should include Maximum Fragment Length Negotiation
1684
         * extension in Client Hello.
1685
         * Please note that value of this member does not have direct
1686
         * effect. The actual (binding) value is stored in SSL_SESSION,
1687
         * as this extension is optional on server side.
1688
         */
1689
        uint8_t max_fragment_len_mode;
1690
1691
        /*
1692
         * On the client side the number of ticket identities we sent in the
1693
         * ClientHello. On the server side the identity of the ticket we
1694
         * selected.
1695
         */
1696
        int tick_identity;
1697
    } ext;
1698
1699
    /*
1700
     * Parsed form of the ClientHello, kept around across client_hello_cb
1701
     * calls.
1702
     */
1703
    CLIENTHELLO_MSG *clienthello;
1704
1705
    /*-
1706
     * no further mod of servername
1707
     * 0 : call the servername extension callback.
1708
     * 1 : prepare 2, allow last ack just after in server callback.
1709
     * 2 : don't call servername callback, no ack in server hello
1710
     */
1711
    int servername_done;
1712
#ifndef OPENSSL_NO_CT
1713
    /*
1714
     * Validates that the SCTs (Signed Certificate Timestamps) are sufficient.
1715
     * If they are not, the connection should be aborted.
1716
     */
1717
    ssl_ct_validation_cb ct_validation_callback;
1718
    /* User-supplied argument that is passed to the ct_validation_callback */
1719
    void *ct_validation_callback_arg;
1720
    /*
1721
     * Consolidated stack of SCTs from all sources.
1722
     * Lazily populated by CT_get_peer_scts(SSL*)
1723
     */
1724
    STACK_OF(SCT) *scts;
1725
    /* Have we attempted to find/parse SCTs yet? */
1726
    int scts_parsed;
1727
#endif
1728
    SSL_CTX *session_ctx; /* initial ctx, used to store sessions */
1729
#ifndef OPENSSL_NO_SRTP
1730
    /* What we'll do */
1731
    STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
1732
    /* What's been chosen */
1733
    SRTP_PROTECTION_PROFILE *srtp_profile;
1734
#endif
1735
    /*-
1736
     * 1 if we are renegotiating.
1737
     * 2 if we are a server and are inside a handshake
1738
     * (i.e. not just sending a HelloRequest)
1739
     */
1740
    int renegotiate;
1741
    /* If sending a KeyUpdate is pending */
1742
    int key_update;
1743
    /* Post-handshake authentication state */
1744
    SSL_PHA_STATE post_handshake_auth;
1745
    int pha_enabled;
1746
    uint8_t *pha_context;
1747
    size_t pha_context_len;
1748
    int certreqs_sent;
1749
    EVP_MD_CTX *pha_dgst; /* this is just the digest through ClientFinished */
1750
1751
#ifndef OPENSSL_NO_SRP
1752
    /* ctx for SRP authentication */
1753
    SRP_CTX srp_ctx;
1754
#endif
1755
    /*
1756
     * Callback for disabling session caching and ticket support on a session
1757
     * basis, depending on the chosen cipher.
1758
     */
1759
    int (*not_resumable_session_cb)(SSL *ssl, int is_forward_secure);
1760
    RECORD_LAYER rlayer;
1761
    /* Default password callback. */
1762
    pem_password_cb *default_passwd_callback;
1763
    /* Default password callback user data. */
1764
    void *default_passwd_callback_userdata;
1765
    /* Async Job info */
1766
    ASYNC_JOB *job;
1767
    ASYNC_WAIT_CTX *waitctx;
1768
    size_t asyncrw;
1769
1770
    /*
1771
     * The maximum number of bytes advertised in session tickets that can be
1772
     * sent as early data.
1773
     */
1774
    uint32_t max_early_data;
1775
    /*
1776
     * The maximum number of bytes of early data that a server will tolerate
1777
     * (which should be at least as much as max_early_data).
1778
     */
1779
    uint32_t recv_max_early_data;
1780
1781
    /*
1782
     * The number of bytes of early data received so far. If we accepted early
1783
     * data then this is a count of the plaintext bytes. If we rejected it then
1784
     * this is a count of the ciphertext bytes.
1785
     */
1786
    uint32_t early_data_count;
1787
1788
    /* TLS1.3 padding callback */
1789
    size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
1790
    void *record_padding_arg;
1791
    size_t block_padding;
1792
1793
    CRYPTO_RWLOCK *lock;
1794
1795
    /* The number of TLS1.3 tickets to automatically send */
1796
    size_t num_tickets;
1797
    /* The number of TLS1.3 tickets actually sent so far */
1798
    size_t sent_tickets;
1799
    /* The next nonce value to use when we send a ticket on this connection */
1800
    uint64_t next_ticket_nonce;
1801
1802
    /* Callback to determine if early_data is acceptable or not */
1803
    SSL_allow_early_data_cb_fn allow_early_data_cb;
1804
    void *allow_early_data_cb_data;
1805
1806
    /* Callback for SSL async handling */
1807
    SSL_async_callback_fn async_cb;
1808
    void *async_cb_arg;
1809
1810
    /*
1811
     * Signature algorithms shared by client and server: cached because these
1812
     * are used most often.
1813
     */
1814
    const struct sigalg_lookup_st **shared_sigalgs;
1815
    size_t shared_sigalgslen;
1816
};
1817
1818
/*
1819
 * Structure containing table entry of values associated with the signature
1820
 * algorithms (signature scheme) extension
1821
 */
1822
typedef struct sigalg_lookup_st {
1823
    /* TLS 1.3 signature scheme name */
1824
    const char *name;
1825
    /* Raw value used in extension */
1826
    uint16_t sigalg;
1827
    /* NID of hash algorithm or NID_undef if no hash */
1828
    int hash;
1829
    /* Index of hash algorithm or -1 if no hash algorithm */
1830
    int hash_idx;
1831
    /* NID of signature algorithm */
1832
    int sig;
1833
    /* Index of signature algorithm */
1834
    int sig_idx;
1835
    /* Combined hash and signature NID, if any */
1836
    int sigandhash;
1837
    /* Required public key curve (ECDSA only) */
1838
    int curve;
1839
    /* Whether this signature algorithm is actually available for use */
1840
    int enabled;
1841
} SIGALG_LOOKUP;
1842
1843
/*
1844
 * Structure containing table entry of certificate info corresponding to
1845
 * CERT_PKEY entries
1846
 */
1847
typedef struct {
1848
    int nid; /* NID of public key algorithm */
1849
    uint32_t amask; /* authmask corresponding to key type */
1850
} SSL_CERT_LOOKUP;
1851
1852
/* DTLS structures */
1853
1854
#ifndef OPENSSL_NO_SCTP
1855
#define DTLS1_SCTP_AUTH_LABEL "EXPORTER_DTLS_OVER_SCTP"
1856
#endif
1857
1858
/* Max MTU overhead we know about so far is 40 for IPv6 + 8 for UDP */
1859
#define DTLS1_MAX_MTU_OVERHEAD 48
1860
1861
/*
1862
 * Flag used in message reuse to indicate the buffer contains the record
1863
 * header as well as the handshake message header.
1864
 */
1865
#define DTLS1_SKIP_RECORD_HEADER 2
1866
1867
struct dtls1_retransmit_state {
1868
    EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
1869
    EVP_MD_CTX *write_hash; /* used for mac generation */
1870
    COMP_CTX *compress; /* compression */
1871
    SSL_SESSION *session;
1872
    unsigned short epoch;
1873
};
1874
1875
struct hm_header_st {
1876
    unsigned char type;
1877
    size_t msg_len;
1878
    unsigned short seq;
1879
    size_t frag_off;
1880
    size_t frag_len;
1881
    unsigned int is_ccs;
1882
    struct dtls1_retransmit_state saved_retransmit_state;
1883
};
1884
1885
typedef struct hm_fragment_st {
1886
    struct hm_header_st msg_header;
1887
    unsigned char *fragment;
1888
    unsigned char *reassembly;
1889
} hm_fragment;
1890
1891
typedef struct pqueue_st pqueue;
1892
typedef struct pitem_st pitem;
1893
1894
struct pitem_st {
1895
    unsigned char priority[8]; /* 64-bit value in big-endian encoding */
1896
    void *data;
1897
    pitem *next;
1898
};
1899
1900
typedef struct pitem_st *piterator;
1901
1902
pitem *pitem_new(unsigned char *prio64be, void *data);
1903
void pitem_free(pitem *item);
1904
pqueue *pqueue_new(void);
1905
void pqueue_free(pqueue *pq);
1906
pitem *pqueue_insert(pqueue *pq, pitem *item);
1907
pitem *pqueue_peek(pqueue *pq);
1908
pitem *pqueue_pop(pqueue *pq);
1909
pitem *pqueue_find(pqueue *pq, unsigned char *prio64be);
1910
pitem *pqueue_iterator(pqueue *pq);
1911
pitem *pqueue_next(piterator *iter);
1912
size_t pqueue_size(pqueue *pq);
1913
1914
typedef struct dtls1_state_st {
1915
    unsigned char cookie[DTLS1_COOKIE_LENGTH];
1916
    size_t cookie_len;
1917
    unsigned int cookie_verified;
1918
    /* handshake message numbers */
1919
    unsigned short handshake_write_seq;
1920
    unsigned short next_handshake_write_seq;
1921
    unsigned short handshake_read_seq;
1922
    /* Buffered handshake messages */
1923
    pqueue *buffered_messages;
1924
    /* Buffered (sent) handshake records */
1925
    pqueue *sent_messages;
1926
    size_t link_mtu; /* max on-the-wire DTLS packet size */
1927
    size_t mtu; /* max DTLS packet size */
1928
    struct hm_header_st w_msg_hdr;
1929
    struct hm_header_st r_msg_hdr;
1930
    /* Number of alerts received so far */
1931
    unsigned int timeout_num_alerts;
1932
    /*
1933
     * Indicates when the last handshake msg sent will timeout
1934
     */
1935
    struct timeval next_timeout;
1936
    /* Timeout duration */
1937
    unsigned int timeout_duration_us;
1938
1939
    unsigned int retransmitting;
1940
#ifndef OPENSSL_NO_SCTP
1941
    int shutdown_received;
1942
#endif
1943
1944
    DTLS_timer_cb timer_cb;
1945
1946
} DTLS1_STATE;
1947
1948
/*
1949
 * From ECC-TLS draft, used in encoding the curve type in ECParameters
1950
 */
1951
#define EXPLICIT_PRIME_CURVE_TYPE 1
1952
#define EXPLICIT_CHAR2_CURVE_TYPE 2
1953
16.9k
#define NAMED_CURVE_TYPE 3
1954
1955
struct cert_pkey_st {
1956
    X509 *x509;
1957
    EVP_PKEY *privatekey;
1958
    /* Chain for this certificate */
1959
    STACK_OF(X509) *chain;
1960
    /*-
1961
     * serverinfo data for this certificate.  The data is in TLS Extension
1962
     * wire format, specifically it's a series of records like:
1963
     *   uint16_t extension_type; // (RFC 5246, 7.4.1.4, Extension)
1964
     *   uint16_t length;
1965
     *   uint8_t data[length];
1966
     */
1967
    unsigned char *serverinfo;
1968
    size_t serverinfo_length;
1969
};
1970
/* Retrieve Suite B flags */
1971
2.57M
#define tls1_suiteb(s) (s->cert->cert_flags & SSL_CERT_FLAG_SUITEB_128_LOS)
1972
/* Uses to check strict mode: suite B modes are always strict */
1973
#define SSL_CERT_FLAGS_CHECK_TLS_STRICT \
1974
21.2k
    (SSL_CERT_FLAG_SUITEB_128_LOS | SSL_CERT_FLAG_TLS_STRICT)
1975
1976
typedef enum {
1977
    ENDPOINT_CLIENT = 0,
1978
    ENDPOINT_SERVER,
1979
    ENDPOINT_BOTH
1980
} ENDPOINT;
1981
1982
typedef struct {
1983
    unsigned short ext_type;
1984
    ENDPOINT role;
1985
    /* The context which this extension applies to */
1986
    unsigned int context;
1987
    /*
1988
     * Per-connection flags relating to this extension type: not used if
1989
     * part of an SSL_CTX structure.
1990
     */
1991
    uint32_t ext_flags;
1992
    SSL_custom_ext_add_cb_ex add_cb;
1993
    SSL_custom_ext_free_cb_ex free_cb;
1994
    void *add_arg;
1995
    SSL_custom_ext_parse_cb_ex parse_cb;
1996
    void *parse_arg;
1997
} custom_ext_method;
1998
1999
/* ext_flags values */
2000
2001
/*
2002
 * Indicates an extension has been received. Used to check for unsolicited or
2003
 * duplicate extensions.
2004
 */
2005
0
#define SSL_EXT_FLAG_RECEIVED 0x1
2006
/*
2007
 * Indicates an extension has been sent: used to enable sending of
2008
 * corresponding ServerHello extension.
2009
 */
2010
178k
#define SSL_EXT_FLAG_SENT 0x2
2011
2012
typedef struct {
2013
    custom_ext_method *meths;
2014
    size_t meths_count;
2015
} custom_ext_methods;
2016
2017
typedef struct cert_st {
2018
    /* Current active set */
2019
    /*
2020
     * ALWAYS points to an element of the pkeys array
2021
     * Probably it would make more sense to store
2022
     * an index, not a pointer.
2023
     */
2024
    CERT_PKEY *key;
2025
2026
    EVP_PKEY *dh_tmp;
2027
    DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
2028
    int dh_tmp_auto;
2029
    /* Flags related to certificates */
2030
    uint32_t cert_flags;
2031
    CERT_PKEY pkeys[SSL_PKEY_NUM];
2032
    /* Custom certificate types sent in certificate request message. */
2033
    uint8_t *ctype;
2034
    size_t ctype_len;
2035
    /*
2036
     * supported signature algorithms. When set on a client this is sent in
2037
     * the client hello as the supported signature algorithms extension. For
2038
     * servers it represents the signature algorithms we are willing to use.
2039
     */
2040
    uint16_t *conf_sigalgs;
2041
    /* Size of above array */
2042
    size_t conf_sigalgslen;
2043
    /*
2044
     * Client authentication signature algorithms, if not set then uses
2045
     * conf_sigalgs. On servers these will be the signature algorithms sent
2046
     * to the client in a certificate request for TLS 1.2. On a client this
2047
     * represents the signature algorithms we are willing to use for client
2048
     * authentication.
2049
     */
2050
    uint16_t *client_sigalgs;
2051
    /* Size of above array */
2052
    size_t client_sigalgslen;
2053
    /*
2054
     * Certificate setup callback: if set is called whenever a certificate
2055
     * may be required (client or server). the callback can then examine any
2056
     * appropriate parameters and setup any certificates required. This
2057
     * allows advanced applications to select certificates on the fly: for
2058
     * example based on supported signature algorithms or curves.
2059
     */
2060
    int (*cert_cb)(SSL *ssl, void *arg);
2061
    void *cert_cb_arg;
2062
    /*
2063
     * Optional X509_STORE for chain building or certificate validation If
2064
     * NULL the parent SSL_CTX store is used instead.
2065
     */
2066
    X509_STORE *chain_store;
2067
    X509_STORE *verify_store;
2068
    /* Custom extensions */
2069
    custom_ext_methods custext;
2070
    /* Security callback */
2071
    int (*sec_cb)(const SSL *s, const SSL_CTX *ctx, int op, int bits, int nid,
2072
        void *other, void *ex);
2073
    /* Security level */
2074
    int sec_level;
2075
    void *sec_ex;
2076
#ifndef OPENSSL_NO_PSK
2077
    /* If not NULL psk identity hint to use for servers */
2078
    char *psk_identity_hint;
2079
#endif
2080
    CRYPTO_REF_COUNT references; /* >1 only if SSL_copy_session_id is used */
2081
    CRYPTO_RWLOCK *lock;
2082
} CERT;
2083
2084
#define FP_ICC (int (*)(const void *, const void *))
2085
2086
/*
2087
 * This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff It is a bit
2088
 * of a mess of functions, but hell, think of it as an opaque structure :-)
2089
 */
2090
typedef struct ssl3_enc_method {
2091
    int (*enc)(SSL *, SSL3_RECORD *, size_t, int, SSL_MAC_BUF *, size_t);
2092
    int (*mac)(SSL *, SSL3_RECORD *, unsigned char *, int);
2093
    int (*setup_key_block)(SSL *);
2094
    int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *,
2095
        size_t, size_t *);
2096
    int (*change_cipher_state)(SSL *, int);
2097
    size_t (*final_finish_mac)(SSL *, const char *, size_t, unsigned char *);
2098
    const char *client_finished_label;
2099
    size_t client_finished_label_len;
2100
    const char *server_finished_label;
2101
    size_t server_finished_label_len;
2102
    int (*alert_value)(int);
2103
    int (*export_keying_material)(SSL *, unsigned char *, size_t,
2104
        const char *, size_t,
2105
        const unsigned char *, size_t,
2106
        int use_context);
2107
    /* Various flags indicating protocol version requirements */
2108
    uint32_t enc_flags;
2109
    /* Set the handshake header */
2110
    int (*set_handshake_header)(SSL *s, WPACKET *pkt, int type);
2111
    /* Close construction of the handshake message */
2112
    int (*close_construct_packet)(SSL *s, WPACKET *pkt, int htype);
2113
    /* Write out handshake message */
2114
    int (*do_write)(SSL *s);
2115
} SSL3_ENC_METHOD;
2116
2117
#define ssl_set_handshake_header(s, pkt, htype) \
2118
20.9k
    s->method->ssl3_enc->set_handshake_header((s), (pkt), (htype))
2119
#define ssl_close_construct_packet(s, pkt, htype) \
2120
41.2k
    s->method->ssl3_enc->close_construct_packet((s), (pkt), (htype))
2121
259k
#define ssl_do_write(s) s->method->ssl3_enc->do_write(s)
2122
2123
/* Values for enc_flags */
2124
2125
/* Uses explicit IV for CBC mode */
2126
5.80k
#define SSL_ENC_FLAG_EXPLICIT_IV 0x1
2127
/* Uses signature algorithms extension */
2128
271k
#define SSL_ENC_FLAG_SIGALGS 0x2
2129
/* Uses SHA256 default PRF */
2130
460k
#define SSL_ENC_FLAG_SHA256_PRF 0x4
2131
/* Is DTLS */
2132
132M
#define SSL_ENC_FLAG_DTLS 0x8
2133
/*
2134
 * Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2: may
2135
 * apply to others in future.
2136
 */
2137
0
#define SSL_ENC_FLAG_TLS1_2_CIPHERS 0x10
2138
2139
#ifndef OPENSSL_NO_COMP
2140
/* Used for holding the relevant compression methods loaded into SSL_CTX */
2141
typedef struct ssl3_comp_st {
2142
    int comp_id; /* The identifier byte for this compression
2143
                  * type */
2144
    char *name; /* Text name used for the compression type */
2145
    COMP_METHOD *method; /* The method :-) */
2146
} SSL3_COMP;
2147
#endif
2148
2149
typedef enum downgrade_en {
2150
    DOWNGRADE_NONE,
2151
    DOWNGRADE_TO_1_2,
2152
    DOWNGRADE_TO_1_1
2153
} DOWNGRADE;
2154
2155
/*
2156
 * Dummy status type for the status_type extension. Indicates no status type
2157
 * set
2158
 */
2159
143k
#define TLSEXT_STATUSTYPE_nothing -1
2160
2161
/* Sigalgs values */
2162
0
#define TLSEXT_SIGALG_ecdsa_secp256r1_sha256 0x0403
2163
0
#define TLSEXT_SIGALG_ecdsa_secp384r1_sha384 0x0503
2164
#define TLSEXT_SIGALG_ecdsa_secp521r1_sha512 0x0603
2165
#define TLSEXT_SIGALG_ecdsa_sha224 0x0303
2166
#define TLSEXT_SIGALG_ecdsa_sha1 0x0203
2167
#define TLSEXT_SIGALG_rsa_pss_rsae_sha256 0x0804
2168
#define TLSEXT_SIGALG_rsa_pss_rsae_sha384 0x0805
2169
#define TLSEXT_SIGALG_rsa_pss_rsae_sha512 0x0806
2170
#define TLSEXT_SIGALG_rsa_pss_pss_sha256 0x0809
2171
#define TLSEXT_SIGALG_rsa_pss_pss_sha384 0x080a
2172
#define TLSEXT_SIGALG_rsa_pss_pss_sha512 0x080b
2173
#define TLSEXT_SIGALG_rsa_pkcs1_sha256 0x0401
2174
#define TLSEXT_SIGALG_rsa_pkcs1_sha384 0x0501
2175
#define TLSEXT_SIGALG_rsa_pkcs1_sha512 0x0601
2176
#define TLSEXT_SIGALG_rsa_pkcs1_sha224 0x0301
2177
#define TLSEXT_SIGALG_rsa_pkcs1_sha1 0x0201
2178
#define TLSEXT_SIGALG_dsa_sha256 0x0402
2179
#define TLSEXT_SIGALG_dsa_sha384 0x0502
2180
#define TLSEXT_SIGALG_dsa_sha512 0x0602
2181
#define TLSEXT_SIGALG_dsa_sha224 0x0302
2182
#define TLSEXT_SIGALG_dsa_sha1 0x0202
2183
#define TLSEXT_SIGALG_gostr34102012_256_intrinsic 0x0840
2184
#define TLSEXT_SIGALG_gostr34102012_512_intrinsic 0x0841
2185
#define TLSEXT_SIGALG_gostr34102012_256_gostr34112012_256 0xeeee
2186
#define TLSEXT_SIGALG_gostr34102012_512_gostr34112012_512 0xefef
2187
#define TLSEXT_SIGALG_gostr34102001_gostr3411 0xeded
2188
2189
15.7k
#define TLSEXT_SIGALG_ed25519 0x0807
2190
8.55k
#define TLSEXT_SIGALG_ed448 0x0808
2191
2192
/* Known PSK key exchange modes */
2193
2.52k
#define TLSEXT_KEX_MODE_KE 0x00
2194
1.85k
#define TLSEXT_KEX_MODE_KE_DHE 0x01
2195
2196
/*
2197
 * Internal representations of key exchange modes
2198
 */
2199
416
#define TLSEXT_KEX_MODE_FLAG_NONE 0
2200
113
#define TLSEXT_KEX_MODE_FLAG_KE 1
2201
91.1k
#define TLSEXT_KEX_MODE_FLAG_KE_DHE 2
2202
2203
5.26k
#define SSL_USE_PSS(s) (s->s3.tmp.peer_sigalg != NULL && s->s3.tmp.peer_sigalg->sig == EVP_PKEY_RSA_PSS)
2204
2205
/* A dummy signature value not valid for TLSv1.2 signature algs */
2206
#define TLSEXT_signature_rsa_pss 0x0101
2207
2208
/* TLSv1.3 downgrade protection sentinel values */
2209
extern const unsigned char tls11downgrade[8];
2210
extern const unsigned char tls12downgrade[8];
2211
2212
extern SSL3_ENC_METHOD ssl3_undef_enc_method;
2213
2214
__owur const SSL_METHOD *ssl_bad_method(int ver);
2215
__owur const SSL_METHOD *sslv3_method(void);
2216
__owur const SSL_METHOD *sslv3_server_method(void);
2217
__owur const SSL_METHOD *sslv3_client_method(void);
2218
__owur const SSL_METHOD *tlsv1_method(void);
2219
__owur const SSL_METHOD *tlsv1_server_method(void);
2220
__owur const SSL_METHOD *tlsv1_client_method(void);
2221
__owur const SSL_METHOD *tlsv1_1_method(void);
2222
__owur const SSL_METHOD *tlsv1_1_server_method(void);
2223
__owur const SSL_METHOD *tlsv1_1_client_method(void);
2224
__owur const SSL_METHOD *tlsv1_2_method(void);
2225
__owur const SSL_METHOD *tlsv1_2_server_method(void);
2226
__owur const SSL_METHOD *tlsv1_2_client_method(void);
2227
__owur const SSL_METHOD *tlsv1_3_method(void);
2228
__owur const SSL_METHOD *tlsv1_3_server_method(void);
2229
__owur const SSL_METHOD *tlsv1_3_client_method(void);
2230
__owur const SSL_METHOD *dtlsv1_method(void);
2231
__owur const SSL_METHOD *dtlsv1_server_method(void);
2232
__owur const SSL_METHOD *dtlsv1_client_method(void);
2233
__owur const SSL_METHOD *dtls_bad_ver_client_method(void);
2234
__owur const SSL_METHOD *dtlsv1_2_method(void);
2235
__owur const SSL_METHOD *dtlsv1_2_server_method(void);
2236
__owur const SSL_METHOD *dtlsv1_2_client_method(void);
2237
2238
extern const SSL3_ENC_METHOD TLSv1_enc_data;
2239
extern const SSL3_ENC_METHOD TLSv1_1_enc_data;
2240
extern const SSL3_ENC_METHOD TLSv1_2_enc_data;
2241
extern const SSL3_ENC_METHOD TLSv1_3_enc_data;
2242
extern const SSL3_ENC_METHOD SSLv3_enc_data;
2243
extern const SSL3_ENC_METHOD DTLSv1_enc_data;
2244
extern const SSL3_ENC_METHOD DTLSv1_2_enc_data;
2245
2246
/*
2247
 * Flags for SSL methods
2248
 */
2249
#define SSL_METHOD_NO_FIPS (1U << 0)
2250
2.95M
#define SSL_METHOD_NO_SUITEB (1U << 1)
2251
2252
#define IMPLEMENT_tls_meth_func(version, flags, mask, func_name, s_accept, \
2253
    s_connect, enc_data)                                                   \
2254
    const SSL_METHOD *func_name(void)                                      \
2255
3.84M
    {                                                                      \
2256
3.84M
        static const SSL_METHOD func_name##_data = {                       \
2257
3.84M
            version,                                                       \
2258
3.84M
            flags,                                                         \
2259
3.84M
            mask,                                                          \
2260
3.84M
            tls1_new,                                                      \
2261
3.84M
            tls1_clear,                                                    \
2262
3.84M
            tls1_free,                                                     \
2263
3.84M
            s_accept,                                                      \
2264
3.84M
            s_connect,                                                     \
2265
3.84M
            ssl3_read,                                                     \
2266
3.84M
            ssl3_peek,                                                     \
2267
3.84M
            ssl3_write,                                                    \
2268
3.84M
            ssl3_shutdown,                                                 \
2269
3.84M
            ssl3_renegotiate,                                              \
2270
3.84M
            ssl3_renegotiate_check,                                        \
2271
3.84M
            ssl3_read_bytes,                                               \
2272
3.84M
            ssl3_write_bytes,                                              \
2273
3.84M
            ssl3_dispatch_alert,                                           \
2274
3.84M
            ssl3_ctrl,                                                     \
2275
3.84M
            ssl3_ctx_ctrl,                                                 \
2276
3.84M
            ssl3_get_cipher_by_char,                                       \
2277
3.84M
            ssl3_put_cipher_by_char,                                       \
2278
3.84M
            ssl3_pending,                                                  \
2279
3.84M
            ssl3_num_ciphers,                                              \
2280
3.84M
            ssl3_get_cipher,                                               \
2281
3.84M
            tls1_default_timeout,                                          \
2282
3.84M
            &enc_data,                                                     \
2283
3.84M
            ssl_undefined_void_function,                                   \
2284
3.84M
            ssl3_callback_ctrl,                                            \
2285
3.84M
            ssl3_ctx_callback_ctrl,                                        \
2286
3.84M
        };                                                                 \
2287
3.84M
        return &func_name##_data;                                          \
2288
3.84M
    }
TLS_method
Line
Count
Source
2255
120k
    {                                                                      \
2256
120k
        static const SSL_METHOD func_name##_data = {                       \
2257
120k
            version,                                                       \
2258
120k
            flags,                                                         \
2259
120k
            mask,                                                          \
2260
120k
            tls1_new,                                                      \
2261
120k
            tls1_clear,                                                    \
2262
120k
            tls1_free,                                                     \
2263
120k
            s_accept,                                                      \
2264
120k
            s_connect,                                                     \
2265
120k
            ssl3_read,                                                     \
2266
120k
            ssl3_peek,                                                     \
2267
120k
            ssl3_write,                                                    \
2268
120k
            ssl3_shutdown,                                                 \
2269
120k
            ssl3_renegotiate,                                              \
2270
120k
            ssl3_renegotiate_check,                                        \
2271
120k
            ssl3_read_bytes,                                               \
2272
120k
            ssl3_write_bytes,                                              \
2273
120k
            ssl3_dispatch_alert,                                           \
2274
120k
            ssl3_ctrl,                                                     \
2275
120k
            ssl3_ctx_ctrl,                                                 \
2276
120k
            ssl3_get_cipher_by_char,                                       \
2277
120k
            ssl3_put_cipher_by_char,                                       \
2278
120k
            ssl3_pending,                                                  \
2279
120k
            ssl3_num_ciphers,                                              \
2280
120k
            ssl3_get_cipher,                                               \
2281
120k
            tls1_default_timeout,                                          \
2282
120k
            &enc_data,                                                     \
2283
120k
            ssl_undefined_void_function,                                   \
2284
120k
            ssl3_callback_ctrl,                                            \
2285
120k
            ssl3_ctx_callback_ctrl,                                        \
2286
120k
        };                                                                 \
2287
120k
        return &func_name##_data;                                          \
2288
120k
    }
Unexecuted instantiation: tlsv1_3_method
Unexecuted instantiation: tlsv1_2_method
Unexecuted instantiation: tlsv1_1_method
Unexecuted instantiation: tlsv1_method
Unexecuted instantiation: TLS_server_method
tlsv1_3_server_method
Line
Count
Source
2255
23.4k
    {                                                                      \
2256
23.4k
        static const SSL_METHOD func_name##_data = {                       \
2257
23.4k
            version,                                                       \
2258
23.4k
            flags,                                                         \
2259
23.4k
            mask,                                                          \
2260
23.4k
            tls1_new,                                                      \
2261
23.4k
            tls1_clear,                                                    \
2262
23.4k
            tls1_free,                                                     \
2263
23.4k
            s_accept,                                                      \
2264
23.4k
            s_connect,                                                     \
2265
23.4k
            ssl3_read,                                                     \
2266
23.4k
            ssl3_peek,                                                     \
2267
23.4k
            ssl3_write,                                                    \
2268
23.4k
            ssl3_shutdown,                                                 \
2269
23.4k
            ssl3_renegotiate,                                              \
2270
23.4k
            ssl3_renegotiate_check,                                        \
2271
23.4k
            ssl3_read_bytes,                                               \
2272
23.4k
            ssl3_write_bytes,                                              \
2273
23.4k
            ssl3_dispatch_alert,                                           \
2274
23.4k
            ssl3_ctrl,                                                     \
2275
23.4k
            ssl3_ctx_ctrl,                                                 \
2276
23.4k
            ssl3_get_cipher_by_char,                                       \
2277
23.4k
            ssl3_put_cipher_by_char,                                       \
2278
23.4k
            ssl3_pending,                                                  \
2279
23.4k
            ssl3_num_ciphers,                                              \
2280
23.4k
            ssl3_get_cipher,                                               \
2281
23.4k
            tls1_default_timeout,                                          \
2282
23.4k
            &enc_data,                                                     \
2283
23.4k
            ssl_undefined_void_function,                                   \
2284
23.4k
            ssl3_callback_ctrl,                                            \
2285
23.4k
            ssl3_ctx_callback_ctrl,                                        \
2286
23.4k
        };                                                                 \
2287
23.4k
        return &func_name##_data;                                          \
2288
23.4k
    }
tlsv1_2_server_method
Line
Count
Source
2255
24.4k
    {                                                                      \
2256
24.4k
        static const SSL_METHOD func_name##_data = {                       \
2257
24.4k
            version,                                                       \
2258
24.4k
            flags,                                                         \
2259
24.4k
            mask,                                                          \
2260
24.4k
            tls1_new,                                                      \
2261
24.4k
            tls1_clear,                                                    \
2262
24.4k
            tls1_free,                                                     \
2263
24.4k
            s_accept,                                                      \
2264
24.4k
            s_connect,                                                     \
2265
24.4k
            ssl3_read,                                                     \
2266
24.4k
            ssl3_peek,                                                     \
2267
24.4k
            ssl3_write,                                                    \
2268
24.4k
            ssl3_shutdown,                                                 \
2269
24.4k
            ssl3_renegotiate,                                              \
2270
24.4k
            ssl3_renegotiate_check,                                        \
2271
24.4k
            ssl3_read_bytes,                                               \
2272
24.4k
            ssl3_write_bytes,                                              \
2273
24.4k
            ssl3_dispatch_alert,                                           \
2274
24.4k
            ssl3_ctrl,                                                     \
2275
24.4k
            ssl3_ctx_ctrl,                                                 \
2276
24.4k
            ssl3_get_cipher_by_char,                                       \
2277
24.4k
            ssl3_put_cipher_by_char,                                       \
2278
24.4k
            ssl3_pending,                                                  \
2279
24.4k
            ssl3_num_ciphers,                                              \
2280
24.4k
            ssl3_get_cipher,                                               \
2281
24.4k
            tls1_default_timeout,                                          \
2282
24.4k
            &enc_data,                                                     \
2283
24.4k
            ssl_undefined_void_function,                                   \
2284
24.4k
            ssl3_callback_ctrl,                                            \
2285
24.4k
            ssl3_ctx_callback_ctrl,                                        \
2286
24.4k
        };                                                                 \
2287
24.4k
        return &func_name##_data;                                          \
2288
24.4k
    }
tlsv1_1_server_method
Line
Count
Source
2255
2.26k
    {                                                                      \
2256
2.26k
        static const SSL_METHOD func_name##_data = {                       \
2257
2.26k
            version,                                                       \
2258
2.26k
            flags,                                                         \
2259
2.26k
            mask,                                                          \
2260
2.26k
            tls1_new,                                                      \
2261
2.26k
            tls1_clear,                                                    \
2262
2.26k
            tls1_free,                                                     \
2263
2.26k
            s_accept,                                                      \
2264
2.26k
            s_connect,                                                     \
2265
2.26k
            ssl3_read,                                                     \
2266
2.26k
            ssl3_peek,                                                     \
2267
2.26k
            ssl3_write,                                                    \
2268
2.26k
            ssl3_shutdown,                                                 \
2269
2.26k
            ssl3_renegotiate,                                              \
2270
2.26k
            ssl3_renegotiate_check,                                        \
2271
2.26k
            ssl3_read_bytes,                                               \
2272
2.26k
            ssl3_write_bytes,                                              \
2273
2.26k
            ssl3_dispatch_alert,                                           \
2274
2.26k
            ssl3_ctrl,                                                     \
2275
2.26k
            ssl3_ctx_ctrl,                                                 \
2276
2.26k
            ssl3_get_cipher_by_char,                                       \
2277
2.26k
            ssl3_put_cipher_by_char,                                       \
2278
2.26k
            ssl3_pending,                                                  \
2279
2.26k
            ssl3_num_ciphers,                                              \
2280
2.26k
            ssl3_get_cipher,                                               \
2281
2.26k
            tls1_default_timeout,                                          \
2282
2.26k
            &enc_data,                                                     \
2283
2.26k
            ssl_undefined_void_function,                                   \
2284
2.26k
            ssl3_callback_ctrl,                                            \
2285
2.26k
            ssl3_ctx_callback_ctrl,                                        \
2286
2.26k
        };                                                                 \
2287
2.26k
        return &func_name##_data;                                          \
2288
2.26k
    }
tlsv1_server_method
Line
Count
Source
2255
2.06k
    {                                                                      \
2256
2.06k
        static const SSL_METHOD func_name##_data = {                       \
2257
2.06k
            version,                                                       \
2258
2.06k
            flags,                                                         \
2259
2.06k
            mask,                                                          \
2260
2.06k
            tls1_new,                                                      \
2261
2.06k
            tls1_clear,                                                    \
2262
2.06k
            tls1_free,                                                     \
2263
2.06k
            s_accept,                                                      \
2264
2.06k
            s_connect,                                                     \
2265
2.06k
            ssl3_read,                                                     \
2266
2.06k
            ssl3_peek,                                                     \
2267
2.06k
            ssl3_write,                                                    \
2268
2.06k
            ssl3_shutdown,                                                 \
2269
2.06k
            ssl3_renegotiate,                                              \
2270
2.06k
            ssl3_renegotiate_check,                                        \
2271
2.06k
            ssl3_read_bytes,                                               \
2272
2.06k
            ssl3_write_bytes,                                              \
2273
2.06k
            ssl3_dispatch_alert,                                           \
2274
2.06k
            ssl3_ctrl,                                                     \
2275
2.06k
            ssl3_ctx_ctrl,                                                 \
2276
2.06k
            ssl3_get_cipher_by_char,                                       \
2277
2.06k
            ssl3_put_cipher_by_char,                                       \
2278
2.06k
            ssl3_pending,                                                  \
2279
2.06k
            ssl3_num_ciphers,                                              \
2280
2.06k
            ssl3_get_cipher,                                               \
2281
2.06k
            tls1_default_timeout,                                          \
2282
2.06k
            &enc_data,                                                     \
2283
2.06k
            ssl_undefined_void_function,                                   \
2284
2.06k
            ssl3_callback_ctrl,                                            \
2285
2.06k
            ssl3_ctx_callback_ctrl,                                        \
2286
2.06k
        };                                                                 \
2287
2.06k
        return &func_name##_data;                                          \
2288
2.06k
    }
Unexecuted instantiation: TLS_client_method
tlsv1_3_client_method
Line
Count
Source
2255
933k
    {                                                                      \
2256
933k
        static const SSL_METHOD func_name##_data = {                       \
2257
933k
            version,                                                       \
2258
933k
            flags,                                                         \
2259
933k
            mask,                                                          \
2260
933k
            tls1_new,                                                      \
2261
933k
            tls1_clear,                                                    \
2262
933k
            tls1_free,                                                     \
2263
933k
            s_accept,                                                      \
2264
933k
            s_connect,                                                     \
2265
933k
            ssl3_read,                                                     \
2266
933k
            ssl3_peek,                                                     \
2267
933k
            ssl3_write,                                                    \
2268
933k
            ssl3_shutdown,                                                 \
2269
933k
            ssl3_renegotiate,                                              \
2270
933k
            ssl3_renegotiate_check,                                        \
2271
933k
            ssl3_read_bytes,                                               \
2272
933k
            ssl3_write_bytes,                                              \
2273
933k
            ssl3_dispatch_alert,                                           \
2274
933k
            ssl3_ctrl,                                                     \
2275
933k
            ssl3_ctx_ctrl,                                                 \
2276
933k
            ssl3_get_cipher_by_char,                                       \
2277
933k
            ssl3_put_cipher_by_char,                                       \
2278
933k
            ssl3_pending,                                                  \
2279
933k
            ssl3_num_ciphers,                                              \
2280
933k
            ssl3_get_cipher,                                               \
2281
933k
            tls1_default_timeout,                                          \
2282
933k
            &enc_data,                                                     \
2283
933k
            ssl_undefined_void_function,                                   \
2284
933k
            ssl3_callback_ctrl,                                            \
2285
933k
            ssl3_ctx_callback_ctrl,                                        \
2286
933k
        };                                                                 \
2287
933k
        return &func_name##_data;                                          \
2288
933k
    }
tlsv1_2_client_method
Line
Count
Source
2255
926k
    {                                                                      \
2256
926k
        static const SSL_METHOD func_name##_data = {                       \
2257
926k
            version,                                                       \
2258
926k
            flags,                                                         \
2259
926k
            mask,                                                          \
2260
926k
            tls1_new,                                                      \
2261
926k
            tls1_clear,                                                    \
2262
926k
            tls1_free,                                                     \
2263
926k
            s_accept,                                                      \
2264
926k
            s_connect,                                                     \
2265
926k
            ssl3_read,                                                     \
2266
926k
            ssl3_peek,                                                     \
2267
926k
            ssl3_write,                                                    \
2268
926k
            ssl3_shutdown,                                                 \
2269
926k
            ssl3_renegotiate,                                              \
2270
926k
            ssl3_renegotiate_check,                                        \
2271
926k
            ssl3_read_bytes,                                               \
2272
926k
            ssl3_write_bytes,                                              \
2273
926k
            ssl3_dispatch_alert,                                           \
2274
926k
            ssl3_ctrl,                                                     \
2275
926k
            ssl3_ctx_ctrl,                                                 \
2276
926k
            ssl3_get_cipher_by_char,                                       \
2277
926k
            ssl3_put_cipher_by_char,                                       \
2278
926k
            ssl3_pending,                                                  \
2279
926k
            ssl3_num_ciphers,                                              \
2280
926k
            ssl3_get_cipher,                                               \
2281
926k
            tls1_default_timeout,                                          \
2282
926k
            &enc_data,                                                     \
2283
926k
            ssl_undefined_void_function,                                   \
2284
926k
            ssl3_callback_ctrl,                                            \
2285
926k
            ssl3_ctx_callback_ctrl,                                        \
2286
926k
        };                                                                 \
2287
926k
        return &func_name##_data;                                          \
2288
926k
    }
tlsv1_1_client_method
Line
Count
Source
2255
904k
    {                                                                      \
2256
904k
        static const SSL_METHOD func_name##_data = {                       \
2257
904k
            version,                                                       \
2258
904k
            flags,                                                         \
2259
904k
            mask,                                                          \
2260
904k
            tls1_new,                                                      \
2261
904k
            tls1_clear,                                                    \
2262
904k
            tls1_free,                                                     \
2263
904k
            s_accept,                                                      \
2264
904k
            s_connect,                                                     \
2265
904k
            ssl3_read,                                                     \
2266
904k
            ssl3_peek,                                                     \
2267
904k
            ssl3_write,                                                    \
2268
904k
            ssl3_shutdown,                                                 \
2269
904k
            ssl3_renegotiate,                                              \
2270
904k
            ssl3_renegotiate_check,                                        \
2271
904k
            ssl3_read_bytes,                                               \
2272
904k
            ssl3_write_bytes,                                              \
2273
904k
            ssl3_dispatch_alert,                                           \
2274
904k
            ssl3_ctrl,                                                     \
2275
904k
            ssl3_ctx_ctrl,                                                 \
2276
904k
            ssl3_get_cipher_by_char,                                       \
2277
904k
            ssl3_put_cipher_by_char,                                       \
2278
904k
            ssl3_pending,                                                  \
2279
904k
            ssl3_num_ciphers,                                              \
2280
904k
            ssl3_get_cipher,                                               \
2281
904k
            tls1_default_timeout,                                          \
2282
904k
            &enc_data,                                                     \
2283
904k
            ssl_undefined_void_function,                                   \
2284
904k
            ssl3_callback_ctrl,                                            \
2285
904k
            ssl3_ctx_callback_ctrl,                                        \
2286
904k
        };                                                                 \
2287
904k
        return &func_name##_data;                                          \
2288
904k
    }
tlsv1_client_method
Line
Count
Source
2255
909k
    {                                                                      \
2256
909k
        static const SSL_METHOD func_name##_data = {                       \
2257
909k
            version,                                                       \
2258
909k
            flags,                                                         \
2259
909k
            mask,                                                          \
2260
909k
            tls1_new,                                                      \
2261
909k
            tls1_clear,                                                    \
2262
909k
            tls1_free,                                                     \
2263
909k
            s_accept,                                                      \
2264
909k
            s_connect,                                                     \
2265
909k
            ssl3_read,                                                     \
2266
909k
            ssl3_peek,                                                     \
2267
909k
            ssl3_write,                                                    \
2268
909k
            ssl3_shutdown,                                                 \
2269
909k
            ssl3_renegotiate,                                              \
2270
909k
            ssl3_renegotiate_check,                                        \
2271
909k
            ssl3_read_bytes,                                               \
2272
909k
            ssl3_write_bytes,                                              \
2273
909k
            ssl3_dispatch_alert,                                           \
2274
909k
            ssl3_ctrl,                                                     \
2275
909k
            ssl3_ctx_ctrl,                                                 \
2276
909k
            ssl3_get_cipher_by_char,                                       \
2277
909k
            ssl3_put_cipher_by_char,                                       \
2278
909k
            ssl3_pending,                                                  \
2279
909k
            ssl3_num_ciphers,                                              \
2280
909k
            ssl3_get_cipher,                                               \
2281
909k
            tls1_default_timeout,                                          \
2282
909k
            &enc_data,                                                     \
2283
909k
            ssl_undefined_void_function,                                   \
2284
909k
            ssl3_callback_ctrl,                                            \
2285
909k
            ssl3_ctx_callback_ctrl,                                        \
2286
909k
        };                                                                 \
2287
909k
        return &func_name##_data;                                          \
2288
909k
    }
2289
2290
#define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect) \
2291
    const SSL_METHOD *func_name(void)                            \
2292
    {                                                            \
2293
        static const SSL_METHOD func_name##_data = {             \
2294
            SSL3_VERSION,                                        \
2295
            SSL_METHOD_NO_FIPS | SSL_METHOD_NO_SUITEB,           \
2296
            SSL_OP_NO_SSLv3,                                     \
2297
            ssl3_new,                                            \
2298
            ssl3_clear,                                          \
2299
            ssl3_free,                                           \
2300
            s_accept,                                            \
2301
            s_connect,                                           \
2302
            ssl3_read,                                           \
2303
            ssl3_peek,                                           \
2304
            ssl3_write,                                          \
2305
            ssl3_shutdown,                                       \
2306
            ssl3_renegotiate,                                    \
2307
            ssl3_renegotiate_check,                              \
2308
            ssl3_read_bytes,                                     \
2309
            ssl3_write_bytes,                                    \
2310
            ssl3_dispatch_alert,                                 \
2311
            ssl3_ctrl,                                           \
2312
            ssl3_ctx_ctrl,                                       \
2313
            ssl3_get_cipher_by_char,                             \
2314
            ssl3_put_cipher_by_char,                             \
2315
            ssl3_pending,                                        \
2316
            ssl3_num_ciphers,                                    \
2317
            ssl3_get_cipher,                                     \
2318
            ssl3_default_timeout,                                \
2319
            &SSLv3_enc_data,                                     \
2320
            ssl_undefined_void_function,                         \
2321
            ssl3_callback_ctrl,                                  \
2322
            ssl3_ctx_callback_ctrl,                              \
2323
        };                                                       \
2324
        return &func_name##_data;                                \
2325
    }
2326
2327
#define IMPLEMENT_dtls1_meth_func(version, flags, mask, func_name, s_accept, \
2328
    s_connect, enc_data)                                                     \
2329
    const SSL_METHOD *func_name(void)                                        \
2330
787k
    {                                                                        \
2331
787k
        static const SSL_METHOD func_name##_data = {                         \
2332
787k
            version,                                                         \
2333
787k
            flags,                                                           \
2334
787k
            mask,                                                            \
2335
787k
            dtls1_new,                                                       \
2336
787k
            dtls1_clear,                                                     \
2337
787k
            dtls1_free,                                                      \
2338
787k
            s_accept,                                                        \
2339
787k
            s_connect,                                                       \
2340
787k
            ssl3_read,                                                       \
2341
787k
            ssl3_peek,                                                       \
2342
787k
            ssl3_write,                                                      \
2343
787k
            dtls1_shutdown,                                                  \
2344
787k
            ssl3_renegotiate,                                                \
2345
787k
            ssl3_renegotiate_check,                                          \
2346
787k
            dtls1_read_bytes,                                                \
2347
787k
            dtls1_write_app_data_bytes,                                      \
2348
787k
            dtls1_dispatch_alert,                                            \
2349
787k
            dtls1_ctrl,                                                      \
2350
787k
            ssl3_ctx_ctrl,                                                   \
2351
787k
            ssl3_get_cipher_by_char,                                         \
2352
787k
            ssl3_put_cipher_by_char,                                         \
2353
787k
            ssl3_pending,                                                    \
2354
787k
            ssl3_num_ciphers,                                                \
2355
787k
            ssl3_get_cipher,                                                 \
2356
787k
            dtls1_default_timeout,                                           \
2357
787k
            &enc_data,                                                       \
2358
787k
            ssl_undefined_void_function,                                     \
2359
787k
            ssl3_callback_ctrl,                                              \
2360
787k
            ssl3_ctx_callback_ctrl,                                          \
2361
787k
        };                                                                   \
2362
787k
        return &func_name##_data;                                            \
2363
787k
    }
Unexecuted instantiation: dtlsv1_method
Unexecuted instantiation: dtlsv1_2_method
DTLS_method
Line
Count
Source
2330
321
    {                                                                        \
2331
321
        static const SSL_METHOD func_name##_data = {                         \
2332
321
            version,                                                         \
2333
321
            flags,                                                           \
2334
321
            mask,                                                            \
2335
321
            dtls1_new,                                                       \
2336
321
            dtls1_clear,                                                     \
2337
321
            dtls1_free,                                                      \
2338
321
            s_accept,                                                        \
2339
321
            s_connect,                                                       \
2340
321
            ssl3_read,                                                       \
2341
321
            ssl3_peek,                                                       \
2342
321
            ssl3_write,                                                      \
2343
321
            dtls1_shutdown,                                                  \
2344
321
            ssl3_renegotiate,                                                \
2345
321
            ssl3_renegotiate_check,                                          \
2346
321
            dtls1_read_bytes,                                                \
2347
321
            dtls1_write_app_data_bytes,                                      \
2348
321
            dtls1_dispatch_alert,                                            \
2349
321
            dtls1_ctrl,                                                      \
2350
321
            ssl3_ctx_ctrl,                                                   \
2351
321
            ssl3_get_cipher_by_char,                                         \
2352
321
            ssl3_put_cipher_by_char,                                         \
2353
321
            ssl3_pending,                                                    \
2354
321
            ssl3_num_ciphers,                                                \
2355
321
            ssl3_get_cipher,                                                 \
2356
321
            dtls1_default_timeout,                                           \
2357
321
            &enc_data,                                                       \
2358
321
            ssl_undefined_void_function,                                     \
2359
321
            ssl3_callback_ctrl,                                              \
2360
321
            ssl3_ctx_callback_ctrl,                                          \
2361
321
        };                                                                   \
2362
321
        return &func_name##_data;                                            \
2363
321
    }
dtlsv1_server_method
Line
Count
Source
2330
4.07k
    {                                                                        \
2331
4.07k
        static const SSL_METHOD func_name##_data = {                         \
2332
4.07k
            version,                                                         \
2333
4.07k
            flags,                                                           \
2334
4.07k
            mask,                                                            \
2335
4.07k
            dtls1_new,                                                       \
2336
4.07k
            dtls1_clear,                                                     \
2337
4.07k
            dtls1_free,                                                      \
2338
4.07k
            s_accept,                                                        \
2339
4.07k
            s_connect,                                                       \
2340
4.07k
            ssl3_read,                                                       \
2341
4.07k
            ssl3_peek,                                                       \
2342
4.07k
            ssl3_write,                                                      \
2343
4.07k
            dtls1_shutdown,                                                  \
2344
4.07k
            ssl3_renegotiate,                                                \
2345
4.07k
            ssl3_renegotiate_check,                                          \
2346
4.07k
            dtls1_read_bytes,                                                \
2347
4.07k
            dtls1_write_app_data_bytes,                                      \
2348
4.07k
            dtls1_dispatch_alert,                                            \
2349
4.07k
            dtls1_ctrl,                                                      \
2350
4.07k
            ssl3_ctx_ctrl,                                                   \
2351
4.07k
            ssl3_get_cipher_by_char,                                         \
2352
4.07k
            ssl3_put_cipher_by_char,                                         \
2353
4.07k
            ssl3_pending,                                                    \
2354
4.07k
            ssl3_num_ciphers,                                                \
2355
4.07k
            ssl3_get_cipher,                                                 \
2356
4.07k
            dtls1_default_timeout,                                           \
2357
4.07k
            &enc_data,                                                       \
2358
4.07k
            ssl_undefined_void_function,                                     \
2359
4.07k
            ssl3_callback_ctrl,                                              \
2360
4.07k
            ssl3_ctx_callback_ctrl,                                          \
2361
4.07k
        };                                                                   \
2362
4.07k
        return &func_name##_data;                                            \
2363
4.07k
    }
dtlsv1_2_server_method
Line
Count
Source
2330
12.3k
    {                                                                        \
2331
12.3k
        static const SSL_METHOD func_name##_data = {                         \
2332
12.3k
            version,                                                         \
2333
12.3k
            flags,                                                           \
2334
12.3k
            mask,                                                            \
2335
12.3k
            dtls1_new,                                                       \
2336
12.3k
            dtls1_clear,                                                     \
2337
12.3k
            dtls1_free,                                                      \
2338
12.3k
            s_accept,                                                        \
2339
12.3k
            s_connect,                                                       \
2340
12.3k
            ssl3_read,                                                       \
2341
12.3k
            ssl3_peek,                                                       \
2342
12.3k
            ssl3_write,                                                      \
2343
12.3k
            dtls1_shutdown,                                                  \
2344
12.3k
            ssl3_renegotiate,                                                \
2345
12.3k
            ssl3_renegotiate_check,                                          \
2346
12.3k
            dtls1_read_bytes,                                                \
2347
12.3k
            dtls1_write_app_data_bytes,                                      \
2348
12.3k
            dtls1_dispatch_alert,                                            \
2349
12.3k
            dtls1_ctrl,                                                      \
2350
12.3k
            ssl3_ctx_ctrl,                                                   \
2351
12.3k
            ssl3_get_cipher_by_char,                                         \
2352
12.3k
            ssl3_put_cipher_by_char,                                         \
2353
12.3k
            ssl3_pending,                                                    \
2354
12.3k
            ssl3_num_ciphers,                                                \
2355
12.3k
            ssl3_get_cipher,                                                 \
2356
12.3k
            dtls1_default_timeout,                                           \
2357
12.3k
            &enc_data,                                                       \
2358
12.3k
            ssl_undefined_void_function,                                     \
2359
12.3k
            ssl3_callback_ctrl,                                              \
2360
12.3k
            ssl3_ctx_callback_ctrl,                                          \
2361
12.3k
        };                                                                   \
2362
12.3k
        return &func_name##_data;                                            \
2363
12.3k
    }
DTLS_server_method
Line
Count
Source
2330
21.6k
    {                                                                        \
2331
21.6k
        static const SSL_METHOD func_name##_data = {                         \
2332
21.6k
            version,                                                         \
2333
21.6k
            flags,                                                           \
2334
21.6k
            mask,                                                            \
2335
21.6k
            dtls1_new,                                                       \
2336
21.6k
            dtls1_clear,                                                     \
2337
21.6k
            dtls1_free,                                                      \
2338
21.6k
            s_accept,                                                        \
2339
21.6k
            s_connect,                                                       \
2340
21.6k
            ssl3_read,                                                       \
2341
21.6k
            ssl3_peek,                                                       \
2342
21.6k
            ssl3_write,                                                      \
2343
21.6k
            dtls1_shutdown,                                                  \
2344
21.6k
            ssl3_renegotiate,                                                \
2345
21.6k
            ssl3_renegotiate_check,                                          \
2346
21.6k
            dtls1_read_bytes,                                                \
2347
21.6k
            dtls1_write_app_data_bytes,                                      \
2348
21.6k
            dtls1_dispatch_alert,                                            \
2349
21.6k
            dtls1_ctrl,                                                      \
2350
21.6k
            ssl3_ctx_ctrl,                                                   \
2351
21.6k
            ssl3_get_cipher_by_char,                                         \
2352
21.6k
            ssl3_put_cipher_by_char,                                         \
2353
21.6k
            ssl3_pending,                                                    \
2354
21.6k
            ssl3_num_ciphers,                                                \
2355
21.6k
            ssl3_get_cipher,                                                 \
2356
21.6k
            dtls1_default_timeout,                                           \
2357
21.6k
            &enc_data,                                                       \
2358
21.6k
            ssl_undefined_void_function,                                     \
2359
21.6k
            ssl3_callback_ctrl,                                              \
2360
21.6k
            ssl3_ctx_callback_ctrl,                                          \
2361
21.6k
        };                                                                   \
2362
21.6k
        return &func_name##_data;                                            \
2363
21.6k
    }
dtlsv1_client_method
Line
Count
Source
2330
240k
    {                                                                        \
2331
240k
        static const SSL_METHOD func_name##_data = {                         \
2332
240k
            version,                                                         \
2333
240k
            flags,                                                           \
2334
240k
            mask,                                                            \
2335
240k
            dtls1_new,                                                       \
2336
240k
            dtls1_clear,                                                     \
2337
240k
            dtls1_free,                                                      \
2338
240k
            s_accept,                                                        \
2339
240k
            s_connect,                                                       \
2340
240k
            ssl3_read,                                                       \
2341
240k
            ssl3_peek,                                                       \
2342
240k
            ssl3_write,                                                      \
2343
240k
            dtls1_shutdown,                                                  \
2344
240k
            ssl3_renegotiate,                                                \
2345
240k
            ssl3_renegotiate_check,                                          \
2346
240k
            dtls1_read_bytes,                                                \
2347
240k
            dtls1_write_app_data_bytes,                                      \
2348
240k
            dtls1_dispatch_alert,                                            \
2349
240k
            dtls1_ctrl,                                                      \
2350
240k
            ssl3_ctx_ctrl,                                                   \
2351
240k
            ssl3_get_cipher_by_char,                                         \
2352
240k
            ssl3_put_cipher_by_char,                                         \
2353
240k
            ssl3_pending,                                                    \
2354
240k
            ssl3_num_ciphers,                                                \
2355
240k
            ssl3_get_cipher,                                                 \
2356
240k
            dtls1_default_timeout,                                           \
2357
240k
            &enc_data,                                                       \
2358
240k
            ssl_undefined_void_function,                                     \
2359
240k
            ssl3_callback_ctrl,                                              \
2360
240k
            ssl3_ctx_callback_ctrl,                                          \
2361
240k
        };                                                                   \
2362
240k
        return &func_name##_data;                                            \
2363
240k
    }
dtls_bad_ver_client_method
Line
Count
Source
2330
238k
    {                                                                        \
2331
238k
        static const SSL_METHOD func_name##_data = {                         \
2332
238k
            version,                                                         \
2333
238k
            flags,                                                           \
2334
238k
            mask,                                                            \
2335
238k
            dtls1_new,                                                       \
2336
238k
            dtls1_clear,                                                     \
2337
238k
            dtls1_free,                                                      \
2338
238k
            s_accept,                                                        \
2339
238k
            s_connect,                                                       \
2340
238k
            ssl3_read,                                                       \
2341
238k
            ssl3_peek,                                                       \
2342
238k
            ssl3_write,                                                      \
2343
238k
            dtls1_shutdown,                                                  \
2344
238k
            ssl3_renegotiate,                                                \
2345
238k
            ssl3_renegotiate_check,                                          \
2346
238k
            dtls1_read_bytes,                                                \
2347
238k
            dtls1_write_app_data_bytes,                                      \
2348
238k
            dtls1_dispatch_alert,                                            \
2349
238k
            dtls1_ctrl,                                                      \
2350
238k
            ssl3_ctx_ctrl,                                                   \
2351
238k
            ssl3_get_cipher_by_char,                                         \
2352
238k
            ssl3_put_cipher_by_char,                                         \
2353
238k
            ssl3_pending,                                                    \
2354
238k
            ssl3_num_ciphers,                                                \
2355
238k
            ssl3_get_cipher,                                                 \
2356
238k
            dtls1_default_timeout,                                           \
2357
238k
            &enc_data,                                                       \
2358
238k
            ssl_undefined_void_function,                                     \
2359
238k
            ssl3_callback_ctrl,                                              \
2360
238k
            ssl3_ctx_callback_ctrl,                                          \
2361
238k
        };                                                                   \
2362
238k
        return &func_name##_data;                                            \
2363
238k
    }
dtlsv1_2_client_method
Line
Count
Source
2330
248k
    {                                                                        \
2331
248k
        static const SSL_METHOD func_name##_data = {                         \
2332
248k
            version,                                                         \
2333
248k
            flags,                                                           \
2334
248k
            mask,                                                            \
2335
248k
            dtls1_new,                                                       \
2336
248k
            dtls1_clear,                                                     \
2337
248k
            dtls1_free,                                                      \
2338
248k
            s_accept,                                                        \
2339
248k
            s_connect,                                                       \
2340
248k
            ssl3_read,                                                       \
2341
248k
            ssl3_peek,                                                       \
2342
248k
            ssl3_write,                                                      \
2343
248k
            dtls1_shutdown,                                                  \
2344
248k
            ssl3_renegotiate,                                                \
2345
248k
            ssl3_renegotiate_check,                                          \
2346
248k
            dtls1_read_bytes,                                                \
2347
248k
            dtls1_write_app_data_bytes,                                      \
2348
248k
            dtls1_dispatch_alert,                                            \
2349
248k
            dtls1_ctrl,                                                      \
2350
248k
            ssl3_ctx_ctrl,                                                   \
2351
248k
            ssl3_get_cipher_by_char,                                         \
2352
248k
            ssl3_put_cipher_by_char,                                         \
2353
248k
            ssl3_pending,                                                    \
2354
248k
            ssl3_num_ciphers,                                                \
2355
248k
            ssl3_get_cipher,                                                 \
2356
248k
            dtls1_default_timeout,                                           \
2357
248k
            &enc_data,                                                       \
2358
248k
            ssl_undefined_void_function,                                     \
2359
248k
            ssl3_callback_ctrl,                                              \
2360
248k
            ssl3_ctx_callback_ctrl,                                          \
2361
248k
        };                                                                   \
2362
248k
        return &func_name##_data;                                            \
2363
248k
    }
DTLS_client_method
Line
Count
Source
2330
21.9k
    {                                                                        \
2331
21.9k
        static const SSL_METHOD func_name##_data = {                         \
2332
21.9k
            version,                                                         \
2333
21.9k
            flags,                                                           \
2334
21.9k
            mask,                                                            \
2335
21.9k
            dtls1_new,                                                       \
2336
21.9k
            dtls1_clear,                                                     \
2337
21.9k
            dtls1_free,                                                      \
2338
21.9k
            s_accept,                                                        \
2339
21.9k
            s_connect,                                                       \
2340
21.9k
            ssl3_read,                                                       \
2341
21.9k
            ssl3_peek,                                                       \
2342
21.9k
            ssl3_write,                                                      \
2343
21.9k
            dtls1_shutdown,                                                  \
2344
21.9k
            ssl3_renegotiate,                                                \
2345
21.9k
            ssl3_renegotiate_check,                                          \
2346
21.9k
            dtls1_read_bytes,                                                \
2347
21.9k
            dtls1_write_app_data_bytes,                                      \
2348
21.9k
            dtls1_dispatch_alert,                                            \
2349
21.9k
            dtls1_ctrl,                                                      \
2350
21.9k
            ssl3_ctx_ctrl,                                                   \
2351
21.9k
            ssl3_get_cipher_by_char,                                         \
2352
21.9k
            ssl3_put_cipher_by_char,                                         \
2353
21.9k
            ssl3_pending,                                                    \
2354
21.9k
            ssl3_num_ciphers,                                                \
2355
21.9k
            ssl3_get_cipher,                                                 \
2356
21.9k
            dtls1_default_timeout,                                           \
2357
21.9k
            &enc_data,                                                       \
2358
21.9k
            ssl_undefined_void_function,                                     \
2359
21.9k
            ssl3_callback_ctrl,                                              \
2360
21.9k
            ssl3_ctx_callback_ctrl,                                          \
2361
21.9k
        };                                                                   \
2362
21.9k
        return &func_name##_data;                                            \
2363
21.9k
    }
2364
2365
struct openssl_ssl_test_functions {
2366
    int (*p_ssl_init_wbio_buffer)(SSL *s);
2367
    int (*p_ssl3_setup_buffers)(SSL *s);
2368
};
2369
2370
const char *ssl_protocol_to_string(int version);
2371
2372
/* Returns true if certificate and private key for 'idx' are present */
2373
static ossl_inline int ssl_has_cert(const SSL *s, int idx)
2374
23.3k
{
2375
23.3k
    if (idx < 0 || idx >= SSL_PKEY_NUM)
2376
0
        return 0;
2377
23.3k
    return s->cert->pkeys[idx].x509 != NULL
2378
14.7k
        && s->cert->pkeys[idx].privatekey != NULL;
2379
23.3k
}
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
ssl_lib.c:ssl_has_cert
Line
Count
Source
2374
8.59k
{
2375
8.59k
    if (idx < 0 || idx >= SSL_PKEY_NUM)
2376
0
        return 0;
2377
8.59k
    return s->cert->pkeys[idx].x509 != NULL
2378
0
        && s->cert->pkeys[idx].privatekey != NULL;
2379
8.59k
}
Unexecuted instantiation: ssl_mcnf.c:ssl_has_cert
Unexecuted instantiation: ssl_rsa.c:ssl_has_cert
Unexecuted instantiation: ssl_sess.c:ssl_has_cert
t1_lib.c:ssl_has_cert
Line
Count
Source
2374
11.1k
{
2375
11.1k
    if (idx < 0 || idx >= SSL_PKEY_NUM)
2376
0
        return 0;
2377
11.1k
    return s->cert->pkeys[idx].x509 != NULL
2378
11.1k
        && s->cert->pkeys[idx].privatekey != NULL;
2379
11.1k
}
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: rec_layer_d1.c:ssl_has_cert
Unexecuted instantiation: rec_layer_s3.c:ssl_has_cert
Unexecuted instantiation: ssl3_buffer.c:ssl_has_cert
Unexecuted instantiation: ssl3_record.c:ssl_has_cert
Unexecuted instantiation: ssl3_record_tls13.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
statem_lib.c:ssl_has_cert
Line
Count
Source
2374
3.58k
{
2375
3.58k
    if (idx < 0 || idx >= SSL_PKEY_NUM)
2376
0
        return 0;
2377
3.58k
    return s->cert->pkeys[idx].x509 != NULL
2378
3.58k
        && s->cert->pkeys[idx].privatekey != NULL;
2379
3.58k
}
Unexecuted instantiation: statem_srvr.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: 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: dtls1_bitmap.c:ssl_has_cert
Unexecuted instantiation: ssl_txt.c:ssl_has_cert
2380
2381
static ossl_inline void tls1_get_peer_groups(SSL *s, const uint16_t **pgroups,
2382
    size_t *pgroupslen)
2383
81.0k
{
2384
81.0k
    *pgroups = s->ext.peer_supportedgroups;
2385
81.0k
    *pgroupslen = s->ext.peer_supportedgroups_len;
2386
81.0k
}
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
t1_lib.c:tls1_get_peer_groups
Line
Count
Source
2383
76.2k
{
2384
76.2k
    *pgroups = s->ext.peer_supportedgroups;
2385
76.2k
    *pgroupslen = s->ext.peer_supportedgroups_len;
2386
76.2k
}
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: rec_layer_d1.c:tls1_get_peer_groups
Unexecuted instantiation: rec_layer_s3.c:tls1_get_peer_groups
Unexecuted instantiation: ssl3_buffer.c:tls1_get_peer_groups
Unexecuted instantiation: ssl3_record.c:tls1_get_peer_groups
Unexecuted instantiation: ssl3_record_tls13.c:tls1_get_peer_groups
extensions.c:tls1_get_peer_groups
Line
Count
Source
2383
393
{
2384
393
    *pgroups = s->ext.peer_supportedgroups;
2385
393
    *pgroupslen = s->ext.peer_supportedgroups_len;
2386
393
}
Unexecuted instantiation: extensions_clnt.c:tls1_get_peer_groups
Unexecuted instantiation: extensions_cust.c:tls1_get_peer_groups
extensions_srvr.c:tls1_get_peer_groups
Line
Count
Source
2383
4.37k
{
2384
4.37k
    *pgroups = s->ext.peer_supportedgroups;
2385
4.37k
    *pgroupslen = s->ext.peer_supportedgroups_len;
2386
4.37k
}
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: 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: 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: dtls1_bitmap.c:tls1_get_peer_groups
Unexecuted instantiation: ssl_txt.c:tls1_get_peer_groups
2387
2388
#ifndef OPENSSL_UNIT_TEST
2389
2390
__owur int ssl_read_internal(SSL *s, void *buf, size_t num, size_t *readbytes);
2391
__owur int ssl_write_internal(SSL *s, const void *buf, size_t num, size_t *written);
2392
void ssl_clear_cipher_ctx(SSL *s);
2393
int ssl_clear_bad_session(SSL *s);
2394
__owur CERT *ssl_cert_new(void);
2395
__owur CERT *ssl_cert_dup(CERT *cert);
2396
void ssl_cert_clear_certs(CERT *c);
2397
void ssl_cert_free(CERT *c);
2398
__owur int ssl_generate_session_id(SSL *s, SSL_SESSION *ss);
2399
__owur int ssl_get_new_session(SSL *s, int session);
2400
__owur SSL_SESSION *lookup_sess_in_cache(SSL *s, const unsigned char *sess_id,
2401
    size_t sess_id_len);
2402
__owur int ssl_get_prev_session(SSL *s, CLIENTHELLO_MSG *hello);
2403
__owur SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket);
2404
__owur int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
2405
DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
2406
__owur int ssl_cipher_ptr_id_cmp(const SSL_CIPHER *const *ap,
2407
    const SSL_CIPHER *const *bp);
2408
__owur STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,
2409
    STACK_OF(SSL_CIPHER) *tls13_ciphersuites,
2410
    STACK_OF(SSL_CIPHER) **cipher_list,
2411
    STACK_OF(SSL_CIPHER) **cipher_list_by_id,
2412
    const char *rule_str,
2413
    CERT *c);
2414
__owur int ssl_cache_cipherlist(SSL *s, PACKET *cipher_suites, int sslv2format);
2415
__owur int bytes_to_cipher_list(SSL *s, PACKET *cipher_suites,
2416
    STACK_OF(SSL_CIPHER) **skp,
2417
    STACK_OF(SSL_CIPHER) **scsvs, int sslv2format,
2418
    int fatal);
2419
void ssl_update_cache(SSL *s, int mode);
2420
__owur int ssl_cipher_get_evp_cipher(SSL_CTX *ctx, const SSL_CIPHER *sslc,
2421
    const EVP_CIPHER **enc);
2422
__owur int ssl_cipher_get_evp(SSL_CTX *ctxc, const SSL_SESSION *s,
2423
    const EVP_CIPHER **enc, const EVP_MD **md,
2424
    int *mac_pkey_type, size_t *mac_secret_size,
2425
    SSL_COMP **comp, int use_etm);
2426
__owur int ssl_cipher_get_overhead(const SSL_CIPHER *c, size_t *mac_overhead,
2427
    size_t *int_overhead, size_t *blocksize,
2428
    size_t *ext_overhead);
2429
__owur int ssl_cert_is_disabled(SSL_CTX *ctx, size_t idx);
2430
__owur const SSL_CIPHER *ssl_get_cipher_by_char(SSL *ssl,
2431
    const unsigned char *ptr,
2432
    int all);
2433
__owur int ssl_cert_set0_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain);
2434
__owur int ssl_cert_set1_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain);
2435
__owur int ssl_cert_add0_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x);
2436
__owur int ssl_cert_add1_chain_cert(SSL *s, SSL_CTX *ctx, X509 *x);
2437
__owur int ssl_cert_select_current(CERT *c, X509 *x);
2438
__owur int ssl_cert_set_current(CERT *c, long arg);
2439
void ssl_cert_set_cert_cb(CERT *c, int (*cb)(SSL *ssl, void *arg), void *arg);
2440
2441
__owur int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk);
2442
__owur int ssl_build_cert_chain(SSL *s, SSL_CTX *ctx, int flags);
2443
__owur int ssl_cert_set_cert_store(CERT *c, X509_STORE *store, int chain,
2444
    int ref);
2445
__owur int ssl_cert_get_cert_store(CERT *c, X509_STORE **pstore, int chain);
2446
2447
__owur int ssl_security(const SSL *s, int op, int bits, int nid, void *other);
2448
__owur int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid,
2449
    void *other);
2450
int ssl_get_security_level_bits(const SSL *s, const SSL_CTX *ctx, int *levelp);
2451
2452
__owur int ssl_cert_lookup_by_nid(int nid, size_t *pidx);
2453
__owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_pkey(const EVP_PKEY *pk,
2454
    size_t *pidx);
2455
__owur const SSL_CERT_LOOKUP *ssl_cert_lookup_by_idx(size_t idx);
2456
2457
int ssl_undefined_function(SSL *s);
2458
__owur int ssl_undefined_void_function(void);
2459
__owur int ssl_undefined_const_function(const SSL *s);
2460
__owur int ssl_get_server_cert_serverinfo(SSL *s,
2461
    const unsigned char **serverinfo,
2462
    size_t *serverinfo_length);
2463
void ssl_set_masks(SSL *s);
2464
__owur STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
2465
__owur int ssl_x509err2alert(int type);
2466
void ssl_sort_cipher_list(void);
2467
int ssl_load_ciphers(SSL_CTX *ctx);
2468
__owur int ssl_setup_sig_algs(SSL_CTX *ctx);
2469
int ssl_load_groups(SSL_CTX *ctx);
2470
__owur int ssl_fill_hello_random(SSL *s, int server, unsigned char *field,
2471
    size_t len, DOWNGRADE dgrd);
2472
__owur int ssl_generate_master_secret(SSL *s, unsigned char *pms, size_t pmslen,
2473
    int free_pms);
2474
__owur EVP_PKEY *ssl_generate_pkey(SSL *s, EVP_PKEY *pm);
2475
__owur int ssl_gensecret(SSL *s, unsigned char *pms, size_t pmslen);
2476
__owur int ssl_derive(SSL *s, EVP_PKEY *privkey, EVP_PKEY *pubkey,
2477
    int genmaster);
2478
__owur int ssl_decapsulate(SSL *s, EVP_PKEY *privkey,
2479
    const unsigned char *ct, size_t ctlen,
2480
    int gensecret);
2481
__owur int ssl_encapsulate(SSL *s, EVP_PKEY *pubkey,
2482
    unsigned char **ctp, size_t *ctlenp,
2483
    int gensecret);
2484
__owur EVP_PKEY *ssl_dh_to_pkey(DH *dh);
2485
__owur int ssl_set_tmp_ecdh_groups(uint16_t **pext, size_t *pextlen,
2486
    void *key);
2487
__owur unsigned int ssl_get_max_send_fragment(const SSL *ssl);
2488
__owur unsigned int ssl_get_split_send_fragment(const SSL *ssl);
2489
2490
__owur const SSL_CIPHER *ssl3_get_cipher_by_id(uint32_t id);
2491
__owur const SSL_CIPHER *ssl3_get_cipher_by_std_name(const char *stdname);
2492
__owur const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
2493
__owur int ssl3_put_cipher_by_char(const SSL_CIPHER *c, WPACKET *pkt,
2494
    size_t *len);
2495
int ssl3_init_finished_mac(SSL *s);
2496
__owur int ssl3_setup_key_block(SSL *s);
2497
__owur int ssl3_change_cipher_state(SSL *s, int which);
2498
void ssl3_cleanup_key_block(SSL *s);
2499
__owur int ssl3_do_write(SSL *s, int type);
2500
int ssl3_send_alert(SSL *s, int level, int desc);
2501
__owur int ssl3_generate_master_secret(SSL *s, unsigned char *out,
2502
    unsigned char *p, size_t len,
2503
    size_t *secret_size);
2504
__owur int ssl3_get_req_cert_type(SSL *s, WPACKET *pkt);
2505
__owur int ssl3_num_ciphers(void);
2506
__owur const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
2507
int ssl3_renegotiate(SSL *ssl);
2508
int ssl3_renegotiate_check(SSL *ssl, int initok);
2509
void ssl3_digest_master_key_set_params(const SSL_SESSION *session,
2510
    OSSL_PARAM params[]);
2511
__owur int ssl3_dispatch_alert(SSL *s);
2512
__owur size_t ssl3_final_finish_mac(SSL *s, const char *sender, size_t slen,
2513
    unsigned char *p);
2514
__owur int ssl3_finish_mac(SSL *s, const unsigned char *buf, size_t len);
2515
void ssl3_free_digest_list(SSL *s);
2516
__owur unsigned long ssl3_output_cert_chain(SSL *s, WPACKET *pkt,
2517
    CERT_PKEY *cpk);
2518
__owur const SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,
2519
    STACK_OF(SSL_CIPHER) *clnt,
2520
    STACK_OF(SSL_CIPHER) *srvr);
2521
__owur int ssl3_digest_cached_records(SSL *s, int keep);
2522
__owur int ssl3_new(SSL *s);
2523
void ssl3_free(SSL *s);
2524
__owur int ssl3_read(SSL *s, void *buf, size_t len, size_t *readbytes);
2525
__owur int ssl3_peek(SSL *s, void *buf, size_t len, size_t *readbytes);
2526
__owur int ssl3_write(SSL *s, const void *buf, size_t len, size_t *written);
2527
__owur int ssl3_shutdown(SSL *s);
2528
int ssl3_clear(SSL *s);
2529
__owur long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
2530
__owur long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
2531
__owur long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
2532
__owur long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
2533
2534
__owur int ssl3_do_change_cipher_spec(SSL *ssl);
2535
__owur long ssl3_default_timeout(void);
2536
2537
__owur int ssl3_set_handshake_header(SSL *s, WPACKET *pkt, int htype);
2538
__owur int tls_close_construct_packet(SSL *s, WPACKET *pkt, int htype);
2539
__owur int tls_setup_handshake(SSL *s);
2540
__owur int dtls1_set_handshake_header(SSL *s, WPACKET *pkt, int htype);
2541
__owur int dtls1_close_construct_packet(SSL *s, WPACKET *pkt, int htype);
2542
__owur int ssl3_handshake_write(SSL *s);
2543
2544
__owur int ssl_allow_compression(SSL *s);
2545
2546
__owur int ssl_version_supported(const SSL *s, int version,
2547
    const SSL_METHOD **meth);
2548
2549
__owur int ssl_set_client_hello_version(SSL *s);
2550
__owur int ssl_check_version_downgrade(SSL *s);
2551
__owur int ssl_set_version_bound(int method_version, int version, int *bound);
2552
__owur int ssl_choose_server_version(SSL *s, CLIENTHELLO_MSG *hello,
2553
    DOWNGRADE *dgrd);
2554
__owur int ssl_choose_client_version(SSL *s, int version,
2555
    RAW_EXTENSION *extensions);
2556
__owur int ssl_get_min_max_version(const SSL *s, int *min_version,
2557
    int *max_version, int *real_max);
2558
2559
__owur long tls1_default_timeout(void);
2560
__owur int dtls1_do_write(SSL *s, int type);
2561
void dtls1_set_message_header(SSL *s,
2562
    unsigned char mt,
2563
    size_t len,
2564
    size_t frag_off, size_t frag_len);
2565
2566
int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, size_t len,
2567
    size_t *written);
2568
2569
__owur int dtls1_read_failed(SSL *s, int code);
2570
__owur int dtls1_buffer_message(SSL *s, int ccs);
2571
__owur int dtls1_retransmit_message(SSL *s, unsigned short seq, int *found);
2572
__owur int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
2573
int dtls1_retransmit_buffered_messages(SSL *s);
2574
void dtls1_clear_received_buffer(SSL *s);
2575
void dtls1_clear_sent_buffer(SSL *s);
2576
void dtls1_get_message_header(unsigned char *data,
2577
    struct hm_header_st *msg_hdr);
2578
__owur long dtls1_default_timeout(void);
2579
__owur struct timeval *dtls1_get_timeout(SSL *s, struct timeval *timeleft);
2580
__owur int dtls1_check_timeout_num(SSL *s);
2581
__owur int dtls1_handle_timeout(SSL *s);
2582
void dtls1_start_timer(SSL *s);
2583
void dtls1_stop_timer(SSL *s);
2584
__owur int dtls1_is_timer_expired(SSL *s);
2585
__owur int dtls_raw_hello_verify_request(WPACKET *pkt, unsigned char *cookie,
2586
    size_t cookie_len);
2587
__owur size_t dtls1_min_mtu(SSL *s);
2588
void dtls1_hm_fragment_free(hm_fragment *frag);
2589
__owur int dtls1_query_mtu(SSL *s);
2590
2591
__owur int tls1_new(SSL *s);
2592
void tls1_free(SSL *s);
2593
int tls1_clear(SSL *s);
2594
2595
__owur int dtls1_new(SSL *s);
2596
void dtls1_free(SSL *s);
2597
int dtls1_clear(SSL *s);
2598
long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
2599
__owur int dtls1_shutdown(SSL *s);
2600
2601
__owur int dtls1_dispatch_alert(SSL *s);
2602
2603
__owur int ssl_init_wbio_buffer(SSL *s);
2604
int ssl_free_wbio_buffer(SSL *s);
2605
2606
__owur int tls1_change_cipher_state(SSL *s, int which);
2607
__owur int tls1_setup_key_block(SSL *s);
2608
__owur size_t tls1_final_finish_mac(SSL *s, const char *str, size_t slen,
2609
    unsigned char *p);
2610
__owur int tls1_generate_master_secret(SSL *s, unsigned char *out,
2611
    unsigned char *p, size_t len,
2612
    size_t *secret_size);
2613
__owur int tls13_setup_key_block(SSL *s);
2614
__owur size_t tls13_final_finish_mac(SSL *s, const char *str, size_t slen,
2615
    unsigned char *p);
2616
__owur int tls13_change_cipher_state(SSL *s, int which);
2617
__owur int tls13_update_key(SSL *s, int send);
2618
__owur int tls13_hkdf_expand(SSL *s, const EVP_MD *md,
2619
    const unsigned char *secret,
2620
    const unsigned char *label, size_t labellen,
2621
    const unsigned char *data, size_t datalen,
2622
    unsigned char *out, size_t outlen, int fatal);
2623
__owur int tls13_derive_key(SSL *s, const EVP_MD *md,
2624
    const unsigned char *secret, unsigned char *key,
2625
    size_t keylen);
2626
__owur int tls13_derive_iv(SSL *s, const EVP_MD *md,
2627
    const unsigned char *secret, unsigned char *iv,
2628
    size_t ivlen);
2629
__owur int tls13_derive_finishedkey(SSL *s, const EVP_MD *md,
2630
    const unsigned char *secret,
2631
    unsigned char *fin, size_t finlen);
2632
int tls13_generate_secret(SSL *s, const EVP_MD *md,
2633
    const unsigned char *prevsecret,
2634
    const unsigned char *insecret,
2635
    size_t insecretlen,
2636
    unsigned char *outsecret);
2637
__owur int tls13_generate_handshake_secret(SSL *s,
2638
    const unsigned char *insecret,
2639
    size_t insecretlen);
2640
__owur int tls13_generate_master_secret(SSL *s, unsigned char *out,
2641
    unsigned char *prev, size_t prevlen,
2642
    size_t *secret_size);
2643
__owur int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
2644
    const char *label, size_t llen,
2645
    const unsigned char *p, size_t plen,
2646
    int use_context);
2647
__owur int tls13_export_keying_material(SSL *s, unsigned char *out, size_t olen,
2648
    const char *label, size_t llen,
2649
    const unsigned char *context,
2650
    size_t contextlen, int use_context);
2651
__owur int tls13_export_keying_material_early(SSL *s, unsigned char *out,
2652
    size_t olen, const char *label,
2653
    size_t llen,
2654
    const unsigned char *context,
2655
    size_t contextlen);
2656
__owur int tls1_alert_code(int code);
2657
__owur int tls13_alert_code(int code);
2658
__owur int ssl3_alert_code(int code);
2659
2660
__owur int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s);
2661
2662
SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
2663
2664
__owur const TLS_GROUP_INFO *tls1_group_id_lookup(SSL_CTX *ctx, uint16_t curve_id);
2665
__owur int tls1_group_id2nid(uint16_t group_id, int include_unknown);
2666
__owur uint16_t tls1_nid2group_id(int nid);
2667
__owur int tls1_check_group_id(SSL *s, uint16_t group_id, int check_own_curves);
2668
__owur uint16_t tls1_shared_group(SSL *s, int nmatch);
2669
__owur int tls1_set_groups(uint16_t **pext, size_t *pextlen,
2670
    int *curves, size_t ncurves);
2671
__owur int tls1_set_groups_list(SSL_CTX *ctx, uint16_t **pext, size_t *pextlen,
2672
    const char *str);
2673
__owur EVP_PKEY *ssl_generate_pkey_group(SSL *s, uint16_t id);
2674
__owur int tls_valid_group(SSL *s, uint16_t group_id, int minversion,
2675
    int maxversion, int isec, int *okfortls13);
2676
__owur EVP_PKEY *ssl_generate_param_group(SSL *s, uint16_t id);
2677
void tls1_get_formatlist(SSL *s, const unsigned char **pformats,
2678
    size_t *num_formats);
2679
__owur int tls1_check_ec_tmp_key(SSL *s, unsigned long id);
2680
2681
__owur int tls_group_allowed(SSL *s, uint16_t curve, int op);
2682
void tls1_get_supported_groups(SSL *s, const uint16_t **pgroups,
2683
    size_t *pgroupslen);
2684
2685
__owur int tls1_set_server_sigalgs(SSL *s);
2686
2687
__owur SSL_TICKET_STATUS tls_get_ticket_from_client(SSL *s, CLIENTHELLO_MSG *hello,
2688
    SSL_SESSION **ret);
2689
__owur SSL_TICKET_STATUS tls_decrypt_ticket(SSL *s, const unsigned char *etick,
2690
    size_t eticklen,
2691
    const unsigned char *sess_id,
2692
    size_t sesslen, SSL_SESSION **psess);
2693
2694
__owur int tls_use_ticket(SSL *s);
2695
2696
void ssl_set_sig_mask(uint32_t *pmask_a, SSL *s, int op);
2697
2698
__owur int tls1_set_sigalgs_list(CERT *c, const char *str, int client);
2699
__owur int tls1_set_raw_sigalgs(CERT *c, const uint16_t *psigs, size_t salglen,
2700
    int client);
2701
__owur int tls1_set_sigalgs(CERT *c, const int *salg, size_t salglen,
2702
    int client);
2703
int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
2704
    int idx);
2705
void tls1_set_cert_validity(SSL *s);
2706
2707
#ifndef OPENSSL_NO_CT
2708
__owur int ssl_validate_ct(SSL *s);
2709
#endif
2710
2711
__owur EVP_PKEY *ssl_get_auto_dh(SSL *s);
2712
2713
__owur int ssl_security_cert(SSL *s, SSL_CTX *ctx, X509 *x, int vfy, int is_ee);
2714
__owur int ssl_security_cert_chain(SSL *s, STACK_OF(X509) *sk, X509 *ex,
2715
    int vfy);
2716
2717
int tls_choose_sigalg(SSL *s, int fatalerrs);
2718
2719
__owur EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md);
2720
void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
2721
__owur long ssl_get_algorithm2(SSL *s);
2722
__owur int tls12_copy_sigalgs(SSL *s, WPACKET *pkt,
2723
    const uint16_t *psig, size_t psiglen);
2724
__owur int tls1_save_u16(PACKET *pkt, uint16_t **pdest, size_t *pdestlen);
2725
__owur int tls1_save_sigalgs(SSL *s, PACKET *pkt, int cert);
2726
__owur int tls1_process_sigalgs(SSL *s);
2727
__owur int tls1_set_peer_legacy_sigalg(SSL *s, const EVP_PKEY *pkey);
2728
__owur int tls1_lookup_md(SSL_CTX *ctx, const SIGALG_LOOKUP *lu,
2729
    const EVP_MD **pmd);
2730
__owur size_t tls12_get_psigalgs(SSL *s, int sent, const uint16_t **psigs);
2731
__owur int tls_check_sigalg_curve(const SSL *s, int curve);
2732
__owur int tls12_check_peer_sigalg(SSL *s, uint16_t, EVP_PKEY *pkey);
2733
__owur int ssl_set_client_disabled(SSL *s);
2734
__owur int ssl_cipher_disabled(const SSL *s, const SSL_CIPHER *c, int op, int echde);
2735
2736
__owur int ssl_handshake_hash(SSL *s, unsigned char *out, size_t outlen,
2737
    size_t *hashlen);
2738
__owur const EVP_MD *ssl_md(SSL_CTX *ctx, int idx);
2739
__owur const EVP_MD *ssl_handshake_md(SSL *s);
2740
__owur const EVP_MD *ssl_prf_md(SSL *s);
2741
2742
/*
2743
 * ssl_log_rsa_client_key_exchange logs |premaster| to the SSL_CTX associated
2744
 * with |ssl|, if logging is enabled. It returns one on success and zero on
2745
 * failure. The entry is identified by the first 8 bytes of
2746
 * |encrypted_premaster|.
2747
 */
2748
__owur int ssl_log_rsa_client_key_exchange(SSL *ssl,
2749
    const uint8_t *encrypted_premaster,
2750
    size_t encrypted_premaster_len,
2751
    const uint8_t *premaster,
2752
    size_t premaster_len);
2753
2754
/*
2755
 * ssl_log_secret logs |secret| to the SSL_CTX associated with |ssl|, if
2756
 * logging is available. It returns one on success and zero on failure. It tags
2757
 * the entry with |label|.
2758
 */
2759
__owur int ssl_log_secret(SSL *ssl, const char *label,
2760
    const uint8_t *secret, size_t secret_len);
2761
2762
1.24k
#define MASTER_SECRET_LABEL "CLIENT_RANDOM"
2763
0
#define CLIENT_EARLY_LABEL "CLIENT_EARLY_TRAFFIC_SECRET"
2764
495
#define CLIENT_HANDSHAKE_LABEL "CLIENT_HANDSHAKE_TRAFFIC_SECRET"
2765
578
#define SERVER_HANDSHAKE_LABEL "SERVER_HANDSHAKE_TRAFFIC_SECRET"
2766
0
#define CLIENT_APPLICATION_LABEL "CLIENT_TRAFFIC_SECRET_0"
2767
0
#define CLIENT_APPLICATION_N_LABEL "CLIENT_TRAFFIC_SECRET_N"
2768
495
#define SERVER_APPLICATION_LABEL "SERVER_TRAFFIC_SECRET_0"
2769
0
#define SERVER_APPLICATION_N_LABEL "SERVER_TRAFFIC_SECRET_N"
2770
0
#define EARLY_EXPORTER_SECRET_LABEL "EARLY_EXPORTER_SECRET"
2771
495
#define EXPORTER_SECRET_LABEL "EXPORTER_SECRET"
2772
2773
#ifndef OPENSSL_NO_KTLS
2774
/* ktls.c */
2775
int ktls_check_supported_cipher(const SSL *s, const EVP_CIPHER *c,
2776
    const EVP_CIPHER_CTX *dd);
2777
int ktls_configure_crypto(const SSL *s, const EVP_CIPHER *c, EVP_CIPHER_CTX *dd,
2778
    void *rl_sequence, ktls_crypto_info_t *crypto_info,
2779
    unsigned char **rec_seq, unsigned char *iv,
2780
    unsigned char *key, unsigned char *mac_key,
2781
    size_t mac_secret_size);
2782
#endif
2783
2784
/* s3_cbc.c */
2785
__owur char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
2786
__owur int ssl3_cbc_digest_record(const EVP_MD *md,
2787
    unsigned char *md_out,
2788
    size_t *md_out_size,
2789
    const unsigned char *header,
2790
    const unsigned char *data,
2791
    size_t data_size,
2792
    size_t data_plus_mac_plus_padding_size,
2793
    const unsigned char *mac_secret,
2794
    size_t mac_secret_length, char is_sslv3);
2795
2796
__owur int srp_generate_server_master_secret(SSL *s);
2797
__owur int srp_generate_client_master_secret(SSL *s);
2798
__owur int srp_verify_server_param(SSL *s);
2799
2800
/* statem/statem_srvr.c */
2801
2802
__owur int send_certificate_request(SSL *s);
2803
2804
/* statem/extensions_cust.c */
2805
2806
custom_ext_method *custom_ext_find(const custom_ext_methods *exts,
2807
    ENDPOINT role, unsigned int ext_type,
2808
    size_t *idx);
2809
2810
void custom_ext_init(custom_ext_methods *meths);
2811
2812
__owur int custom_ext_parse(SSL *s, unsigned int context, unsigned int ext_type,
2813
    const unsigned char *ext_data, size_t ext_size,
2814
    X509 *x, size_t chainidx);
2815
__owur int custom_ext_add(SSL *s, int context, WPACKET *pkt, X509 *x,
2816
    size_t chainidx, int maxversion);
2817
2818
__owur int custom_exts_copy(custom_ext_methods *dst,
2819
    const custom_ext_methods *src);
2820
__owur int custom_exts_copy_flags(custom_ext_methods *dst,
2821
    const custom_ext_methods *src);
2822
void custom_exts_free(custom_ext_methods *exts);
2823
2824
void ssl_comp_free_compression_methods_int(void);
2825
2826
/* ssl_mcnf.c */
2827
void ssl_ctx_system_config(SSL_CTX *ctx);
2828
2829
const EVP_CIPHER *ssl_evp_cipher_fetch(OSSL_LIB_CTX *libctx,
2830
    int nid,
2831
    const char *properties);
2832
int ssl_evp_cipher_up_ref(const EVP_CIPHER *cipher);
2833
void ssl_evp_cipher_free(const EVP_CIPHER *cipher);
2834
const EVP_MD *ssl_evp_md_fetch(OSSL_LIB_CTX *libctx,
2835
    int nid,
2836
    const char *properties);
2837
int ssl_evp_md_up_ref(const EVP_MD *md);
2838
void ssl_evp_md_free(const EVP_MD *md);
2839
2840
int tls_provider_set_tls_params(SSL *s, EVP_CIPHER_CTX *ctx,
2841
    const EVP_CIPHER *ciph,
2842
    const EVP_MD *md);
2843
2844
void tls_engine_finish(ENGINE *e);
2845
const EVP_CIPHER *tls_get_cipher_from_engine(int nid);
2846
const EVP_MD *tls_get_digest_from_engine(int nid);
2847
int tls_engine_load_ssl_client_cert(SSL *s, X509 **px509, EVP_PKEY **ppkey);
2848
int ssl_hmac_old_new(SSL_HMAC *ret);
2849
void ssl_hmac_old_free(SSL_HMAC *ctx);
2850
int ssl_hmac_old_init(SSL_HMAC *ctx, void *key, size_t len, char *md);
2851
int ssl_hmac_old_update(SSL_HMAC *ctx, const unsigned char *data, size_t len);
2852
int ssl_hmac_old_final(SSL_HMAC *ctx, unsigned char *md, size_t *len);
2853
size_t ssl_hmac_old_size(const SSL_HMAC *ctx);
2854
2855
int ssl_ctx_srp_ctx_free_intern(SSL_CTX *ctx);
2856
int ssl_ctx_srp_ctx_init_intern(SSL_CTX *ctx);
2857
int ssl_srp_ctx_free_intern(SSL *s);
2858
int ssl_srp_ctx_init_intern(SSL *s);
2859
2860
int ssl_srp_calc_a_param_intern(SSL *s);
2861
int ssl_srp_server_param_with_username_intern(SSL *s, int *ad);
2862
2863
void ssl_session_calculate_timeout(SSL_SESSION *ss);
2864
2865
#else /* OPENSSL_UNIT_TEST */
2866
2867
#define ssl_init_wbio_buffer SSL_test_functions()->p_ssl_init_wbio_buffer
2868
#define ssl3_setup_buffers SSL_test_functions()->p_ssl3_setup_buffers
2869
2870
#endif
2871
2872
/* Some helper routines to support TSAN operations safely */
2873
static ossl_unused ossl_inline int ssl_tsan_lock(const SSL_CTX *ctx)
2874
214k
{
2875
#ifdef TSAN_REQUIRES_LOCKING
2876
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2877
        return 0;
2878
#endif
2879
214k
    return 1;
2880
214k
}
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
ssl_lib.c:ssl_tsan_lock
Line
Count
Source
2874
1.46k
{
2875
#ifdef TSAN_REQUIRES_LOCKING
2876
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2877
        return 0;
2878
#endif
2879
1.46k
    return 1;
2880
1.46k
}
Unexecuted instantiation: ssl_mcnf.c:ssl_tsan_lock
Unexecuted instantiation: ssl_rsa.c:ssl_tsan_lock
ssl_sess.c:ssl_tsan_lock
Line
Count
Source
2874
3.96k
{
2875
#ifdef TSAN_REQUIRES_LOCKING
2876
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2877
        return 0;
2878
#endif
2879
3.96k
    return 1;
2880
3.96k
}
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: rec_layer_d1.c:ssl_tsan_lock
Unexecuted instantiation: rec_layer_s3.c:ssl_tsan_lock
Unexecuted instantiation: ssl3_buffer.c:ssl_tsan_lock
Unexecuted instantiation: ssl3_record.c:ssl_tsan_lock
Unexecuted instantiation: ssl3_record_tls13.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
statem_clnt.c:ssl_tsan_lock
Line
Count
Source
2874
50
{
2875
#ifdef TSAN_REQUIRES_LOCKING
2876
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2877
        return 0;
2878
#endif
2879
50
    return 1;
2880
50
}
Unexecuted instantiation: statem_dtls.c:ssl_tsan_lock
statem_lib.c:ssl_tsan_lock
Line
Count
Source
2874
208k
{
2875
#ifdef TSAN_REQUIRES_LOCKING
2876
    if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2877
        return 0;
2878
#endif
2879
208k
    return 1;
2880
208k
}
Unexecuted instantiation: statem_srvr.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: 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: dtls1_bitmap.c:ssl_tsan_lock
Unexecuted instantiation: ssl_txt.c:ssl_tsan_lock
2881
2882
static ossl_unused ossl_inline void ssl_tsan_unlock(const SSL_CTX *ctx)
2883
214k
{
2884
#ifdef TSAN_REQUIRES_LOCKING
2885
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
2886
#endif
2887
214k
}
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
ssl_lib.c:ssl_tsan_unlock
Line
Count
Source
2883
1.46k
{
2884
#ifdef TSAN_REQUIRES_LOCKING
2885
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
2886
#endif
2887
1.46k
}
Unexecuted instantiation: ssl_mcnf.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_rsa.c:ssl_tsan_unlock
ssl_sess.c:ssl_tsan_unlock
Line
Count
Source
2883
3.96k
{
2884
#ifdef TSAN_REQUIRES_LOCKING
2885
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
2886
#endif
2887
3.96k
}
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: rec_layer_d1.c:ssl_tsan_unlock
Unexecuted instantiation: rec_layer_s3.c:ssl_tsan_unlock
Unexecuted instantiation: ssl3_buffer.c:ssl_tsan_unlock
Unexecuted instantiation: ssl3_record.c:ssl_tsan_unlock
Unexecuted instantiation: ssl3_record_tls13.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
statem_clnt.c:ssl_tsan_unlock
Line
Count
Source
2883
50
{
2884
#ifdef TSAN_REQUIRES_LOCKING
2885
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
2886
#endif
2887
50
}
Unexecuted instantiation: statem_dtls.c:ssl_tsan_unlock
statem_lib.c:ssl_tsan_unlock
Line
Count
Source
2883
208k
{
2884
#ifdef TSAN_REQUIRES_LOCKING
2885
    CRYPTO_THREAD_unlock(ctx->tsan_lock);
2886
#endif
2887
208k
}
Unexecuted instantiation: statem_srvr.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: 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: dtls1_bitmap.c:ssl_tsan_unlock
Unexecuted instantiation: ssl_txt.c:ssl_tsan_unlock
2888
2889
static ossl_unused ossl_inline void ssl_tsan_counter(const SSL_CTX *ctx,
2890
    TSAN_QUALIFIER int *stat)
2891
212k
{
2892
212k
    if (ssl_tsan_lock(ctx)) {
2893
        tsan_counter(stat);
2894
212k
        ssl_tsan_unlock(ctx);
2895
212k
    }
2896
212k
}
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
ssl_sess.c:ssl_tsan_counter
Line
Count
Source
2891
3.96k
{
2892
3.96k
    if (ssl_tsan_lock(ctx)) {
2893
        tsan_counter(stat);
2894
3.96k
        ssl_tsan_unlock(ctx);
2895
3.96k
    }
2896
3.96k
}
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: rec_layer_d1.c:ssl_tsan_counter
Unexecuted instantiation: rec_layer_s3.c:ssl_tsan_counter
Unexecuted instantiation: ssl3_buffer.c:ssl_tsan_counter
Unexecuted instantiation: ssl3_record.c:ssl_tsan_counter
Unexecuted instantiation: ssl3_record_tls13.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
statem_clnt.c:ssl_tsan_counter
Line
Count
Source
2891
50
{
2892
50
    if (ssl_tsan_lock(ctx)) {
2893
        tsan_counter(stat);
2894
50
        ssl_tsan_unlock(ctx);
2895
50
    }
2896
50
}
Unexecuted instantiation: statem_dtls.c:ssl_tsan_counter
statem_lib.c:ssl_tsan_counter
Line
Count
Source
2891
208k
{
2892
208k
    if (ssl_tsan_lock(ctx)) {
2893
        tsan_counter(stat);
2894
208k
        ssl_tsan_unlock(ctx);
2895
208k
    }
2896
208k
}
Unexecuted instantiation: statem_srvr.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: 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: dtls1_bitmap.c:ssl_tsan_counter
Unexecuted instantiation: ssl_txt.c:ssl_tsan_counter
2897
2898
#endif