Skip to content

Commit 6acf306

Browse files
authored
Validate additionally outgoing DATA messages (#97)
* Add protocol version check for outgoing DATA messages * Report error on STREAM_START message with a mismatched version in SOURCE mode * Fix typo in AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH error name * Add a new function to secure tunnel vtable (aws_secure_tunnel_operation_prepare_message_for_send_fn) to perform actions on outbound message in event loop thread before sending the message * Define new errors for reporting issues on sending messages * Fix data race on sending DATA, STREAM_START, CONNECTION_START messages * Add tests for sending DATA messages with mismatched protocol or on inactive connections * Add tests for sending STREAM_START and CONNECTION messages (in SOURCE mode) * Fix data race in tests by moving mocked WebSocket operations to event loop thread
1 parent fb6cd3e commit 6acf306

File tree

9 files changed

+1182
-247
lines changed

9 files changed

+1182
-247
lines changed

include/aws/iotdevice/iotdevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ enum aws_iotdevice_error {
3838
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY,
3939
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP,
4040
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP,
41+
/* NOTE Leave the old name for compatibility. */
4142
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH,
43+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH =
44+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH,
4245
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED,
4346
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE,
47+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION,
48+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH,
49+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID,
4450

4551
AWS_ERROR_END_IOTDEVICE_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_IOTDEVICE_PACKAGE_ID),
4652
};

include/aws/iotdevice/private/secure_tunneling_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ struct aws_secure_tunnel_connections {
163163
/* Table containing streams using multiplexing (service ids) */
164164
struct aws_hash_table service_ids;
165165

166-
/* Message used for initializing a stream upon a reconnect due to a protocol version missmatch */
166+
/* Message used for initializing a stream upon a reconnect due to a protocol version mismatch */
167167
struct aws_secure_tunnel_message_storage *restore_stream_message_view;
168168
struct aws_secure_tunnel_message_storage restore_stream_message;
169169
};

include/aws/iotdevice/private/secure_tunneling_operations.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ struct aws_secure_tunnel_operation_vtable {
6262
int (*aws_secure_tunnel_operation_set_connection_start_id)(
6363
struct aws_secure_tunnel_operation *operation,
6464
struct aws_secure_tunnel *secure_tunnel);
65+
66+
/* Perform actions on outbound message before sending it */
67+
void (*aws_secure_tunnel_operation_prepare_message_for_send_fn)(
68+
struct aws_secure_tunnel_operation *operation,
69+
struct aws_secure_tunnel *secure_tunnel);
6570
};
6671

6772
/**

include/aws/iotdevice/secure_tunneling.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,25 @@ const char *aws_secure_tunnel_message_type_to_c_string(enum aws_secure_tunnel_me
318318
//***********************************************************************************************************************
319319
/* THIS API SHOULD ONLY BE USED FROM SOURCE MODE */
320320
//***********************************************************************************************************************
321+
/**
322+
* Queue a STREAM_START message in a secure tunnel
323+
* @note This function should only be used from source mode.
324+
* @param secure_tunnel secure tunnel to queue a message for
325+
* @param message_options configuration options for the message operation
326+
* @return success/failure in the synchronous logic that kicks off the message operation
327+
*/
321328
AWS_IOTDEVICE_API
322329
int aws_secure_tunnel_stream_start(
323330
struct aws_secure_tunnel *secure_tunnel,
324331
const struct aws_secure_tunnel_message_view *message_options);
325332

333+
/**
334+
* Queue a CONNECTION_START message in a secure tunnel
335+
* @note This function should only be used from source mode.
336+
* @param secure_tunnel secure tunnel to queue a message for
337+
* @param message_options configuration options for the message operation
338+
* @return success/failure in the synchronous logic that kicks off the message operation
339+
*/
326340
AWS_IOTDEVICE_API
327341
int aws_secure_tunnel_connection_start(
328342
struct aws_secure_tunnel *secure_tunnel,
@@ -331,6 +345,13 @@ int aws_secure_tunnel_connection_start(
331345
//***********************************************************************************************************************
332346
/* THIS API SHOULD NOT BE USED BY THE CUSTOMER AND IS DEPRECATED */
333347
//***********************************************************************************************************************
348+
/**
349+
* Queue a STREAM_RESET message in a secure tunnel
350+
* @deprecated This function should not be used.
351+
* @param secure_tunnel secure tunnel to queue a message for
352+
* @param message_options configuration options for the message operation
353+
* @return success/failure in the synchronous logic that kicks off the message operation
354+
*/
334355
AWS_IOTDEVICE_API
335356
int aws_secure_tunnel_stream_reset(
336357
struct aws_secure_tunnel *secure_tunnel,

source/iotdevice.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,31 @@ static struct aws_error_info s_errors[] = {
7777
"Error while processing secure tunnel operational state."),
7878
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
7979
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_OPERATION_FAILED_DUE_TO_OFFLINE_QUEUE_POLICY,
80-
"Error while processing secure tunnel operational state."),
80+
"Secure Tunnel operation failed due to offline queue policy."),
8181
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
8282
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_UNEXPECTED_HANGUP,
8383
"The connection was closed unexpectedly."),
8484
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
8585
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_USER_REQUESTED_STOP,
8686
"Secure Tunnel connection interrupted by user request."),
8787
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
88-
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISSMATCH,
89-
"Secure Tunnel connection interrupted due to a protocol version missmatch."),
88+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_PROTOCOL_VERSION_MISMATCH,
89+
"Secure Tunnel connection interrupted due to a protocol version mismatch."),
9090
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
9191
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_TERMINATED,
9292
"Secure Tunnel terminated by user request."),
93-
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
94-
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE,
95-
"Error occured while decoding an incoming message." ),
93+
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
94+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE,
95+
"Error occured while decoding an incoming message." ),
96+
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
97+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION,
98+
"DATA message processing failed due to no active connection found." ),
99+
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
100+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH,
101+
"DATA message processing failed due to a protocol version mismatch." ),
102+
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
103+
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID,
104+
"Secure Tunnel operation failed due to using inactive service id." ),
96105
};
97106
/* clang-format on */
98107
#undef AWS_DEFINE_ERROR_INFO_IOTDEVICE

0 commit comments

Comments
 (0)