Skip to content

Commit

Permalink
remove commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred2g committed Jun 13, 2024
1 parent 19fa6da commit bafa0bc
Showing 1 changed file with 25 additions and 89 deletions.
114 changes: 25 additions & 89 deletions tests/tls_handler_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,44 +1199,27 @@ static int s_verify_good_host_mqtt_connect(

ASSERT_SUCCESS(s_tls_common_tester_init(allocator, &c_tester));

/* ****** NEW ********/
uint8_t outgoing_received_message[128] = {0};

// const uint8_t mqtt_connect_message[] = {

// 0x10, /* connect */
// 0x10,/*packet length */
// 0x00, 0x04,/* protocol name length */
// 0x4d, 0x51, 0x54, 0x54,/* MQTT */
// 0x04,/* protocol version 4 (3.11) */
// 0x02,/* connect flags */
// 0x00, 0x3c,/* keep alive */
// 0x00, 0x04, 't', 'e', 's', 't' /* client id(size (2) + data(4) */
//};

const uint8_t mqtt_connect_message[] = {
0x10, 0x51, 0x00, 0x04, 0x4D, 0x51, 0x54, 0x54, 0x04, 0x80, 0x03, 0xE8, 0x00, 0x29, 0x74, 0x65, 0x73,
0x74, 0x2D, 0x30, 0x62, 0x34, 0x37, 0x36, 0x30, 0x64, 0x35, 0x2D, 0x62, 0x61, 0x39, 0x63, 0x2D, 0x38,
0x65, 0x66, 0x64, 0x2D, 0x33, 0x32, 0x65, 0x37, 0x2D, 0x34, 0x38, 0x64, 0x30, 0x35, 0x62, 0x62, 0x32,
0x30, 0x30, 0x65, 0x61, 0x00, 0x1A, 0x3F, 0x53, 0x44, 0x4B, 0x3D, 0x43, 0x50, 0x50, 0x76, 0x32, 0x26,
0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x76, 0x31, 0x2E, 0x33, 0x32, 0x2E, 0x36
};

/*
const uint8_t mqtt_connect_message[] = {
0x10, 0x51, 0x00, 0x04, 0x4D, 0x51, 0x54, 0x54, 0x04, 0x80,
0x03, 0xE8, 0x00, 0x29, 0x74, 0x65, 0x73, 0x74, 0x2D, 0x35,
0x62, 0x39, 0x39, 0x36, 0x61, 0x62, 0x63, 0x2D, 0x63, 0x30,
0x38, 0x31, 0x2D, 0x37, 0x36, 0x31, 0x37, 0x2D, 0x64, 0x31,
0x34, 0x33, 0x2D, 0x64, 0x33, 0x35, 0x66, 0x37, 0x32, 0x65,
0x37, 0x36, 0x39, 0x64, 0x62, 0x00, 0x1A, 0x3F, 0x53, 0x44,
0x4B, 0x3D, 0x43, 0x50, 0x50, 0x76, 0x32, 0x26, 0x56, 0x65,
0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x76, 0x31, 0x2E, 0x33,
0x32, 0x2E, 0x36, 0x00
0x10, /* connect packet */
0x51, /* packet length */
0x00, 0x04, /* protocol name length */
0x4D, 0x51, 0x54, 0x54, /* M Q T T */
0x04, /* protocol version 3.11 = 4 */
0x82, /* connect flags user name + clean session */
0x03, 0xE8, // keep alive
0x00, 0x29, /* client id size */
0x74, 0x65, 0x73, 0x74, 0x2D, 0x30, 0x62, 0x34, 0x37, 0x36,
0x30, 0x64, 0x35, 0x2D, 0x62, 0x61, 0x39, 0x63, 0x2D, 0x38,
0x65, 0x66, 0x64, 0x2D, 0x33, 0x32, 0x65, 0x37, 0x2D, 0x34,
0x38, 0x64, 0x30, 0x35, 0x62, 0x62, 0x32, 0x30, 0x30, 0x65,
0x61, /* client id */
0x00, 0x1A, /* user name length */
0x3F, 0x53, 0x44, 0x4B, 0x3D, 0x43, 0x50, 0x50, 0x76, 0x32,
0x26, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x76,
0x31, 0x2E, 0x33, 0x32, 0x2E, 0x36 /* user name */
};
*/

