LCOV - code coverage report
Current view: top level - tls/extensions - s2n_quic_transport_params.c (source / functions) Hit Total Coverage
Test: unit_test_coverage.info Lines: 28 28 100.0 %
Date: 2025-08-14 07:26:07 Functions: 4 4 100.0 %
Branches: 30 46 65.2 %

           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                 :            : #include "tls/extensions/s2n_quic_transport_params.h"
      17                 :            : 
      18                 :            : #include "stuffer/s2n_stuffer.h"
      19                 :            : #include "tls/s2n_connection.h"
      20                 :            : #include "tls/s2n_tls.h"
      21                 :            : #include "utils/s2n_safety.h"
      22                 :            : 
      23                 :            : /*
      24                 :            :  * The quic_transport_params extension is required by the QUIC protocol to
      25                 :            :  * negotiate additional connection parameters when using S2N.
      26                 :            :  *
      27                 :            :  * This extension should not be sent or received unless using S2N with QUIC.
      28                 :            :  * S2N treats the extension data as opaque bytes and performs no validation.
      29                 :            :  */
      30                 :            : 
      31                 :            : static bool s2n_quic_transport_params_should_send(struct s2n_connection *conn)
      32                 :       9522 : {
      33                 :       9522 :     return s2n_connection_is_quic_enabled(conn);
      34                 :       9522 : }
      35                 :            : 
      36                 :            : static int s2n_quic_transport_params_if_missing(struct s2n_connection *conn)
      37                 :       9101 : {
      38 [ +  + ][ +  - ]:       9101 :     POSIX_ENSURE_REF(conn);
      39 [ -  + ][ #  # ]:       9100 :     POSIX_ENSURE_REF(conn->config);
      40 [ +  + ][ +  - ]:       9100 :     POSIX_ENSURE(!s2n_connection_is_quic_enabled(conn), S2N_ERR_MISSING_EXTENSION);
      41                 :       9099 :     return S2N_SUCCESS;
      42                 :       9100 : }
      43                 :            : 
      44                 :            : static int s2n_quic_transport_params_send(struct s2n_connection *conn, struct s2n_stuffer *out)
      45                 :         24 : {
      46 [ +  + ][ +  - ]:         24 :     POSIX_ENSURE_REF(conn);
      47 [ +  + ][ +  - ]:         23 :     POSIX_ENSURE_REF(out);
      48                 :            : 
      49         [ +  + ]:         22 :     if (conn->our_quic_transport_parameters.size) {
      50         [ -  + ]:          4 :         POSIX_GUARD(s2n_stuffer_write(out, &conn->our_quic_transport_parameters));
      51                 :          4 :     }
      52                 :         22 :     return S2N_SUCCESS;
      53                 :         22 : }
      54                 :            : 
      55                 :            : static int s2n_quic_transport_params_recv(struct s2n_connection *conn, struct s2n_stuffer *extension)
      56                 :         23 : {
      57 [ +  + ][ +  - ]:         23 :     POSIX_ENSURE_REF(conn);
      58 [ +  + ][ +  - ]:         22 :     POSIX_ENSURE_REF(extension);
      59 [ -  + ][ #  # ]:         21 :     POSIX_ENSURE_REF(conn->config);
      60 [ +  + ][ +  - ]:         21 :     POSIX_ENSURE(s2n_connection_is_quic_enabled(conn), S2N_ERR_UNSUPPORTED_EXTENSION);
      61                 :            : 
      62         [ +  + ]:         20 :     if (s2n_stuffer_data_available(extension)) {
      63         [ -  + ]:          4 :         POSIX_GUARD(s2n_alloc(&conn->peer_quic_transport_parameters, s2n_stuffer_data_available(extension)));
      64         [ -  + ]:          4 :         POSIX_GUARD(s2n_stuffer_read(extension, &conn->peer_quic_transport_parameters));
      65                 :          4 :     }
      66                 :         20 :     return S2N_SUCCESS;
      67                 :         20 : }
      68                 :            : 
      69                 :            : const s2n_extension_type s2n_quic_transport_parameters_extension = {
      70                 :            :     .iana_value = TLS_EXTENSION_QUIC_TRANSPORT_PARAMETERS,
      71                 :            :     .minimum_version = S2N_TLS13,
      72                 :            :     .is_response = false,
      73                 :            :     .send = s2n_quic_transport_params_send,
      74                 :            :     .recv = s2n_quic_transport_params_recv,
      75                 :            :     .should_send = s2n_quic_transport_params_should_send,
      76                 :            :     .if_missing = s2n_quic_transport_params_if_missing,
      77                 :            : };

Generated by: LCOV version 1.14