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