// const uint8_t mqtt_connect_message[] = {'a', 'l', 'f', 'r', 'e', 'd', 0x00, 0x02, 0x01};

struct aws_byte_buf write_tag = aws_byte_buf_from_array((const char*)mqtt_connect_message, 83);

Expand All @@ -1251,8 +1234,6 @@ static int s_verify_good_host_mqtt_connect(
true, write_tag.len, &outgoing_rw_args);
ASSERT_NOT_NULL(outgoing_rw_handler);

/* end new */

struct tls_test_args outgoing_args = {
.mutex = &c_tester.mutex,
.allocator = allocator,
Expand Down Expand Up @@ -1283,18 +1264,14 @@ static int s_verify_good_host_mqtt_connect(
aws_tls_connection_options_set_callbacks(
&tls_client_conn_options, s_tls_on_negotiated, NULL, NULL, &outgoing_args);

/* ***** new ****** */
struct aws_byte_buf cert_buf = {0};
struct aws_byte_buf key_buf = {0};
struct aws_byte_buf ca_buf = {0};
struct aws_tls_ctx_options tls_options = {0};
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&cert_buf, allocator, "ed384_server.pem"));
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&key_buf, allocator, "ed384_key.pem"));
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&ca_buf, allocator, "AmazonRootCA1.pem"));

// ASSERT_SUCCESS(aws_byte_buf_init_from_file(&cert_buf, allocator, "server_EC384.pem"));
// ASSERT_SUCCESS(aws_byte_buf_init_from_file(&key_buf, allocator, "server_EC384.key"));
//ASSERT_SUCCESS(aws_byte_buf_init_from_file(&ca_buf, allocator, "ca.pem"));
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&cert_buf, allocator, "ed384_server.pem"));
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&key_buf, allocator, "ed384_key.pem"));
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&ca_buf, allocator, "AmazonRootCA1.pem"));

