Skip to content

Commit

Permalink
test wip
Browse files Browse the repository at this point in the history
  • Loading branch information
goatgoose committed Sep 20, 2023
1 parent 3530f04 commit 033891a
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions tests/unit/s2n_client_hello_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,8 +1634,12 @@ int main(int argc, char **argv)

/* s2n_client_hello_get_supported_groups tests */
{
/* 2 length bytes + space for the maximum number of supported groups */
#define TEST_SUPPORTED_GROUPS_EXTENSION_SIZE (2 + (S2N_RECEIVED_SUPPORTED_GROUPS_MAX * 2))

/* Each supported group is 2 bytes. */
#define TEST_SUPPORTED_GROUPS_LIST_SIZE (S2N_RECEIVED_SUPPORTED_GROUPS_MAX * 2)

/* 2 length bytes + space for the maximum number of supported groups. */
#define TEST_SUPPORTED_GROUPS_EXTENSION_SIZE (2 + TEST_SUPPORTED_GROUPS_LIST_SIZE)

/* Safety */
{
Expand Down Expand Up @@ -1677,8 +1681,7 @@ int main(int argc, char **argv)
struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));

uint16_t maximum_groups_size = S2N_RECEIVED_SUPPORTED_GROUPS_MAX * 2;
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&extension_stuffer, maximum_groups_size));
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&extension_stuffer, TEST_SUPPORTED_GROUPS_LIST_SIZE));

uint16_t supported_groups[S2N_RECEIVED_SUPPORTED_GROUPS_MAX] = { 0 };
uint16_t supported_groups_count = 0;
Expand Down Expand Up @@ -1772,8 +1775,7 @@ int main(int argc, char **argv)
struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));

uint16_t maximum_groups_size = S2N_RECEIVED_SUPPORTED_GROUPS_MAX * 2;
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&extension_stuffer, maximum_groups_size));
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&extension_stuffer, TEST_SUPPORTED_GROUPS_LIST_SIZE));

uint16_t supported_groups[S2N_RECEIVED_SUPPORTED_GROUPS_MAX] = { 0 };
uint16_t supported_groups_count = 0;
Expand All @@ -1793,7 +1795,7 @@ int main(int argc, char **argv)
struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));

uint16_t too_many_groups_size = (S2N_RECEIVED_SUPPORTED_GROUPS_MAX + 1) * 2;
uint16_t too_many_groups_size = TEST_SUPPORTED_GROUPS_LIST_SIZE + 2;
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&extension_stuffer, too_many_groups_size));

uint16_t supported_groups[S2N_RECEIVED_SUPPORTED_GROUPS_MAX] = { 0 };
Expand Down Expand Up @@ -1829,10 +1831,42 @@ int main(int argc, char **argv)
}

/* Ensure that s2n_client_hello_get_supported_groups writes what is contained in the parsed
* extension in the client hello.
* supported groups extension in the client hello.
*/
{
struct s2n_client_hello client_hello = { 0 };

s2n_extension_type_id supported_groups_id = 0;
EXPECT_SUCCESS(s2n_extension_supported_iana_value_to_id(S2N_EXTENSION_SUPPORTED_GROUPS, &supported_groups_id));

s2n_parsed_extension *supported_groups_extension = &client_hello.extensions.parsed_extensions[supported_groups_id];
supported_groups_extension->extension_type = S2N_EXTENSION_SUPPORTED_GROUPS;

for (uint16_t groups_count = 0; groups_count < S2N_RECEIVED_SUPPORTED_GROUPS_MAX; groups_count++) {
uint16_t groups_list_size = groups_count * 2;

uint8_t test_groups_list_data[TEST_SUPPORTED_GROUPS_LIST_SIZE] = { 0 };
struct s2n_blob test_groups_list_data_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&test_groups_list_data_blob, test_groups_list_data, groups_list_size));
EXPECT_OK(s2n_get_public_random_data(&test_groups_list_data_blob));

uint8_t extension_data[TEST_SUPPORTED_GROUPS_EXTENSION_SIZE] = { 0 };
struct s2n_blob extension_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&extension_blob, extension_data, sizeof(extension_data)));
supported_groups_extension->extension = extension_blob;

struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&extension_stuffer, groups_list_size));
EXPECT_SUCCESS(s2n_stuffer_write(&extension_stuffer, &test_groups_list_data_blob));

uint16_t supported_groups[S2N_RECEIVED_SUPPORTED_GROUPS_MAX] = { 0 };
uint16_t supported_groups_count = 0;
EXPECT_SUCCESS(s2n_client_hello_get_supported_groups(&client_hello, supported_groups,
&supported_groups_count, S2N_RECEIVED_SUPPORTED_GROUPS_MAX));

EXPECT_EQUAL(supported_groups_count)
}
}

/* Self-talk: Ensure that the retrieved supported groups match what was sent by the client.
Expand Down

0 comments on commit 033891a

Please sign in to comment.