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_connection.h" 19 : : 20 : : /** 21 : : * Populate handshake information at the end of the handshake. 22 : : * 23 : : * Precondition: handshake timing information is already completed 24 : : */ 25 : : S2N_RESULT s2n_event_handshake_populate(struct s2n_connection *conn, struct s2n_event_handshake *event) 26 : 16204 : { 27 [ - + ][ # # ]: 16204 : RESULT_ENSURE_REF(event); 28 : : 29 : 16204 : event->protocol_version = s2n_connection_get_actual_protocol_version(conn); 30 : 16204 : event->cipher = s2n_connection_get_cipher(conn); 31 : : /* get_key_group is expected to fail in cases where a group is not negotiated, 32 : : * e.g. RSA key exchange. In this case event->group will be null. */ 33 : 16204 : s2n_connection_get_key_exchange_group(conn, &event->group); 34 : 16204 : return S2N_RESULT_OK; 35 : 16204 : } 36 : : 37 : : /** 38 : : * Send the completed handshake event by calling the appropriate method 39 : : * on the subscriber. 40 : : * 41 : : * If there is no subscriber on the config this method is a no-op 42 : : */ 43 : : S2N_RESULT s2n_event_handshake_send(struct s2n_connection *conn, struct s2n_event_handshake *event) 44 : 16205 : { 45 [ - + ][ # # ]: 16205 : RESULT_ENSURE_REF(conn); 46 [ # # ][ - + ]: 16205 : RESULT_ENSURE_REF(conn->config); 47 [ - + ][ # # ]: 16205 : RESULT_ENSURE_REF(event); 48 : : 49 [ + + ][ - + ]: 16205 : if (conn->config->subscriber == NULL || conn->config->on_handshake_event == NULL) { 50 : 16203 : return S2N_RESULT_OK; 51 : 16203 : } 52 : : 53 : : /* the event has already been sent */ 54 [ + + ]: 2 : if (event->handshake_start_ns == HANDSHAKE_EVENT_SENT) { 55 : 1 : return S2N_RESULT_OK; 56 : 1 : } 57 : : 58 : 1 : conn->config->on_handshake_event(conn, conn->config->subscriber, event); 59 : 1 : event->handshake_start_ns = HANDSHAKE_EVENT_SENT; 60 : 1 : return S2N_RESULT_OK; 61 : 2 : }