| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <stdint.h> |
| 17 |
#include <unistd.h> |
| 18 |
|
| 19 |
#include "api/s2n.h" |
| 20 |
#include "s2n_test.h" |
| 21 |
#include "testlib/s2n_testlib.h" |
| 22 |
|
| 23 |
#define ZERO_TO_THIRTY_ONE 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, \ |
| 24 |
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F |
| 25 |
|
| 26 |
#define INTERNAL_ERROR_ALERT_HEX 0x50 |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
int main(int argc, char **argv) |
| 34 |
{ |
| 35 |
BEGIN_TEST(); |
| 36 |
EXPECT_SUCCESS(s2n_disable_tls13_in_test()); |
| 37 |
uint8_t client_hello_message[] = { |
| 38 |
|
| 39 |
0x03, 0x03, |
| 40 |
|
| 41 |
ZERO_TO_THIRTY_ONE, |
| 42 |
|
| 43 |
0x20, |
| 44 |
|
| 45 |
ZERO_TO_THIRTY_ONE, |
| 46 |
|
| 47 |
0x00, 0x02, |
| 48 |
|
| 49 |
0x00, 0x3C, |
| 50 |
|
| 51 |
0x01, |
| 52 |
|
| 53 |
0x00, |
| 54 |
|
| 55 |
0x00, 0x00 |
| 56 |
}; |
| 57 |
size_t body_len = sizeof(client_hello_message); |
| 58 |
uint8_t message_header[] = { |
| 59 |
|
| 60 |
0x01, |
| 61 |
|
| 62 |
(body_len >> 16) & 0xff, |
| 63 |
(body_len >> 8) & 0xff, |
| 64 |
(body_len & 0xff), |
| 65 |
}; |
| 66 |
size_t message_len = sizeof(message_header) + body_len; |
| 67 |
uint8_t record_header[] = { |
| 68 |
|
| 69 |
0x16, |
| 70 |
|
| 71 |
0x03, |
| 72 |
0x03, |
| 73 |
|
| 74 |
(message_len >> 8) & 0xff, |
| 75 |
(message_len & 0xff), |
| 76 |
}; |
| 77 |
|
| 78 |
uint8_t alert_record[] = { |
| 79 |
|
| 80 |
0x15, |
| 81 |
|
| 82 |
0x03, |
| 83 |
0x03, |
| 84 |
|
| 85 |
0x00, |
| 86 |
0x02, |
| 87 |
|
| 88 |
0x02, |
| 89 |
INTERNAL_ERROR_ALERT_HEX, |
| 90 |
}; |
| 91 |
|
| 92 |
struct s2n_connection *server_conn = NULL; |
| 93 |
struct s2n_config *server_config = NULL; |
| 94 |
s2n_blocked_status server_blocked; |
| 95 |
char *cert_chain = malloc(S2N_MAX_TEST_PEM_SIZE); |
| 96 |
char *private_key = malloc(S2N_MAX_TEST_PEM_SIZE); |
| 97 |
struct s2n_cert_chain_and_key *chain_and_key = NULL; |
| 98 |
|
| 99 |
struct s2n_test_io_pair io_pair; |
| 100 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 101 |
|
| 102 |
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER)); |
| 103 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair)); |
| 104 |
|
| 105 |
EXPECT_NOT_NULL(server_config = s2n_config_new()); |
| 106 |
|
| 107 |
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "test_all")); |
| 108 |
EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE)); |
| 109 |
EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE)); |
| 110 |
EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new()); |
| 111 |
EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key)); |
| 112 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key)); |
| 113 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config)); |
| 114 |
|
| 115 |
|
| 116 |
EXPECT_EQUAL(s2n_test_send(io_pair.client, record_header, sizeof(record_header)), sizeof(record_header)); |
| 117 |
EXPECT_EQUAL(s2n_test_send(io_pair.client, message_header, sizeof(message_header)), sizeof(message_header)); |
| 118 |
EXPECT_EQUAL(s2n_test_send(io_pair.client, client_hello_message, sizeof(client_hello_message)), sizeof(client_hello_message)); |
| 119 |
|
| 120 |
|
| 121 |
EXPECT_EQUAL(s2n_test_send(io_pair.client, alert_record, sizeof(alert_record)), sizeof(alert_record)); |
| 122 |
|
| 123 |
|
| 124 |
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_CLIENT)); |
| 125 |
|
| 126 |
|
| 127 |
s2n_negotiate(server_conn, &server_blocked); |
| 128 |
EXPECT_EQUAL(s2n_error_get_type(s2n_errno), S2N_ERR_T_ALERT); |
| 129 |
EXPECT_EQUAL(s2n_connection_get_alert(server_conn), INTERNAL_ERROR_ALERT_HEX); |
| 130 |
|
| 131 |
EXPECT_SUCCESS(s2n_connection_free(server_conn)); |
| 132 |
EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key)); |
| 133 |
EXPECT_SUCCESS(s2n_config_free(server_config)); |
| 134 |
free(cert_chain); |
| 135 |
free(private_key); |
| 136 |
|
| 137 |
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER)); |
| 138 |
|
| 139 |
END_TEST(); |
| 140 |
} |