Skip to content

Commit 86575bd

Browse files
committed
Handle old Windows
1 parent e10ca19 commit 86575bd

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

source/windows/secure_channel_tls_handler.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define READ_OUT_SIZE (16 * KB_1)
4646
#define READ_IN_SIZE READ_OUT_SIZE
4747
#define EST_HANDSHAKE_SIZE (7 * KB_1)
48-
#define WINDOWS_BUILD_1809 1809
48+
#define WINDOWS_BUILD_17763 17763
4949

5050
#define EST_TLS_RECORD_OVERHEAD 53 /* 5 byte header + 32 + 16 bytes for padding */
5151

@@ -142,20 +142,24 @@ static size_t s_message_overhead(struct aws_channel_handler *handler) {
142142
return sc_handler->stream_sizes.cbTrailer + sc_handler->stream_sizes.cbHeader;
143143
}
144144

145-
/* Checks whether current system is running Windows 10 version `build_number` or later. This check is used
146-
to determin availability of TLS 1.3. This will continue to be a valid check in Windows 11 and later as the
147-
build number continues to increment upwards. e.g. Windows 11 starts at version 21H2 (build 22_000) */
148-
static bool s_is_windows_equal_or_above_version(DWORD build_number) {
149-
ULONGLONG dwlConditionMask = 0;
150-
BYTE op = VER_GREATER_EQUAL;
151-
OSVERSIONINFOEX osvi;
152-
145+
/* Checks whether the current system is running Windows of a specific build number or later.
146+
*
147+
* This check is used to determine the availability of TLS 1.3. This will continue to be a valid check in the future
148+
* versions of Windows as the build number continues to increment upwards. E.g., Windows 11 starts at build 22000.
149+
*
150+
* For more information see https://learn.microsoft.com/en-us/windows/release-health/release-information and
151+
* https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information */
152+
static bool s_is_windows_equal_or_above_build_number(DWORD build_number) {
153153
NTSTATUS status = STATUS_DLL_NOT_FOUND;
154154

155+
OSVERSIONINFOEX osvi;
155156
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
157+
156158
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
157159
osvi.dwBuildNumber = build_number;
158160

161+
ULONGLONG dwlConditionMask = 0;
162+
BYTE op = VER_GREATER_EQUAL;
159163
dwlConditionMask = VerSetConditionMask(dwlConditionMask, VER_BUILDNUMBER, op);
160164
typedef NTSTATUS(WINAPI * pRtlGetVersionInfo)(
161165
OSVERSIONINFOEX * lpVersionInformation, ULONG TypeMask, ULONGLONG ConditionMask);
@@ -2142,8 +2146,10 @@ static DWORD s_get_enabled_protocols(enum aws_tls_versions minimum_tls_version,
21422146
return bit_enabled_protocols;
21432147
}
21442148

2145-
static struct aws_channel_handler *s_tls_handler_sch_credentials_new(
2149+
#if NTDDI_VERSION >= 0x0A000006 /* Windows SDK 10.1.17763.0 or later */
21462150

2151+
/* The SCH_CREDENTIALS and few other structures became available starting with Windows SDK 10.1.17763.0. */
2152+
static struct aws_channel_handler *s_tls_handler_sch_credentials_new(
21472153
struct aws_allocator *alloc,
21482154
struct aws_tls_connection_options *options,
21492155
struct aws_channel_slot *slot,
@@ -2193,7 +2199,7 @@ static struct aws_channel_handler *s_tls_handler_sch_credentials_new(
21932199
&sc_handler->sspi_timestamp);
21942200

21952201
if (status != SEC_E_OK) {
2196-
AWS_LOGF_ERROR(AWS_LS_IO_TLS, "Error on AcquireCredentialsHandle. SECURITY_STATUS is %d", (int)status);
2202+
AWS_LOGF_ERROR(AWS_LS_IO_TLS, "Error on AcquireCredentialsHandle. SECURITY_STATUS is 0x%X", (int)status);
21972203
int aws_error = s_determine_sspi_error(status);
21982204
aws_raise_error(aws_error);
21992205
goto on_error;
@@ -2208,6 +2214,8 @@ static struct aws_channel_handler *s_tls_handler_sch_credentials_new(
22082214
return NULL;
22092215
}
22102216

2217+
#endif /* NTDDI_VERSION >= 0x0A000006 */
2218+
22112219
static struct aws_channel_handler *s_tls_handler_schannel_cred_new(
22122220
struct aws_allocator *alloc,
22132221
struct aws_tls_connection_options *options,
@@ -2281,10 +2289,12 @@ static struct aws_channel_handler *s_tls_handler_new(
22812289
struct aws_channel_slot *slot,
22822290
bool is_client_mode) {
22832291

2292+
#if NTDDI_VERSION >= 0x0A000006 /* Windows SDK 10.1.17763.0 or later */
22842293
/* check if run on Windows 10 build 1809, (build 17_763) */
2285-
if (s_is_windows_equal_or_above_version(WINDOWS_BUILD_1809) && !s_use_schannel_creds) {
2294+
if (s_is_windows_equal_or_above_build_number(WINDOWS_BUILD_17763) && !s_use_schannel_creds) {
22862295
return s_tls_handler_sch_credentials_new(alloc, options, slot, is_client_mode);
22872296
}
2297+
#endif
22882298
return s_tls_handler_schannel_cred_new(alloc, options, slot, is_client_mode);
22892299
}
22902300

tests/tls_handler_test.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,13 +1494,13 @@ static int s_verify_good_host_mqtt_connect(
14941494
aws_tls_ctx_options_set_verify_peer(&tls_options, false);
14951495
aws_tls_ctx_options_set_alpn_list(&tls_options, "x-amzn-mqtt-ca");
14961496

1497-
struct aws_tls_ctx *tls_context = aws_tls_client_ctx_new(allocator, &tls_options);
1498-
ASSERT_NOT_NULL(tls_context);
1499-
15001497
if (override_tls_options_fn) {
15011498
(*override_tls_options_fn)(&tls_options);
15021499
}
15031500

1501+
struct aws_tls_ctx *tls_context = aws_tls_client_ctx_new(allocator, &tls_options);
1502+
ASSERT_NOT_NULL(tls_context);
1503+
15041504
struct aws_tls_connection_options tls_client_conn_options;
15051505
aws_tls_connection_options_init_from_ctx(&tls_client_conn_options, tls_context);
15061506
aws_tls_connection_options_set_callbacks(&tls_client_conn_options, s_tls_on_negotiated, NULL, NULL, &outgoing_args);
@@ -1621,10 +1621,14 @@ AWS_TEST_CASE(
16211621
s_tls_client_channel_negotiation_success_ecc384_SCHANNEL_CREDS_fn)
16221622
# endif
16231623

1624+
static void s_raise_tls_version_to_13(struct aws_tls_ctx_options *options) {
1625+
aws_tls_ctx_options_set_minimum_tls_version(options, AWS_IO_TLSv1_3);
1626+
}
1627+
16241628
AWS_STATIC_STRING_FROM_LITERAL(s_aws_ecc384_host_name, "127.0.0.1");
16251629
static int s_tls_client_channel_negotiation_success_mtls_tls1_3_fn(struct aws_allocator *allocator, void *ctx) {
16261630
(void)ctx;
1627-
return s_verify_good_host_mqtt_connect(allocator, s_aws_ecc384_host_name, 59443, NULL);
1631+
return s_verify_good_host_mqtt_connect(allocator, s_aws_ecc384_host_name, 59443, s_raise_tls_version_to_13);
16281632
}
16291633

16301634
AWS_TEST_CASE(

0 commit comments

Comments
 (0)