Skip to content

Commit b8ac923

Browse files
mstorsjogitster
authored andcommitted
Add an option for using any HTTP authentication scheme, not only basic
This adds the configuration option http.authAny (overridable with the environment variable GIT_HTTP_AUTH_ANY), for instructing curl to allow any HTTP authentication scheme, not only basic (which sends the password in plaintext). When this is enabled, curl has to do double requests most of the time, in order to discover which HTTP authentication method to use, which lowers the performance slightly. Therefore this isn't enabled by default. One example of another authentication scheme to use is digest, which doesn't send the password in plaintext, but uses a challenge-response mechanism instead. Using digest authentication in practice requires at least curl 7.18.1, due to bugs in the digest handling in earlier versions of curl. Signed-off-by: Martin Storsjö <[email protected]> Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad75ebe commit b8ac923

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,13 @@ http.noEPSV::
11581158
support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
11591159
environment variable. Default is false (curl will use EPSV).
11601160

1161+
http.authAny::
1162+
Allow any HTTP authentication method, not only basic. Enabling
1163+
this lowers the performance slightly, by having to do requests
1164+
without any authentication to discover the authentication method
1165+
to use. Can be overridden by the 'GIT_HTTP_AUTH_ANY'
1166+
environment variable. Default is false.
1167+
11611168
i18n.commitEncoding::
11621169
Character encoding the commit messages are stored in; git itself
11631170
does not care per se, but this information is necessary e.g. when

http.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ int active_requests;
77
int http_is_verbose;
88
size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
99

10+
#if LIBCURL_VERSION_NUM >= 0x070a06
11+
#define LIBCURL_CAN_HANDLE_AUTH_ANY
12+
#endif
13+
1014
static int min_curl_sessions = 1;
1115
static int curl_session_count;
1216
#ifdef USE_CURL_MULTI
@@ -36,6 +40,9 @@ static long curl_low_speed_time = -1;
3640
static int curl_ftp_no_epsv;
3741
static const char *curl_http_proxy;
3842
static char *user_name, *user_pass;
43+
#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
44+
static int curl_http_auth_any = 0;
45+
#endif
3946

4047
#if LIBCURL_VERSION_NUM >= 0x071700
4148
/* Use CURLOPT_KEYPASSWD as is */
@@ -190,6 +197,12 @@ static int http_options(const char *var, const char *value, void *cb)
190197
http_post_buffer = LARGE_PACKET_MAX;
191198
return 0;
192199
}
200+
#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
201+
if (!strcmp("http.authany", var)) {
202+
curl_http_auth_any = git_config_bool(var, value);
203+
return 0;
204+
}
205+
#endif
193206

194207
/* Fall back on the default ones */
195208
return git_default_config(var, value, cb);
@@ -240,6 +253,10 @@ static CURL *get_curl_handle(void)
240253
#if LIBCURL_VERSION_NUM >= 0x070907
241254
curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
242255
#endif
256+
#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
257+
if (curl_http_auth_any)
258+
curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
259+
#endif
243260

244261
init_curl_http_auth(result);
245262

@@ -391,6 +408,11 @@ void http_init(struct remote *remote)
391408
if (getenv("GIT_CURL_FTP_NO_EPSV"))
392409
curl_ftp_no_epsv = 1;
393410

411+
#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
412+
if (getenv("GIT_HTTP_AUTH_ANY"))
413+
curl_http_auth_any = 1;
414+
#endif
415+
394416
if (remote && remote->url && remote->url[0]) {
395417
http_auth_init(remote->url[0]);
396418
if (!ssl_cert_password_required &&

0 commit comments

Comments
 (0)