Skip to content

Commit 3cf866d

Browse files
committed
http: add client cert for HTTPS proxies.
Git currently supports performing connections to HTTPS proxies but we don't support doing mutual authentication with them (through TLS). This commit adds the necessary options to be able to send a client certificate to the HTTPS proxy. A client certificate can provide an alternative way of authentication instead of using 'ProxyAuthorization' or other more common methods of authentication. Libcurl supports this functionality already. The feature is guarded by the first available libcurl version that supports these options. Signed-off-by: Jorge Lopez Silva <[email protected]>
1 parent 51ebf55 commit 3cf866d

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

http.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ static long curl_low_speed_time = -1;
8686
static int curl_ftp_no_epsv;
8787
static const char *curl_http_proxy;
8888
static const char *http_proxy_authmethod;
89+
90+
#if LIBCURL_VERSION_NUM >= 0x073400
91+
static const char *http_proxy_ssl_cert;
92+
static const char *http_proxy_ssl_key;
93+
static const char *http_proxy_ssl_key_passwd;
94+
#endif
95+
static const char *http_proxy_ssl_ca_info;
96+
8997
static struct {
9098
const char *name;
9199
long curlauth_param;
@@ -365,6 +373,20 @@ static int http_options(const char *var, const char *value, void *cb)
365373
if (!strcmp("http.proxyauthmethod", var))
366374
return git_config_string(&http_proxy_authmethod, var, value);
367375

376+
#if LIBCURL_VERSION_NUM >= 0x073400
377+
if (!strcmp("http.proxycert", var))
378+
return git_config_string(&http_proxy_ssl_cert, var, value);
379+
380+
if (!strcmp("http.proxykey", var))
381+
return git_config_string(&http_proxy_ssl_key, var, value);
382+
383+
if (!strcmp("http.proxykeypass", var))
384+
return git_config_string(&http_proxy_ssl_key_passwd, var, value);
385+
386+
if (!strcmp("http.proxycainfo", var))
387+
return git_config_string(&http_proxy_ssl_ca_info, var, value);
388+
#endif
389+
368390
if (!strcmp("http.cookiefile", var))
369391
return git_config_pathname(&curl_cookie_file, var, value);
370392
if (!strcmp("http.savecookies", var)) {
@@ -924,8 +946,14 @@ static CURL *get_curl_handle(void)
924946
#if LIBCURL_VERSION_NUM >= 0x073400
925947
curl_easy_setopt(result, CURLOPT_PROXY_CAINFO, NULL);
926948
#endif
927-
} else if (ssl_cainfo != NULL)
928-
curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
949+
} else if (ssl_cainfo != NULL || http_proxy_ssl_ca_info != NULL) {
950+
if (ssl_cainfo != NULL)
951+
curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
952+
#if LIBCURL_VERSION_NUM >= 0x073400
953+
if (http_proxy_ssl_ca_info != NULL)
954+
curl_easy_setopt(result, CURLOPT_PROXY_CAINFO, http_proxy_ssl_ca_info);
955+
#endif
956+
}
929957

930958
if (curl_low_speed_limit > 0 && curl_low_speed_time > 0) {
931959
curl_easy_setopt(result, CURLOPT_LOW_SPEED_LIMIT,
@@ -1018,9 +1046,23 @@ static CURL *get_curl_handle(void)
10181046
CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
10191047
#endif
10201048
#if LIBCURL_VERSION_NUM >= 0x073400
1021-
else if (starts_with(curl_http_proxy, "https"))
1049+
else if (starts_with(curl_http_proxy, "https")) {
10221050
curl_easy_setopt(result,
10231051
CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);
1052+
1053+
if (http_proxy_ssl_cert != NULL) {
1054+
curl_easy_setopt(result,
1055+
CURLOPT_PROXY_SSLCERT, http_proxy_ssl_cert);
1056+
}
1057+
if (http_proxy_ssl_key != NULL) {
1058+
curl_easy_setopt(result,
1059+
CURLOPT_PROXY_SSLKEY, http_proxy_ssl_key);
1060+
}
1061+
if (http_proxy_ssl_key_passwd != NULL) {
1062+
curl_easy_setopt(result,
1063+
CURLOPT_PROXY_KEYPASSWD, http_proxy_ssl_key_passwd);
1064+
}
1065+
}
10241066
#endif
10251067
if (strstr(curl_http_proxy, "://"))
10261068
credential_from_url(&proxy_auth, curl_http_proxy);

0 commit comments

Comments
 (0)