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

Skip to content

Commit b4dde78

Browse files
authored
Merge pull request libgit2#4550 from libgit2/ethomson/winhttp
winhttp: enable TLS 1.2
2 parents 7d90637 + 5ecb622 commit b4dde78

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

deps/winhttp/winhttp.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,12 @@ typedef int INTERNET_SCHEME, *LPINTERNET_SCHEME;
437437
#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE 0x00000040
438438
#define WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR 0x80000000
439439

440-
#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 0x00000008
441-
#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 0x00000020
442-
#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 0x00000080
443-
#define WINHTTP_FLAG_SECURE_PROTOCOL_ALL (WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 | WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1)
440+
#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 0x00000008
441+
#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 0x00000020
442+
#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 0x00000080
443+
#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200
444+
#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800
445+
#define WINHTTP_FLAG_SECURE_PROTOCOL_ALL (WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 | WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1)
444446

445447
#define WINHTTP_AUTH_SCHEME_BASIC 0x00000001
446448
#define WINHTTP_AUTH_SCHEME_NTLM 0x00000002

src/transports/winhttp.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
4141
#endif
4242

43+
#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS_1_1
44+
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200
45+
#endif
46+
47+
#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS_1_2
48+
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800
49+
#endif
50+
4351
static const char *prefix_https = "https://";
4452
static const char *upload_pack_service = "upload-pack";
4553
static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";
@@ -744,6 +752,10 @@ static int winhttp_connect(
744752
int error = -1;
745753
int default_timeout = TIMEOUT_INFINITE;
746754
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;
747759

748760
t->session = NULL;
749761
t->connection = NULL;
@@ -786,6 +798,16 @@ static int winhttp_connect(
786798
goto on_error;
787799
}
788800

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+
789811
if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
790812
giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP");
791813
goto on_error;

0 commit comments

Comments
 (0)