LCOV - code coverage report
Current view: top level - tls/extensions - s2n_extension_type.h (source / functions) Hit Total Coverage
Test: unit_test_coverage.info Lines: 1 1 100.0 %
Date: 2025-08-14 07:26:07 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License").
       5                 :            :  * You may not use this file except in compliance with the License.
       6                 :            :  * A copy of the License is located at
       7                 :            :  *
       8                 :            :  *  http://aws.amazon.com/apache2.0
       9                 :            :  *
      10                 :            :  * or in the "license" file accompanying this file. This file is distributed
      11                 :            :  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
      12                 :            :  * express or implied. See the License for the specific language governing
      13                 :            :  * permissions and limitations under the License.
      14                 :            :  */
      15                 :            : 
      16                 :            : #pragma once
      17                 :            : 
      18                 :            : #include <stdbool.h>
      19                 :            : 
      20                 :            : #include "stuffer/s2n_stuffer.h"
      21                 :            : #include "tls/s2n_tls_parameters.h"
      22                 :            : 
      23                 :            : #define S2N_EXTENSION_TYPE_FIELD_LENGTH   2
      24                 :            : #define S2N_EXTENSION_LENGTH_FIELD_LENGTH 2
      25                 :            : #define S2N_EXTENSION_HEADER_LENGTH       (S2N_EXTENSION_TYPE_FIELD_LENGTH + S2N_EXTENSION_LENGTH_FIELD_LENGTH)
      26                 :            : 
      27                 :            : /* The number of extensions supported by S2N */
      28                 :     682626 : #define S2N_SUPPORTED_EXTENSIONS_COUNT (sizeof(s2n_supported_extensions) / sizeof(s2n_supported_extensions[0]))
      29                 :            : 
      30                 :            : /* The number of bytes needed to assign 1 bit to every supported extension.
      31                 :            :  * The +1 is necessary to handle any remainder left over when dividing. */
      32                 :            : #define S2N_SUPPORTED_EXTENSIONS_BITFIELD_LEN ((S2N_SUPPORTED_EXTENSIONS_COUNT / sizeof(char)) + 1)
      33                 :            : 
      34                 :            : struct s2n_connection;
      35                 :            : typedef struct {
      36                 :            :     uint16_t iana_value;
      37                 :            :     unsigned is_response : 1;
      38                 :            :     uint16_t minimum_version;
      39                 :            : 
      40                 :            :     int (*send)(struct s2n_connection *conn, struct s2n_stuffer *out);
      41                 :            :     int (*recv)(struct s2n_connection *conn, struct s2n_stuffer *in);
      42                 :            : 
      43                 :            :     /* Returns true or false to indicate whether the extension should be sent */
      44                 :            :     bool (*should_send)(struct s2n_connection *conn);
      45                 :            : 
      46                 :            :     /* Handler called if an extension is not received */
      47                 :            :     int (*if_missing)(struct s2n_connection *conn);
      48                 :            : } s2n_extension_type;
      49                 :            : 
      50                 :            : static const uint16_t s2n_supported_extensions[] = {
      51                 :            :     TLS_EXTENSION_RENEGOTIATION_INFO,
      52                 :            :     TLS_EXTENSION_PQ_KEM_PARAMETERS,
      53                 :            :     TLS_EXTENSION_SERVER_NAME,
      54                 :            :     TLS_EXTENSION_MAX_FRAG_LEN,
      55                 :            :     TLS_EXTENSION_STATUS_REQUEST,
      56                 :            :     TLS_EXTENSION_SUPPORTED_GROUPS,
      57                 :            :     TLS_EXTENSION_EC_POINT_FORMATS,
      58                 :            :     TLS_EXTENSION_SIGNATURE_ALGORITHMS,
      59                 :            :     TLS_EXTENSION_ALPN,
      60                 :            :     TLS_EXTENSION_SCT_LIST,
      61                 :            :     TLS_EXTENSION_SESSION_TICKET,
      62                 :            :     TLS_EXTENSION_SUPPORTED_VERSIONS,
      63                 :            :     TLS_EXTENSION_KEY_SHARE,
      64                 :            :     TLS_EXTENSION_COOKIE,
      65                 :            :     TLS_EXTENSION_QUIC_TRANSPORT_PARAMETERS,
      66                 :            :     TLS_EXTENSION_PSK_KEY_EXCHANGE_MODES,
      67                 :            :     TLS_EXTENSION_PRE_SHARED_KEY,
      68                 :            :     TLS_EXTENSION_EARLY_DATA,
      69                 :            :     TLS_EXTENSION_EMS,
      70                 :            :     TLS_EXTENSION_NPN,
      71                 :            :     TLS_EXTENSION_CERT_AUTHORITIES,
      72                 :            : };
      73                 :            : 
      74                 :            : typedef char s2n_extension_bitfield[S2N_SUPPORTED_EXTENSIONS_BITFIELD_LEN];
      75                 :            : 
      76                 :            : typedef uint8_t s2n_extension_type_id;
      77                 :            : extern const s2n_extension_type_id s2n_unsupported_extension;
      78                 :            : 
      79                 :            : int s2n_extension_send(const s2n_extension_type *extension_type, struct s2n_connection *conn, struct s2n_stuffer *out);
      80                 :            : int s2n_extension_recv(const s2n_extension_type *extension_type, struct s2n_connection *conn, struct s2n_stuffer *in);
      81                 :            : int s2n_extension_is_missing(const s2n_extension_type *extension_type, struct s2n_connection *conn);
      82                 :            : 
      83                 :            : /* Map from TLS IANA value to internal s2n id.
      84                 :            :  * All possible IANA values is a large space, so using an internal id gives us more
      85                 :            :  * flexibility when using arrays / bitfields / etc. */
      86                 :            : int s2n_extension_supported_iana_value_to_id(const uint16_t iana_value, s2n_extension_type_id *internal_id);
      87                 :            : 
      88                 :            : /* Initializer */
      89                 :            : int s2n_extension_type_init();
      90                 :            : 
      91                 :            : /* Common implementations for send */
      92                 :            : int s2n_extension_send_unimplemented(struct s2n_connection *conn, struct s2n_stuffer *out);
      93                 :            : int s2n_extension_send_noop(struct s2n_connection *conn, struct s2n_stuffer *out);
      94                 :            : 
      95                 :            : /* Common implementations for recv */
      96                 :            : int s2n_extension_recv_unimplemented(struct s2n_connection *conn, struct s2n_stuffer *in);
      97                 :            : int s2n_extension_recv_noop(struct s2n_connection *conn, struct s2n_stuffer *out);
      98                 :            : 
      99                 :            : /* Common implementations for should_send */
     100                 :            : bool s2n_extension_always_send(struct s2n_connection *conn);
     101                 :            : bool s2n_extension_never_send(struct s2n_connection *conn);
     102                 :            : bool s2n_extension_send_if_tls13_connection(struct s2n_connection *conn);
     103                 :            : 
     104                 :            : /* Common implementations for if_missing */
     105                 :            : int s2n_extension_error_if_missing(struct s2n_connection *conn);
     106                 :            : int s2n_extension_noop_if_missing(struct s2n_connection *conn);

Generated by: LCOV version 1.14