Skip to content

Commit

Permalink
Update s2n_connection_get_kem_group_name() to work with ClientHelloRe… (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexw91 authored Jul 18, 2024
1 parent b20075b commit 533b502
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/unit/s2n_tls13_pq_handshake_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ int s2n_test_tls13_pq_handshake(const struct s2n_security_policy *client_sec_pol
POSIX_ENSURE_EQ(expected_kem_group->kem, server_conn->kex_params.server_kem_group_params.kem_params.kem);
POSIX_ENSURE_EQ(expected_kem_group->curve, server_conn->kex_params.server_kem_group_params.ecc_params.negotiated_curve);
POSIX_ENSURE_EQ(NULL, server_conn->kex_params.server_ecc_evp_params.negotiated_curve);

/* Ensure s2n_connection_get_kem_group_name() gives the correct answer for both client and server */
POSIX_ENSURE_EQ(strlen(expected_kem_group->name), strlen(s2n_connection_get_kem_group_name(server_conn)));
POSIX_ENSURE_EQ(memcmp(expected_kem_group->name, s2n_connection_get_kem_group_name(server_conn), strlen(expected_kem_group->name)), 0);
POSIX_ENSURE_EQ(strlen(expected_kem_group->name), strlen(s2n_connection_get_kem_group_name(client_conn)));
POSIX_ENSURE_EQ(memcmp(expected_kem_group->name, s2n_connection_get_kem_group_name(client_conn), strlen(expected_kem_group->name)), 0);
} else {
POSIX_ENSURE_EQ(NULL, client_conn->kex_params.server_kem_group_params.kem_group);
POSIX_ENSURE_EQ(NULL, client_conn->kex_params.server_kem_group_params.kem_params.kem);
Expand All @@ -247,6 +253,12 @@ int s2n_test_tls13_pq_handshake(const struct s2n_security_policy *client_sec_pol
POSIX_ENSURE_EQ(NULL, server_conn->kex_params.server_kem_group_params.kem_params.kem);
POSIX_ENSURE_EQ(NULL, server_conn->kex_params.server_kem_group_params.ecc_params.negotiated_curve);
POSIX_ENSURE_EQ(expected_curve, server_conn->kex_params.server_ecc_evp_params.negotiated_curve);

/* Ensure s2n_connection_get_curve() gives the correct answer for both client and server */
POSIX_ENSURE_EQ(strlen(expected_curve->name), strlen(s2n_connection_get_curve(server_conn)));
POSIX_ENSURE_EQ(memcmp(expected_curve->name, s2n_connection_get_curve(server_conn), strlen(expected_curve->name)), 0);
POSIX_ENSURE_EQ(strlen(expected_curve->name), strlen(s2n_connection_get_curve(client_conn)));
POSIX_ENSURE_EQ(memcmp(expected_curve->name, s2n_connection_get_curve(client_conn), strlen(expected_curve->name)), 0);
}

/* Verify basic properties of secrets */
Expand Down
4 changes: 2 additions & 2 deletions tls/s2n_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,11 @@ const char *s2n_connection_get_kem_group_name(struct s2n_connection *conn)
{
PTR_ENSURE_REF(conn);

if (conn->actual_protocol_version < S2N_TLS13 || !conn->kex_params.client_kem_group_params.kem_group) {
if (conn->actual_protocol_version < S2N_TLS13 || !conn->kex_params.server_kem_group_params.kem_group) {
return "NONE";
}

return conn->kex_params.client_kem_group_params.kem_group->name;
return conn->kex_params.server_kem_group_params.kem_group->name;
}

static S2N_RESULT s2n_connection_get_client_supported_version(struct s2n_connection *conn,
Expand Down

0 comments on commit 533b502

Please sign in to comment.