Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ecb622

Browse files
committed
winhttp: enable TLS 1.2 on Windows 7 and earlier
Versions of Windows prior to Windows 8 do not enable TLS 1.2 by default, though support may exist. Try to enable TLS 1.2 support explicitly on connections. This request may fail if the operating system does not have TLS 1.2 support - the initial release of Vista lacks TLS 1.2 support (though it is available as a software update) and XP completely lacks TLS 1.2 support. If this request does fail, the HTTP context is still valid, and still maintains the original protocol support. So we ignore the failure from this operation.
1 parent 934e6a3 commit 5ecb622

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/transports/winhttp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,10 @@ static int winhttp_connect(
752752
int error = -1;
753753
int default_timeout = TIMEOUT_INFINITE;
754754
int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
755+
DWORD protocols =
756+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
757+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
758+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
755759

756760
t->session = NULL;
757761
t->connection = NULL;
@@ -794,6 +798,16 @@ static int winhttp_connect(
794798
goto on_error;
795799
}
796800

801+
/*
802+
* Do a best-effort attempt to enable TLS 1.2 but allow this to
803+
* fail; if TLS 1.2 support is not available for some reason,
804+
* ignore the failure (it will keep the default protocols).
805+
*/
806+
WinHttpSetOption(t->session,
807+
WINHTTP_OPTION_SECURE_PROTOCOLS,
808+
&protocols,
809+
sizeof(protocols));
810+
797811
if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
798812
giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP");
799813
goto on_error;

0 commit comments

Comments
 (0)