| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "utils/s2n_events.h" |
| 17 |
|
| 18 |
#include <math.h> |
| 19 |
#include <stdlib.h> |
| 20 |
|
| 21 |
#include "error/s2n_errno.h" |
| 22 |
#include "s2n_test.h" |
| 23 |
#include "testlib/s2n_testlib.h" |
| 24 |
#include "tls/s2n_connection.h" |
| 25 |
#include "tls/s2n_post_handshake.h" |
| 26 |
#include "tls/s2n_tls.h" |
| 27 |
#include "utils/s2n_safety.h" |
| 28 |
|
| 29 |
struct event_subscriber { |
| 30 |
uint64_t invoked; |
| 31 |
}; |
| 32 |
|
| 33 |
void subscriber_on_handshake_complete( |
| 34 |
struct s2n_connection *conn, |
| 35 |
void *subscriber, |
| 36 |
struct s2n_event_handshake *event) |
| 37 |
{ |
| 38 |
struct event_subscriber *sub = (struct event_subscriber *) subscriber; |
| 39 |
sub->invoked++; |
| 40 |
} |
| 41 |
|
| 42 |
int main(int argc, char **argv) |
| 43 |
{ |
| 44 |
BEGIN_TEST(); |
| 45 |
|
| 46 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 47 |
struct event_subscriber subscriber = { 0 }; |
| 48 |
s2n_config_set_subscriber(config, &subscriber); |
| 49 |
s2n_config_set_handshake_event(config, subscriber_on_handshake_complete); |
| 50 |
|
| 51 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free); |
| 52 |
s2n_connection_set_config(conn, config); |
| 53 |
|
| 54 |
|
| 55 |
conn->secure->cipher_suite = &s2n_ecdhe_ecdsa_with_chacha20_poly1305_sha256; |
| 56 |
conn->kex_params.server_ecc_evp_params.negotiated_curve = &s2n_ecc_curve_secp521r1; |
| 57 |
conn->actual_protocol_version = S2N_TLS12; |
| 58 |
EXPECT_OK(s2n_handshake_type_set_flag(conn, FULL_HANDSHAKE)); |
| 59 |
|
| 60 |
|
| 61 |
{ |
| 62 |
struct s2n_event_handshake event = { 0 }; |
| 63 |
EXPECT_OK(s2n_event_handshake_populate(conn, &event)); |
| 64 |
EXPECT_EQUAL(strcmp(event.cipher, "ECDHE-ECDSA-CHACHA20-POLY1305"), 0); |
| 65 |
EXPECT_EQUAL(strcmp(event.group, "secp521r1"), 0); |
| 66 |
EXPECT_EQUAL(event.protocol_version, S2N_TLS12); |
| 67 |
|
| 68 |
EXPECT_EQUAL(event.handshake_end_ns, 0); |
| 69 |
EXPECT_EQUAL(event.handshake_start_ns, 0); |
| 70 |
EXPECT_EQUAL(event.handshake_time_ns, 0); |
| 71 |
|
| 72 |
EXPECT_EQUAL(event.error_code, 0); |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
{ |
| 77 |
struct s2n_event_handshake event = { 0 }; |
| 78 |
EXPECT_OK(s2n_event_handshake_send(conn, &event)); |
| 79 |
EXPECT_EQUAL(subscriber.invoked, 1); |
| 80 |
EXPECT_EQUAL(event.handshake_start_ns, HANDSHAKE_EVENT_SENT); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
EXPECT_OK(s2n_event_handshake_send(conn, &event)); |
| 85 |
EXPECT_EQUAL(subscriber.invoked, 1); |
| 86 |
} |
| 87 |
|
| 88 |
END_TEST(); |
| 89 |
} |