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