Skip to content

Commit

Permalink
clang
Browse files Browse the repository at this point in the history
  • Loading branch information
maddeleine committed Jul 16, 2024
1 parent ce8f060 commit 5adaf40
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/unit/s2n_resume_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,9 +1291,9 @@ int main(int argc, char **argv)
/* Check error is thrown when no ticket key is available */
{
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER),
s2n_connection_ptr_free);
s2n_connection_ptr_free);
EXPECT_ERROR_WITH_ERRNO(s2n_resume_encrypt_session_ticket(conn, &conn->client_ticket_to_decrypt),
S2N_ERR_NO_TICKET_ENCRYPT_DECRYPT_KEY);
S2N_ERR_NO_TICKET_ENCRYPT_DECRYPT_KEY);
}

/* Check encrypted data can be decrypted correctly for TLS12 */
Expand Down
94 changes: 94 additions & 0 deletions tests/unit/s2n_resumption_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include "s2n_test.h"
#include "testlib/s2n_testlib.h"


int main(int argc, char **argv)
{
BEGIN_TEST();

DEFER_CLEANUP(struct s2n_cert_chain_and_key *chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free);
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key,
S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY));

DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new(),
s2n_config_ptr_free);
EXPECT_NOT_NULL(server_config);
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "default_tls13"));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config,
chain_and_key));
EXPECT_OK(s2n_resumption_test_ticket_key_setup(server_config));

DEFER_CLEANUP(struct s2n_config *client_config = s2n_config_new(),
s2n_config_ptr_free);
EXPECT_NOT_NULL(client_config);
EXPECT_SUCCESS(s2n_config_set_session_tickets_onoff(client_config, 1));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "default_tls13"));
EXPECT_SUCCESS(s2n_config_set_verification_ca_location(client_config, S2N_DEFAULT_TEST_CERT_CHAIN, NULL));

{
DEFER_CLEANUP(struct s2n_connection *client = s2n_connection_new(S2N_CLIENT),
s2n_connection_ptr_free);
EXPECT_NOT_NULL(client);
DEFER_CLEANUP(struct s2n_connection *server = s2n_connection_new(S2N_SERVER),
s2n_connection_ptr_free);
EXPECT_NOT_NULL(server);

EXPECT_SUCCESS(s2n_set_server_name(client, "localhost"));

EXPECT_SUCCESS(s2n_connection_set_config(client, client_config));
EXPECT_SUCCESS(s2n_connection_set_config(server, server_config));

DEFER_CLEANUP(struct s2n_test_io_stuffer_pair test_io = { 0 },
s2n_io_stuffer_pair_free);
EXPECT_OK(s2n_io_stuffer_pair_init(&test_io));
EXPECT_OK(s2n_connections_set_io_stuffer_pair(client, server, &test_io));

EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server, client));
EXPECT_EQUAL(client->actual_protocol_version, S2N_TLS13);
EXPECT_EQUAL(server->actual_protocol_version, S2N_TLS13);

uint16_t tickets_sent = 0;
EXPECT_SUCCESS(s2n_connection_get_tickets_sent(server, &tickets_sent));
EXPECT_EQUAL(tickets_sent, 1);

s2n_blocked_status blocked = S2N_NOT_BLOCKED;
uint8_t out = 0;
EXPECT_FAILURE_WITH_ERRNO(s2n_recv(client, &out, 1, &blocked), S2N_ERR_IO_BLOCKED);
uint8_t session_data[S2N_TLS12_SESSION_SIZE] = { 0 };
EXPECT_SUCCESS(s2n_connection_get_session(client, session_data, sizeof(session_data)));

EXPECT_SUCCESS(s2n_connection_wipe(client));
EXPECT_SUCCESS(s2n_connection_wipe(server));

EXPECT_SUCCESS(s2n_connection_set_config(client, client_config));
EXPECT_SUCCESS(s2n_connection_set_config(server, server_config));

EXPECT_SUCCESS(s2n_connection_set_session(client, session_data, sizeof(session_data)));

EXPECT_OK(s2n_connections_set_io_stuffer_pair(client, server, &test_io));

EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server, client));
EXPECT_EQUAL(client->actual_protocol_version, S2N_TLS13);
EXPECT_EQUAL(server->actual_protocol_version, S2N_TLS13);

EXPECT_FALSE(IS_FULL_HANDSHAKE(client));
EXPECT_FALSE(IS_FULL_HANDSHAKE(server));
}

END_TEST();
}

0 comments on commit 5adaf40

Please sign in to comment.