@matheusbsbs / matheus-bagliano / commits / b8ac923010
Fork 0

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ö <martin@martin.st> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Storsjö committed Nov 27, 2009 at 23:43 UTC b8ac923010484908d8426cb8ded5ad7e8c21a7f6
2 files changed +29
Documentation/config.txt
+7
@@ -1158,6 +1158,13 @@ http.noEPSV::
1158 support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
1159 environment variable. Default is false (curl will use EPSV).
1160
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 +
1168 i18n.commitEncoding::
1169 Character encoding the commit messages are stored in; git itself
1170 does not care per se, but this information is necessary e.g. when
http.c
+22
@@ -7,6 +7,10 @@ int active_requests;
7 int http_is_verbose;
8 size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
9
10 +#if LIBCURL_VERSION_NUM >= 0x070a06
11 +#define LIBCURL_CAN_HANDLE_AUTH_ANY
12 +#endif
13 +
14 static int min_curl_sessions = 1;
15 static int curl_session_count;
16 #ifdef USE_CURL_MULTI
@@ -36,6 +40,9 @@ static long curl_low_speed_time = -1;
40 static int curl_ftp_no_epsv;
41 static const char *curl_http_proxy;
42 static char *user_name, *user_pass;
43 +#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
44 +static int curl_http_auth_any = 0;
45 +#endif
46
47 #if LIBCURL_VERSION_NUM >= 0x071700
48 /* Use CURLOPT_KEYPASSWD as is */
@@ -190,6 +197,12 @@ static int http_options(const char *var, const char *value, void *cb)
197 http_post_buffer = LARGE_PACKET_MAX;
198 return 0;
199 }
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
206
207 /* Fall back on the default ones */
208 return git_default_config(var, value, cb);
@@ -240,6 +253,10 @@ static CURL *get_curl_handle(void)
253 #if LIBCURL_VERSION_NUM >= 0x070907
254 curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
255 #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
260
261 init_curl_http_auth(result);
262
@@ -391,6 +408,11 @@ void http_init(struct remote *remote)
408 if (getenv("GIT_CURL_FTP_NO_EPSV"))
409 curl_ftp_no_epsv = 1;
410
411 +#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
412 + if (getenv("GIT_HTTP_AUTH_ANY"))
413 + curl_http_auth_any = 1;
414 +#endif
415 +
416 if (remote && remote->url && remote->url[0]) {
417 http_auth_init(remote->url[0]);
418 if (!ssl_cert_password_required &&