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