LCOV - code coverage report
Current view: top level - utils - s2n_events.c (source / functions) Hit Total Coverage
Test: unit_test_coverage.info Lines: 41 41 100.0 %
Date: 2026-08-22 07:27:53 Functions: 3 3 100.0 %
Branches: 18 38 47.4 %

           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 "utils/s2n_events.h"
      17                 :            : 
      18                 :            : #include "tls/s2n_config.h"
      19                 :            : #include "tls/s2n_connection.h"
      20                 :            : #include "tls/s2n_security_policies.h"
      21                 :            : 
      22                 :            : /**
      23                 :            :  * Populate handshake information at the end of the handshake.
      24                 :            :  * 
      25                 :            :  * Precondition: handshake timing information is already completed
      26                 :            :  */
      27                 :            : S2N_RESULT s2n_event_handshake_populate(struct s2n_connection *conn, struct s2n_event_handshake *event)
      28                 :      20563 : {
      29 [ -  + ][ #  # ]:      20563 :     RESULT_ENSURE_REF(event);
      30                 :            : 
      31                 :      20563 :     event->protocol_version = s2n_connection_get_actual_protocol_version(conn);
      32                 :      20563 :     event->cipher = s2n_connection_get_cipher(conn);
      33                 :            :     /* get_key_group is expected to fail in cases where a group is not negotiated,
      34                 :            :      * e.g. RSA key exchange. In this case event->group will be null. */
      35                 :      20563 :     s2n_connection_get_key_exchange_group(conn, &event->group);
      36                 :            : 
      37                 :      20563 :     const struct s2n_security_policy *security_policy = NULL;
      38         [ +  - ]:      20563 :     if (s2n_connection_get_security_policy(conn, &security_policy) == S2N_SUCCESS) {
      39                 :      20563 :         event->security_policy_label = s2n_find_version_from_security_policy(security_policy);
      40                 :      20563 :     }
      41                 :            : 
      42                 :      20563 :     return S2N_RESULT_OK;
      43                 :      20563 : }
      44                 :            : 
      45                 :            : /**
      46                 :            :  * Send the completed handshake event by calling the appropriate method
      47                 :            :  * on the subscriber.
      48                 :            :  * 
      49                 :            :  * If there is no subscriber on the config this method is a no-op
      50                 :            :  */
      51                 :            : S2N_RESULT s2n_event_handshake_send(struct s2n_connection *conn, struct s2n_event_handshake *event)
      52                 :      20564 : {
      53 [ #  # ][ -  + ]:      20564 :     RESULT_ENSURE_REF(conn);
      54 [ -  + ][ #  # ]:      20564 :     RESULT_ENSURE_REF(conn->config);
      55 [ -  + ][ #  # ]:      20564 :     RESULT_ENSURE_REF(event);
      56                 :            : 
      57 [ +  + ][ +  + ]:      20564 :     if (conn->config->subscriber == NULL || conn->config->on_handshake_event == NULL) {
      58                 :      20562 :         return S2N_RESULT_OK;
      59                 :      20562 :     }
      60                 :            : 
      61                 :            :     /* the event has already been sent */
      62         [ +  + ]:          2 :     if (event->handshake_start_ns == HANDSHAKE_EVENT_SENT) {
      63                 :          1 :         return S2N_RESULT_OK;
      64                 :          1 :     }
      65                 :            : 
      66                 :          1 :     conn->config->on_handshake_event(conn, conn->config->subscriber, event);
      67                 :          1 :     event->handshake_start_ns = HANDSHAKE_EVENT_SENT;
      68                 :          1 :     return S2N_RESULT_OK;
      69                 :          2 : }
      70                 :            : 
      71                 :            : /**
      72                 :            :  * Emit a per-message timing checkpoint.
      73                 :            :  *
      74                 :            :  * No-op if no callback is registered or config is NULL.
      75                 :            :  */
      76                 :            : S2N_RESULT s2n_event_checkpoint_send(struct s2n_connection *conn, const char *name, uint8_t role)
      77                 :     259516 : {
      78 [ -  + ][ #  # ]:     259516 :     RESULT_ENSURE_REF(conn);
      79 [ -  + ][ #  # ]:     259516 :     RESULT_ENSURE_REF(name);
      80                 :            : 
      81 [ +  + ][ +  + ]:     259516 :     if (conn->config == NULL || conn->config->on_timing_checkpoint_cb == NULL) {
      82                 :     259440 :         return S2N_RESULT_OK;
      83                 :     259440 :     }
      84                 :            : 
      85                 :         76 :     uint64_t timestamp_ns = 0;
      86         [ -  + ]:         76 :     RESULT_GUARD_POSIX(s2n_default_monotonic_clock(NULL, &timestamp_ns));
      87                 :            : 
      88                 :         76 :     struct s2n_timing_checkpoint checkpoint = {
      89                 :         76 :         .name = name,
      90                 :         76 :         .role = role,
      91                 :         76 :         .timestamp_ns = timestamp_ns,
      92                 :         76 :     };
      93                 :            : 
      94                 :         76 :     conn->config->on_timing_checkpoint_cb(conn, conn->config->subscriber, &checkpoint);
      95                 :         76 :     return S2N_RESULT_OK;
      96                 :         76 : }

Generated by: LCOV version 1.14