Debian Codegraph @

crt/s2n/utils/s2n_events.c

raw symbols SCIP
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 {
28 RESULT_ENSURE_REF(event);
29
30 event->protocol_version = s2n_connection_get_actual_protocol_version(conn);
31 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 s2n_connection_get_key_exchange_group(conn, &event->group);
35
36 const struct s2n_security_policy *security_policy = NULL;
37 if (s2n_connection_get_security_policy(conn, &security_policy) == S2N_SUCCESS) {
38 event->security_policy_label = s2n_find_version_from_security_policy(security_policy);
39 }
40
41 return S2N_RESULT_OK;
42 }
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 {
52 RESULT_ENSURE_REF(conn);
53 RESULT_ENSURE_REF(conn->config);
54 RESULT_ENSURE_REF(event);
55
56 if (conn->config->subscriber == NULL || conn->config->on_handshake_event == NULL) {
57 return S2N_RESULT_OK;
58 }
59
60 /* the event has already been sent */
61 if (event->handshake_start_ns == HANDSHAKE_EVENT_SENT) {
62 return S2N_RESULT_OK;
63 }
64
65 conn->config->on_handshake_event(conn, conn->config->subscriber, event);
66 event->handshake_start_ns = HANDSHAKE_EVENT_SENT;
67 return S2N_RESULT_OK;
68 }