Skip to content

Commit 04633d7

Browse files
committed
Add cmake parameter to enforce tls version
1 parent b3d2152 commit 04633d7

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

.cspell.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"PythonInterp", "DWAVE", "Winmm", "DPULSE", "pulseaudio", "MSVC", "NOTFOUND", "libpulse", "COREAUDIO",
2323
"devel", "AUDIOTOOLBOX", "DCORE", "CONCAT", "DNON", "FULLPATCH", "setopt", "CURLOPT", "SSLCERT",
2424
"CROSSCOMPILING", "nullptr", "DWORD", "lpsz", "commoncrypto", "COMMONCRYPTO", "endforeach", "pkgconfig",
25-
"MGMT", "DENABLED",
25+
"MGMT", "DENABLED", "DENFORCE",
2626
// Compiler and linker
2727
"Wpedantic", "Wextra", "Werror", "xldscope", "Wtype", "Wunused", "RTTI", "ffunction", "fdata", "fsanitize",
2828
"pathconf", "unistd", "umask", "GNUCXX", "libasan", "SUNPRO", "gnustl", "libgnustl", "Wmissing",

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ if (LEGACY_BUILD)
6464
option(BUILD_BENCHMARKS "Enables building the benchmark executable" OFF)
6565
option(BUILD_OPTEL "Enables building the open telemetry implementation of tracing" OFF)
6666
option(AWS_SDK_WARNINGS_ARE_ERRORS "Compiler warning is treated as an error. Try turning this off when observing errors on a new or uncommon compiler" ON)
67+
option(USE_TLS_V1_2 "Set http client to enforce TLS 1.2" ON)
68+
option(USE_TLS_V1_3 "Set http client to enforce TLS 1.3" OFF)
6769

6870
set(AWS_USER_AGENT_CUSTOMIZATION "" CACHE STRING "User agent extension")
6971
set(AWS_TEST_REGION "US_EAST_1" CACHE STRING "Region to target integration tests against")
@@ -78,6 +80,12 @@ if (LEGACY_BUILD)
7880
if (DISABLE_INTERNAL_IMDSV1_CALLS)
7981
add_definitions(-DDISABLE_IMDSV1)
8082
endif ()
83+
if (USE_TLS_V2)
84+
add_definitions(-DENFORCE_TLS_V1_2)
85+
endif ()
86+
if (USE_TLS_V3)
87+
add_definitions(-DENFORCE_TLS_V1_3)
88+
endif ()
8189

8290
#From https://stackoverflow.com/questions/18968979/how-to-get-colorized-output-with-cmake
8391
if (NOT WIN32)

src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,13 @@ std::shared_ptr<HttpResponse> CurlHttpClient::MakeRequest(const std::shared_ptr<
674674

675675
#if LIBCURL_VERSION_MAJOR >= 7
676676
#if LIBCURL_VERSION_MINOR >= 34
677+
#if defined(ENFORCE_TLS_V1_3)
678+
curl_easy_setopt(connectionHandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_3);
679+
#elif defined(ENFORCE_TLS_V1_2)
680+
curl_easy_setopt(connectionHandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
681+
#else
677682
curl_easy_setopt(connectionHandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
683+
#endif
678684
#endif //LIBCURL_VERSION_MINOR
679685
#endif //LIBCURL_VERSION_MAJOR
680686
}

src/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,22 @@ WinHttpSyncHttpClient::WinHttpSyncHttpClient(const ClientConfiguration& config)
105105
if (m_verifySSL)
106106
{
107107
//disable insecure tls protocols, otherwise you might as well turn ssl verification off.
108-
#if defined(WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3)
109-
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
110-
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
108+
#if defined(ENFORCE_TLS_V1_3) && defined(WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3)
109+
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
110+
#elif defined(ENFORCE_TLS_V1_2) && defined(WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3)
111+
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 |
112+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
113+
#elif defined(ENFORCE_TLS_V1_2) && !defined(WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3)
114+
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
115+
#elif defined(WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3)
116+
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
117+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
118+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 |
119+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
111120
#else
112-
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
121+
DWORD flags = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
122+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
123+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
113124
#endif
114125

115126
if (!WinHttpSetOption(GetOpenHandle(), WINHTTP_OPTION_SECURE_PROTOCOLS, &flags, sizeof(flags)))

0 commit comments

Comments
 (0)