Skip to content

Commit 797535b

Browse files
committed
WinHTTP: Try to use TLS1.3
Signed-off-by: Sven Strickroth <email@cs-ware.de>
1 parent 1e98752 commit 797535b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/transports/winhttp.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800
5050
#endif
5151

52+
#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3
53+
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3 0x00002000
54+
#endif
55+
5256
#ifndef HTTP_STATUS_PERMANENT_REDIRECT
5357
# define HTTP_STATUS_PERMANENT_REDIRECT 308
5458
#endif
@@ -743,7 +747,8 @@ static int winhttp_connect(
743747
DWORD protocols =
744748
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
745749
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
746-
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
750+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 |
751+
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
747752

748753
t->session = NULL;
749754
t->connection = NULL;
@@ -788,14 +793,20 @@ static int winhttp_connect(
788793
}
789794

790795
/*
791-
* Do a best-effort attempt to enable TLS 1.2 but allow this to
792-
* fail; if TLS 1.2 support is not available for some reason,
796+
* Do a best-effort attempt to enable TLS 1.3 and 1.2 but allow this to
797+
* fail; if TLS 1.2 or 1.3 support is not available for some reason,
793798
* ignore the failure (it will keep the default protocols).
794799
*/
795-
WinHttpSetOption(t->session,
800+
if (WinHttpSetOption(t->session,
796801
WINHTTP_OPTION_SECURE_PROTOCOLS,
797802
&protocols,
798-
sizeof(protocols));
803+
sizeof(protocols)) == FALSE) {
804+
protocols &= ~WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
805+
WinHttpSetOption(t->session,
806+
WINHTTP_OPTION_SECURE_PROTOCOLS,
807+
&protocols,
808+
sizeof(protocols));
809+
}
799810

800811
if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
801812
git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP");

0 commit comments

Comments
 (0)