Skip to content

Commit 3e8084f

Browse files
avargitster
authored andcommitted
http: check CURLE_SSL_PINNEDPUBKEYNOTMATCH when emitting errors
Change the error shown when a http.pinnedPubKey doesn't match to point the http.pinnedPubKey variable added in aeff8a6 (http: implement public key pinning, 2016-02-15), e.g.: git -c http.pinnedPubKey=sha256/someNonMatchingKey ls-remote https://github.com/git/git.git fatal: unable to access 'https://github.com/git/git.git/' with http.pinnedPubkey configuration: SSL: public key does not match pinned public key! Before this we'd emit the exact same thing without the " with http.pinnedPubkey configuration". The advantage of doing this is that we're going to get a translated message (everything after the ":" is hardcoded in English in libcurl), and we've got a reference to the git-specific configuration variable that's causing the error. Unfortunately we can't test this easily, as there are no tests that require https:// in the test suite, and t/lib-httpd.sh doesn't know how to set up such tests. See [1] for the start of a discussion about what it would take to have divergent "t/lib-httpd/apache.conf" test setups. #leftoverbits 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ddb1055 commit 3e8084f

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

git-curl-compat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@
6767

6868
/**
6969
* CURLOPT_PINNEDPUBLICKEY was added in 7.39.0, released in November
70-
* 2014.
70+
* 2014. CURLE_SSL_PINNEDPUBKEYNOTMATCH was added in that same version.
7171
*/
7272
#if LIBCURL_VERSION_NUM >= 0x072c00
7373
#define GIT_CURL_HAVE_CURLOPT_PINNEDPUBLICKEY 1
74+
#define GIT_CURL_HAVE_CURLE_SSL_PINNEDPUBKEYNOTMATCH 1
7475
#endif
7576

7677
/**

http.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,10 @@ static int handle_curl_result(struct slot_results *results)
14891489
*/
14901490
credential_reject(&cert_auth);
14911491
return HTTP_NOAUTH;
1492+
#ifdef GIT_CURL_HAVE_CURLE_SSL_PINNEDPUBKEYNOTMATCH
1493+
} else if (results->curl_result == CURLE_SSL_PINNEDPUBKEYNOTMATCH) {
1494+
return HTTP_NOMATCHPUBLICKEY;
1495+
#endif
14921496
} else if (missing_target(results))
14931497
return HTTP_MISSING_TARGET;
14941498
else if (results->http_code == 401) {

http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct http_get_options {
154154
#define HTTP_START_FAILED 3
155155
#define HTTP_REAUTH 4
156156
#define HTTP_NOAUTH 5
157+
#define HTTP_NOMATCHPUBLICKEY 6
157158

158159
/*
159160
* Requests a URL and stores the result in a strbuf.

remote-curl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ static struct discovery *discover_refs(const char *service, int for_push)
499499
show_http_message(&type, &charset, &buffer);
500500
die(_("Authentication failed for '%s'"),
501501
transport_anonymize_url(url.buf));
502+
case HTTP_NOMATCHPUBLICKEY:
503+
show_http_message(&type, &charset, &buffer);
504+
die(_("unable to access '%s' with http.pinnedPubkey configuration: %s"),
505+
transport_anonymize_url(url.buf), curl_errorstr);
502506
default:
503507
show_http_message(&type, &charset, &buffer);
504508
die(_("unable to access '%s': %s"),

0 commit comments

Comments
 (0)