Skip to content

Commit 3a78635

Browse files
authored
Replace tls double channel (awslabs#441)
* Remove test first * Add codebuild job spec that will run downstream integration tests (aws-c-http) that exercise double tls * Add channel API to read from initial handler
1 parent a96cf8d commit 3a78635

File tree

7 files changed

+84
-532
lines changed

7 files changed

+84
-532
lines changed

codebuild/linux-integration-tests.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: 0.2
2+
#this build spec assumes the manylinux1 image for pypi
3+
#additional packages we installed: cmake 3.5, libcrypto 1.1.0j, gcc 4.8.4
4+
phases:
5+
install:
6+
commands:
7+
- add-apt-repository ppa:ubuntu-toolchain-r/test
8+
- apt-get update -y
9+
- apt-get install gcc-7 cmake ninja-build python3 -y
10+
pre_build:
11+
commands:
12+
- export CC=gcc-7
13+
- export BUILDER_VERSION=v0.8.27
14+
- export BUILDER_SOURCE=releases
15+
- export BUILDER_HOST=https://d19elf31gohf1l.cloudfront.net
16+
build:
17+
commands:
18+
- echo Build started on `date`
19+
- aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env.sh /tmp/setup_proxy_test_env.sh
20+
- chmod a+xr /tmp/setup_proxy_test_env.sh
21+
- python3 -c "from urllib.request import urlretrieve; urlretrieve('$BUILDER_HOST/$BUILDER_SOURCE/$BUILDER_VERSION/builder.pyz', 'builder.pyz')"
22+
- python3 builder.pyz build downstream -p aws-c-io --cmake-extra=-DENABLE_PROXY_INTEGRATION_TESTS=ON
23+
post_build:
24+
commands:
25+
- echo Build completed on `date`

include/aws/io/channel.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ struct aws_channel_handler_vtable {
119119
* associated with the channel's handler chain.
120120
*/
121121
void (*gather_statistics)(struct aws_channel_handler *handler, struct aws_array_list *stats_list);
122+
123+
/*
124+
* If this handler represents a source of data (like the socket_handler), then this will trigger a read
125+
* from the data source.
126+
*/
127+
void (*trigger_read)(struct aws_channel_handler *handler);
122128
};
123129

124130
struct aws_channel_handler {
@@ -467,6 +473,15 @@ size_t aws_channel_handler_initial_window_size(struct aws_channel_handler *handl
467473
AWS_IO_API
468474
struct aws_channel_slot *aws_channel_get_first_slot(struct aws_channel *channel);
469475

476+
/**
477+
* A way for external processes to force a read by the data-source channel handler. Necessary in certain cases, like
478+
* when a server channel finishes setting up its initial handlers, a read may have already been triggered on the
479+
* socket (the client's CLIENT_HELLO tls payload, for example) and absent further data/notifications, this data
480+
* would never get processed.
481+
*/
482+
AWS_IO_API
483+
int aws_channel_trigger_read(struct aws_channel *channel);
484+
470485
AWS_EXTERN_C_END
471486

472487
#endif /* AWS_IO_CHANNEL_H */

source/channel.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,3 +1142,29 @@ int aws_channel_set_statistics_handler(struct aws_channel *channel, struct aws_c
11421142
struct aws_event_loop *aws_channel_get_event_loop(struct aws_channel *channel) {
11431143
return channel->loop;
11441144
}
1145+
1146+
int aws_channel_trigger_read(struct aws_channel *channel) {
1147+
if (channel == NULL) {
1148+
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
1149+
}
1150+
1151+
if (!aws_channel_thread_is_callers_thread(channel)) {
1152+
return aws_raise_error(AWS_ERROR_INVALID_STATE);
1153+
}
1154+
1155+
struct aws_channel_slot *slot = channel->first;
1156+
if (slot == NULL) {
1157+
return aws_raise_error(AWS_ERROR_INVALID_STATE);
1158+
}
1159+
1160+
struct aws_channel_handler *handler = slot->handler;
1161+
if (handler == NULL) {
1162+
return aws_raise_error(AWS_ERROR_INVALID_STATE);
1163+
}
1164+
1165+
if (handler->vtable->trigger_read != NULL) {
1166+
handler->vtable->trigger_read(handler);
1167+
}
1168+
1169+
return AWS_OP_SUCCESS;
1170+
}

source/channel_bootstrap.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,16 @@ static inline int s_setup_server_tls(struct server_channel_data *channel_data, s
10851085
}
10861086
}
10871087

1088+
/*
1089+
* Server-side channels can reach this point in execution and actually have the CLIENT_HELLO payload already
1090+
* on the socket in a signalled state, but there was no socket handler or read handler at the time of signal.
1091+
* So we need to manually trigger a read here to cover that case, otherwise the negotiation will time out because
1092+
* we will not receive any more data/notifications (unless we read and react).
1093+
*/
1094+
if (aws_channel_trigger_read(channel)) {
1095+
return AWS_OP_ERR;
1096+
}
1097+
10881098
return AWS_OP_SUCCESS;
10891099
}
10901100

source/socket_channel_handler.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,19 @@ static void s_reset_statistics(struct aws_channel_handler *handler) {
348348
aws_crt_statistics_socket_reset(&socket_handler->stats);
349349
}
350350

351-
void s_gather_statistics(struct aws_channel_handler *handler, struct aws_array_list *stats_list) {
351+
static void s_gather_statistics(struct aws_channel_handler *handler, struct aws_array_list *stats_list) {
352352
struct socket_handler *socket_handler = (struct socket_handler *)handler->impl;
353353

354354
void *stats_base = &socket_handler->stats;
355355
aws_array_list_push_back(stats_list, &stats_base);
356356
}
357357

358+
static void s_trigger_read(struct aws_channel_handler *handler) {
359+
struct socket_handler *socket_handler = (struct socket_handler *)handler->impl;
360+
361+
s_do_read(socket_handler);
362+
}
363+
358364
static struct aws_channel_handler_vtable s_vtable = {
359365
.process_read_message = s_socket_process_read_message,
360366
.destroy = s_socket_destroy,
@@ -365,6 +371,7 @@ static struct aws_channel_handler_vtable s_vtable = {
365371
.message_overhead = s_message_overhead,
366372
.reset_statistics = s_reset_statistics,
367373
.gather_statistics = s_gather_statistics,
374+
.trigger_read = s_trigger_read,
368375
};
369376

370377
struct aws_channel_handler *aws_socket_handler_new(

tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ if (NOT BYO_CRYPTO)
149149
add_net_test_case(tls_server_hangup_during_negotiation)
150150
add_net_test_case(tls_client_channel_no_verify)
151151
add_net_test_case(test_tls_negotiation_timeout)
152-
add_net_test_case(tls_double_channel)
153152
add_net_test_case(alpn_successfully_negotiates)
154153
add_net_test_case(alpn_no_protocol_message)
155154
add_net_test_case(test_ecc_cert_import)

0 commit comments

Comments
 (0)