struct aws_byte_cursor cert_cur = aws_byte_cursor_from_buf(&cert_buf);
struct aws_byte_cursor key_cur = aws_byte_cursor_from_buf(&key_buf);
Expand All @@ -1307,10 +1284,7 @@ static int s_verify_good_host_mqtt_connect(

struct aws_tls_ctx *tls_context = aws_tls_client_ctx_new(allocator, &tls_options);
ASSERT_NOT_NULL(tls_context);
/* new */
tls_client_conn_options.ctx = tls_context;
/* new */
/* ***** new ****** */

struct aws_byte_cursor host_name_cur = aws_byte_cursor_from_string(host_name);
aws_tls_connection_options_set_server_name(&tls_client_conn_options, allocator, &host_name_cur);
Expand Down Expand Up @@ -1354,8 +1328,6 @@ static int s_verify_good_host_mqtt_connect(
ASSERT_FALSE(outgoing_args.error_invoked);
struct aws_byte_buf expected_protocol = aws_byte_buf_from_c_str("x-amzn-mqtt-ca");
/* check ALPN and SNI was properly negotiated */


if (aws_tls_is_alpn_available() && client_ctx_options.verify_peer) {
ASSERT_BIN_ARRAYS_EQUALS(
expected_protocol.buffer,
Expand All @@ -1364,19 +1336,12 @@ static int s_verify_good_host_mqtt_connect(
outgoing_args.negotiated_protocol.len);
}

ASSERT_BIN_ARRAYS_EQUALS(
host_name->bytes, host_name->len, outgoing_args.server_name.buffer, outgoing_args.server_name.len);

// ASSERT_BIN_ARRAYS_EQUALS(
// host_name->bytes, host_name->len, outgoing_args.server_name.buffer, outgoing_args.server_name.len);


/* XXX: ---- new ----*/
/* Do the IO operations */
printf(" ============================================= doing the io operaion \n");
outgoing_rw_args.invocation_happened = false;
rw_handler_write(outgoing_args.rw_handler, outgoing_args.rw_slot, &write_tag);


printf(" ============================================= waiting to read data \n");
ASSERT_SUCCESS(aws_mutex_lock(&c_tester.mutex));

ASSERT_SUCCESS(aws_condition_variable_wait_pred(
Expand All @@ -1386,36 +1351,13 @@ static int s_verify_good_host_mqtt_connect(
ASSERT_SUCCESS(aws_mutex_unlock(&c_tester.mutex));

aws_mutex_lock(outgoing_rw_args.mutex);
printf("=====================================printing message received message buffer\n");
for (size_t i = 0; i < outgoing_rw_args.received_message.len; i++) {
printf(" %.2X ", outgoing_rw_args.received_message.buffer[i]);
}
printf("\n");
//printf("conn ack is %d\n", outgoing_rw_args.received_message.buffer[3]);

ASSERT_INT_EQUALS(0x20, outgoing_rw_args.received_message.buffer[0]); /* conn ack */
ASSERT_INT_EQUALS(0x02, outgoing_rw_args.received_message.buffer[1]); /* conn ack */
ASSERT_INT_EQUALS(0x01, outgoing_rw_args.received_message.buffer[2]); /* conn ack */
ASSERT_INT_EQUALS(0x00, outgoing_rw_args.received_message.buffer[3]); /* conn ack */
ASSERT_INT_EQUALS(0x02, outgoing_rw_args.received_message.buffer[1]);
ASSERT_INT_EQUALS(0x00, outgoing_rw_args.received_message.buffer[2]); /* clean session */
ASSERT_INT_EQUALS(0x00, outgoing_rw_args.received_message.buffer[3]);
aws_mutex_unlock(outgoing_rw_args.mutex);

//ASSERT_INT_EQUALS('0', outgoing_rw_args.received_message.buffer[0]); /* conn ack */
//ASSERT_INT_EQUALS('0', outgoing_rw_args.received_message.buffer[1]); /* conn ack */
//ASSERT_INT_EQUALS('0', outgoing_rw_args.received_message.buffer[2]); /* conn ack */
printf(" ============================================= data read\n");

//outgoing_rw_args.invocation_happened = false;
//ASSERT_INT_EQUALS(1, outgoing_rw_args.read_invocations);

/*
struct aws_byte_cursor cert_cur = aws_byte_cursor_from_buf(&cert_buf);
struct aws_byte_cursor key_cur = aws_byte_cursor_from_buf(&key_buf);
struct aws_byte_cursor ca_cur = aws_byte_cursor_from_buf(&ca_buf);
*/
/* ---- */

printf(" ======================================================= freeing memory\n");

ASSERT_SUCCESS(aws_mutex_lock(&c_tester.mutex));
aws_channel_shutdown(outgoing_args.channel, AWS_OP_SUCCESS);
ASSERT_SUCCESS(aws_condition_variable_wait_pred(
Expand All @@ -1428,7 +1370,6 @@ static int s_verify_good_host_mqtt_connect(
aws_tls_ctx_release(client_ctx);
aws_tls_ctx_release(client_ctx);
aws_tls_ctx_release(tls_context->impl);
//aws_tls_ctx_release(tls_context->impl);

aws_tls_ctx_options_clean_up(&tls_options);

Expand Down Expand Up @@ -1465,15 +1406,10 @@ static int s_tls_client_channel_negotiation_success_ecc384_fn(struct aws_allocat
}

AWS_TEST_CASE(tls_client_channel_negotiation_success_ecc384, s_tls_client_channel_negotiation_success_ecc384_fn)

//AWS_STATIC_STRING_FROM_LITERAL(s_aws_ecc384_host_name, "a2w1wmp9234lcw-ats.iot.us-west-2.amazonaws.com");
//AWS_STATIC_STRING_FROM_LITERAL(s_aws_ecc384_host_name, "192.168.1.152"); /* mosuquitto/openssl local server */
AWS_STATIC_STRING_FROM_LITERAL(s_aws_ecc384_host_name, "a2yvr5l8sc9814-ats.iot.us-east-2.amazonaws.com");
//AWS_STATIC_STRING_FROM_LITERAL(s_aws_ecc384_host_name, "172.17.48.219"); /* s2n windows wsl */

static int s_tls_client_channel_negotiation_success_ecc384_tls1_3_fn(struct aws_allocator *allocator, void *ctx) {
(void)ctx;
//return s_verify_good_host_mqtt_connect(allocator, s_aws_ecc384_host_name, 8883, NULL);
return s_verify_good_host_mqtt_connect(allocator, s_aws_ecc384_host_name, 443, NULL);
}

Expand Down

0 comments on commit bafa0bc

Please sign in to comment.