Skip to content

Commit 31d7361

Browse files
authored
Revert error code ordering (#723)
Restore order of error codes to pre secitem/dispatch queue commit. Add test that checks that order of existing error codes has not been altered.
1 parent acaeb4a commit 31d7361

File tree

6 files changed

+128
-106
lines changed

6 files changed

+128
-106
lines changed

include/aws/io/io.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ enum aws_io_errors {
9999
AWS_IO_CHANNEL_READ_WOULD_EXCEED_WINDOW,
100100
AWS_IO_EVENT_LOOP_ALREADY_ASSIGNED,
101101
AWS_IO_EVENT_LOOP_SHUTDOWN,
102+
AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
103+
AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
104+
AWS_IO_TLS_ERROR_WRITE_FAILURE,
105+
AWS_IO_TLS_ERROR_ALERT_RECEIVED,
106+
AWS_IO_TLS_CTX_ERROR,
107+
AWS_IO_TLS_VERSION_UNSUPPORTED,
108+
AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
102109
AWS_IO_MISSING_ALPN_MESSAGE,
103110
AWS_IO_UNHANDLED_ALPN_PROTOCOL_MESSAGE,
104111
AWS_IO_FILE_VALIDATION_FAILURE,
@@ -121,7 +128,6 @@ enum aws_io_errors {
121128
AWS_IO_SOCKET_INVALID_ADDRESS,
122129
AWS_IO_SOCKET_ILLEGAL_OPERATION_FOR_STATE,
123130
AWS_IO_SOCKET_CONNECT_ABORTED,
124-
AWS_IO_SOCKET_MISSING_EVENT_LOOP,
125131
AWS_IO_DNS_QUERY_FAILED,
126132
AWS_IO_DNS_INVALID_NAME,
127133
AWS_IO_DNS_NO_ADDRESS_FOR_HOST,
@@ -131,35 +137,12 @@ enum aws_io_errors {
131137
DEPRECATED_AWS_IO_INVALID_FILE_HANDLE,
132138
AWS_IO_SHARED_LIBRARY_LOAD_FAILURE,
133139
AWS_IO_SHARED_LIBRARY_FIND_SYMBOL_FAILURE,
134-
AWS_IO_MAX_RETRIES_EXCEEDED,
135-
AWS_IO_RETRY_PERMISSION_DENIED,
136-
137-
AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
138-
AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
139-
AWS_IO_TLS_ERROR_WRITE_FAILURE,
140-
AWS_IO_TLS_ERROR_ALERT_RECEIVED,
141-
AWS_IO_TLS_CTX_ERROR,
142-
AWS_IO_TLS_VERSION_UNSUPPORTED,
143-
AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
144140
AWS_IO_TLS_NEGOTIATION_TIMEOUT,
145141
AWS_IO_TLS_ALERT_NOT_GRACEFUL,
142+
AWS_IO_MAX_RETRIES_EXCEEDED,
143+
AWS_IO_RETRY_PERMISSION_DENIED,
146144
AWS_IO_TLS_DIGEST_ALGORITHM_UNSUPPORTED,
147145
AWS_IO_TLS_SIGNATURE_ALGORITHM_UNSUPPORTED,
148-
AWS_IO_TLS_ERROR_READ_FAILURE,
149-
AWS_IO_TLS_UNKNOWN_ROOT_CERTIFICATE,
150-
AWS_IO_TLS_NO_ROOT_CERTIFICATE_FOUND,
151-
AWS_IO_TLS_CERTIFICATE_EXPIRED,
152-
AWS_IO_TLS_CERTIFICATE_NOT_YET_VALID,
153-
AWS_IO_TLS_BAD_CERTIFICATE,
154-
AWS_IO_TLS_PEER_CERTIFICATE_EXPIRED,
155-
AWS_IO_TLS_BAD_PEER_CERTIFICATE,
156-
AWS_IO_TLS_PEER_CERTIFICATE_REVOKED,
157-
AWS_IO_TLS_PEER_CERTIFICATE_UNKNOWN,
158-
AWS_IO_TLS_INTERNAL_ERROR,
159-
AWS_IO_TLS_CLOSED_GRACEFUL,
160-
AWS_IO_TLS_CLOSED_ABORT,
161-
AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN,
162-
AWS_IO_TLS_HOST_NAME_MISSMATCH,
163146

164147
AWS_ERROR_PKCS11_VERSION_UNSUPPORTED,
165148
AWS_ERROR_PKCS11_TOKEN_NOT_FOUND,
@@ -271,9 +254,26 @@ enum aws_io_errors {
271254
AWS_IO_STREAM_GET_LENGTH_FAILED,
272255
AWS_IO_STREAM_SEEK_UNSUPPORTED,
273256
AWS_IO_STREAM_GET_LENGTH_UNSUPPORTED,
257+
AWS_IO_TLS_ERROR_READ_FAILURE,
274258

275259
AWS_ERROR_PEM_MALFORMED,
276260

261+
AWS_IO_SOCKET_MISSING_EVENT_LOOP,
262+
AWS_IO_TLS_UNKNOWN_ROOT_CERTIFICATE,
263+
AWS_IO_TLS_NO_ROOT_CERTIFICATE_FOUND,
264+
AWS_IO_TLS_CERTIFICATE_EXPIRED,
265+
AWS_IO_TLS_CERTIFICATE_NOT_YET_VALID,
266+
AWS_IO_TLS_BAD_CERTIFICATE,
267+
AWS_IO_TLS_PEER_CERTIFICATE_EXPIRED,
268+
AWS_IO_TLS_BAD_PEER_CERTIFICATE,
269+
AWS_IO_TLS_PEER_CERTIFICATE_REVOKED,
270+
AWS_IO_TLS_PEER_CERTIFICATE_UNKNOWN,
271+
AWS_IO_TLS_INTERNAL_ERROR,
272+
AWS_IO_TLS_CLOSED_GRACEFUL,
273+
AWS_IO_TLS_CLOSED_ABORT,
274+
AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN,
275+
AWS_IO_TLS_HOST_NAME_MISMATCH,
276+
277277
AWS_IO_ERROR_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_IO_PACKAGE_ID),
278278
AWS_IO_INVALID_FILE_HANDLE = AWS_ERROR_INVALID_FILE_HANDLE,
279279
};

source/darwin/nw_socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int s_determine_socket_error(int error) {
7373
case errSSLXCertChainInvalid:
7474
return AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN;
7575
case errSSLHostNameMismatch:
76-
return AWS_IO_TLS_HOST_NAME_MISSMATCH;
76+
return AWS_IO_TLS_HOST_NAME_MISMATCH;
7777
case errSecNotTrusted:
7878
case errSSLPeerProtocolVersion:
7979
return AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE;

source/io.c

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ static struct aws_error_info s_errors[] = {
3232
AWS_DEFINE_ERROR_INFO_IO(
3333
AWS_IO_EVENT_LOOP_SHUTDOWN,
3434
"Event loop has shutdown and a resource was still using it, the resource has been removed from the loop."),
35+
AWS_DEFINE_ERROR_INFO_IO(
36+
AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
37+
"TLS (SSL) negotiation failed"),
38+
AWS_DEFINE_ERROR_INFO_IO(
39+
AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
40+
"Attempt to read/write, but TLS (SSL) hasn't been negotiated"),
41+
AWS_DEFINE_ERROR_INFO_IO(
42+
AWS_IO_TLS_ERROR_WRITE_FAILURE,
43+
"Failed to write to TLS handler"),
44+
AWS_DEFINE_ERROR_INFO_IO(
45+
AWS_IO_TLS_ERROR_ALERT_RECEIVED,
46+
"Fatal TLS Alert was received"),
47+
AWS_DEFINE_ERROR_INFO_IO(
48+
AWS_IO_TLS_CTX_ERROR,
49+
"Failed to create tls context"),
50+
AWS_DEFINE_ERROR_INFO_IO(
51+
AWS_IO_TLS_VERSION_UNSUPPORTED,
52+
"A TLS version was specified that is currently not supported. Consider using AWS_IO_TLS_VER_SYS_DEFAULTS, "
53+
" and when this lib or the operating system is updated, it will automatically be used."),
54+
AWS_DEFINE_ERROR_INFO_IO(
55+
AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
56+
"A TLS Cipher Preference was specified that is currently not supported by the current platform. Consider "
57+
" using AWS_IO_TLS_CIPHER_SYSTEM_DEFAULT, and when this lib or the operating system is updated, it will "
58+
"automatically be used."),
3559
AWS_DEFINE_ERROR_INFO_IO(
3660
AWS_IO_MISSING_ALPN_MESSAGE,
3761
"An ALPN message was expected but not received"),
@@ -98,9 +122,6 @@ static struct aws_error_info s_errors[] = {
98122
AWS_DEFINE_ERROR_INFO_IO(
99123
AWS_IO_SOCKET_CONNECT_ABORTED,
100124
"Incoming connection was aborted."),
101-
AWS_DEFINE_ERROR_INFO_IO(
102-
AWS_IO_SOCKET_MISSING_EVENT_LOOP,
103-
"Socket is missing its event loop."),
104125
AWS_DEFINE_ERROR_INFO_IO (
105126
AWS_IO_DNS_QUERY_FAILED,
106127
"A query to dns failed to resolve."),
@@ -128,93 +149,24 @@ static struct aws_error_info s_errors[] = {
128149
AWS_DEFINE_ERROR_INFO_IO(
129150
AWS_IO_SHARED_LIBRARY_FIND_SYMBOL_FAILURE,
130151
"System call error during attempt to find shared library symbol"),
131-
AWS_DEFINE_ERROR_INFO_IO(
132-
AWS_IO_MAX_RETRIES_EXCEEDED,
133-
"Retry cannot be attempted because the maximum number of retries has been exceeded."),
134-
AWS_DEFINE_ERROR_INFO_IO(
135-
AWS_IO_RETRY_PERMISSION_DENIED,
136-
"Retry cannot be attempted because the retry strategy has prevented the operation."),
137-
AWS_DEFINE_ERROR_INFO_IO(
138-
AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
139-
"TLS (SSL) negotiation failed"),
140-
AWS_DEFINE_ERROR_INFO_IO(
141-
AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
142-
"Attempt to read/write, but TLS (SSL) hasn't been negotiated"),
143-
AWS_DEFINE_ERROR_INFO_IO(
144-
AWS_IO_TLS_ERROR_WRITE_FAILURE,
145-
"Failed to write to TLS handler"),
146-
AWS_DEFINE_ERROR_INFO_IO(
147-
AWS_IO_TLS_ERROR_ALERT_RECEIVED,
148-
"Fatal TLS Alert was received"),
149-
AWS_DEFINE_ERROR_INFO_IO(
150-
AWS_IO_TLS_CTX_ERROR,
151-
"Failed to create tls context"),
152-
AWS_DEFINE_ERROR_INFO_IO(
153-
AWS_IO_TLS_VERSION_UNSUPPORTED,
154-
"A TLS version was specified that is currently not supported. Consider using AWS_IO_TLS_VER_SYS_DEFAULTS, "
155-
" and when this lib or the operating system is updated, it will automatically be used."),
156-
AWS_DEFINE_ERROR_INFO_IO(
157-
AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
158-
"A TLS Cipher Preference was specified that is currently not supported by the current platform. Consider "
159-
" using AWS_IO_TLS_CIPHER_SYSTEM_DEFAULT, and when this lib or the operating system is updated, it will "
160-
"automatically be used."),
161152
AWS_DEFINE_ERROR_INFO_IO(
162153
AWS_IO_TLS_NEGOTIATION_TIMEOUT,
163154
"Channel shutdown due to tls negotiation timeout"),
164155
AWS_DEFINE_ERROR_INFO_IO(
165156
AWS_IO_TLS_ALERT_NOT_GRACEFUL,
166157
"Channel shutdown due to tls alert. The alert was not for a graceful shutdown."),
158+
AWS_DEFINE_ERROR_INFO_IO(
159+
AWS_IO_MAX_RETRIES_EXCEEDED,
160+
"Retry cannot be attempted because the maximum number of retries has been exceeded."),
161+
AWS_DEFINE_ERROR_INFO_IO(
162+
AWS_IO_RETRY_PERMISSION_DENIED,
163+
"Retry cannot be attempted because the retry strategy has prevented the operation."),
167164
AWS_DEFINE_ERROR_INFO_IO(
168165
AWS_IO_TLS_DIGEST_ALGORITHM_UNSUPPORTED,
169166
"TLS digest was created with an unsupported algorithm"),
170167
AWS_DEFINE_ERROR_INFO_IO(
171168
AWS_IO_TLS_SIGNATURE_ALGORITHM_UNSUPPORTED,
172169
"TLS signature algorithm is currently unsupported."),
173-
AWS_DEFINE_ERROR_INFO_IO(
174-
AWS_IO_TLS_ERROR_READ_FAILURE,
175-
"Failure during TLS read."),
176-
AWS_DEFINE_ERROR_INFO_IO(
177-
AWS_IO_TLS_UNKNOWN_ROOT_CERTIFICATE,
178-
"Channel shutdown due to tls unknown root certificate."),
179-
AWS_DEFINE_ERROR_INFO_IO(
180-
AWS_IO_TLS_NO_ROOT_CERTIFICATE_FOUND,
181-
"Channel shutdown due to tls no root certificate found."),
182-
AWS_DEFINE_ERROR_INFO_IO(
183-
AWS_IO_TLS_CERTIFICATE_EXPIRED,
184-
"Channel shutdown due to tls certificate expired."),
185-
AWS_DEFINE_ERROR_INFO_IO(
186-
AWS_IO_TLS_CERTIFICATE_NOT_YET_VALID,
187-
"Channel shutdown due to tls certificate not yet valid."),
188-
AWS_DEFINE_ERROR_INFO_IO(
189-
AWS_IO_TLS_BAD_CERTIFICATE,
190-
"Channel shutdown due to tls certificate is malformed or not correctly formatted."),
191-
AWS_DEFINE_ERROR_INFO_IO(
192-
AWS_IO_TLS_PEER_CERTIFICATE_EXPIRED,
193-
"Channel shutdown due to peer tls certificate is malformed or not correctly formatted."),
194-
AWS_DEFINE_ERROR_INFO_IO(
195-
AWS_IO_TLS_BAD_PEER_CERTIFICATE,
196-
"Channel shutdown due to peer tls certificate is malformed or not correctly formatted."),
197-
AWS_DEFINE_ERROR_INFO_IO(
198-
AWS_IO_TLS_PEER_CERTIFICATE_REVOKED,
199-
"Channel shutdown due to peer tls certificate has been revoked."),
200-
AWS_DEFINE_ERROR_INFO_IO(
201-
AWS_IO_TLS_PEER_CERTIFICATE_UNKNOWN,
202-
"Channel shutdown due to peer tls certificate is unknown."),
203-
AWS_DEFINE_ERROR_INFO_IO(
204-
AWS_IO_TLS_INTERNAL_ERROR,
205-
"Channel shutdown due to internal SSL error."),
206-
AWS_DEFINE_ERROR_INFO_IO(
207-
AWS_IO_TLS_CLOSED_GRACEFUL,
208-
"Channel shutdown due to connection closed gracefully."),
209-
AWS_DEFINE_ERROR_INFO_IO(
210-
AWS_IO_TLS_CLOSED_ABORT,
211-
"Channel shutdown due to connection closed due to an error."),
212-
AWS_DEFINE_ERROR_INFO_IO(
213-
AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN,
214-
"Channel shutdown due to invalid certificate chain."),
215-
AWS_DEFINE_ERROR_INFO_IO(
216-
AWS_IO_TLS_HOST_NAME_MISSMATCH,
217-
"Channel shutdown due to certificate's host name does not match the endpoint host name."),
218170

219171
AWS_DEFINE_ERROR_INFO_IO(
220172
AWS_ERROR_PKCS11_VERSION_UNSUPPORTED,
@@ -350,7 +302,55 @@ static struct aws_error_info s_errors[] = {
350302
AWS_DEFINE_ERROR_INFO_IO(
351303
AWS_IO_STREAM_GET_LENGTH_UNSUPPORTED,
352304
"Get length is not supported in the underlying I/O source."),
305+
AWS_DEFINE_ERROR_INFO_IO(
306+
AWS_IO_TLS_ERROR_READ_FAILURE,
307+
"Failure during TLS read."),
353308
AWS_DEFINE_ERROR_INFO_IO(AWS_ERROR_PEM_MALFORMED, "Malformed PEM object encountered."),
309+
AWS_DEFINE_ERROR_INFO_IO(
310+
AWS_IO_SOCKET_MISSING_EVENT_LOOP,
311+
"Socket is missing its event loop."),
312+
AWS_DEFINE_ERROR_INFO_IO(
313+
AWS_IO_TLS_UNKNOWN_ROOT_CERTIFICATE,
314+
"Channel shutdown due to tls unknown root certificate."),
315+
AWS_DEFINE_ERROR_INFO_IO(
316+
AWS_IO_TLS_NO_ROOT_CERTIFICATE_FOUND,
317+
"Channel shutdown due to tls no root certificate found."),
318+
AWS_DEFINE_ERROR_INFO_IO(
319+
AWS_IO_TLS_CERTIFICATE_EXPIRED,
320+
"Channel shutdown due to tls certificate expired."),
321+
AWS_DEFINE_ERROR_INFO_IO(
322+
AWS_IO_TLS_CERTIFICATE_NOT_YET_VALID,
323+
"Channel shutdown due to tls certificate not yet valid."),
324+
AWS_DEFINE_ERROR_INFO_IO(
325+
AWS_IO_TLS_BAD_CERTIFICATE,
326+
"Channel shutdown due to tls certificate is malformed or not correctly formatted."),
327+
AWS_DEFINE_ERROR_INFO_IO(
328+
AWS_IO_TLS_PEER_CERTIFICATE_EXPIRED,
329+
"Channel shutdown due to peer tls certificate is malformed or not correctly formatted."),
330+
AWS_DEFINE_ERROR_INFO_IO(
331+
AWS_IO_TLS_BAD_PEER_CERTIFICATE,
332+
"Channel shutdown due to peer tls certificate is malformed or not correctly formatted."),
333+
AWS_DEFINE_ERROR_INFO_IO(
334+
AWS_IO_TLS_PEER_CERTIFICATE_REVOKED,
335+
"Channel shutdown due to peer tls certificate has been revoked."),
336+
AWS_DEFINE_ERROR_INFO_IO(
337+
AWS_IO_TLS_PEER_CERTIFICATE_UNKNOWN,
338+
"Channel shutdown due to peer tls certificate is unknown."),
339+
AWS_DEFINE_ERROR_INFO_IO(
340+
AWS_IO_TLS_INTERNAL_ERROR,
341+
"Channel shutdown due to internal SSL error."),
342+
AWS_DEFINE_ERROR_INFO_IO(
343+
AWS_IO_TLS_CLOSED_GRACEFUL,
344+
"Channel shutdown due to connection closed gracefully."),
345+
AWS_DEFINE_ERROR_INFO_IO(
346+
AWS_IO_TLS_CLOSED_ABORT,
347+
"Channel shutdown due to connection closed due to an error."),
348+
AWS_DEFINE_ERROR_INFO_IO(
349+
AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN,
350+
"Channel shutdown due to invalid certificate chain."),
351+
AWS_DEFINE_ERROR_INFO_IO(
352+
AWS_IO_TLS_HOST_NAME_MISMATCH,
353+
"Channel shutdown due to certificate's host name does not match the endpoint host name."),
354354
};
355355
/* clang-format on */
356356

source/tls_channel_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ bool aws_error_code_is_tls(int error_code) {
957957
case AWS_IO_TLS_CLOSED_GRACEFUL:
958958
case AWS_IO_TLS_CLOSED_ABORT:
959959
case AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN:
960-
case AWS_IO_TLS_HOST_NAME_MISSMATCH:
960+
case AWS_IO_TLS_HOST_NAME_MISMATCH:
961961
return true;
962962
default:
963963
return false;

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ endmacro()
1616

1717
add_test_case(io_library_init)
1818
add_test_case(io_library_init_cleanup_init_cleanup)
19+
add_test_case(io_library_error_order)
1920

2021
# Dispatch Queue does not support pipe
2122
if(NOT AWS_USE_APPLE_NETWORK_FRAMEWORK)

tests/io_lib_test.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,24 @@ static int s_test_io_library_init_cleanup_init_cleanup(struct aws_allocator *all
3535
return AWS_OP_SUCCESS;
3636
}
3737
AWS_TEST_CASE(io_library_init_cleanup_init_cleanup, s_test_io_library_init_cleanup_init_cleanup)
38+
39+
/* Make sure that new error codes are being added to the end instead of in the middle. */
40+
static int s_test_io_library_error_order(struct aws_allocator *allocator, void *ctx) {
41+
(void)allocator;
42+
(void)ctx;
43+
44+
aws_io_library_init(allocator);
45+
// Checking against expected int values of the error codes.
46+
// The checked error codes are the first, somewhere in the middle, and last as of this commit.
47+
int error_code_initial = 1024;
48+
int error_code_mid = 1067;
49+
int error_code_end = 1194;
50+
51+
ASSERT_TRUE(error_code_initial == AWS_IO_CHANNEL_ERROR_ERROR_CANT_ACCEPT_INPUT);
52+
ASSERT_TRUE(error_code_mid == AWS_IO_TLS_NEGOTIATION_TIMEOUT);
53+
ASSERT_TRUE(error_code_end == AWS_IO_TLS_HOST_NAME_MISMATCH);
54+
aws_io_library_clean_up();
55+
return AWS_OP_SUCCESS;
56+
}
57+
58+
AWS_TEST_CASE(io_library_error_order, s_test_io_library_error_order)

0 commit comments

Comments
 (0)