]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: store credential when PKI auth is used
authorJohn Szakmeister <john@szakmeister.net>
Fri, 12 Mar 2021 02:40:26 +0000 (21:40 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Mar 2021 06:17:07 +0000 (22:17 -0800)
We already looked for the PKI credentials in the credential store, but
failed to approve it on success.  Meaning, the PKI certificate password
was never stored and git would request it on every connection to the
remote.  Let's complete the chain by storing the certificate password on
success.

Likewise, we also need to reject the credential when there is a failure.
Curl appears to report client-related certificate issues are reported
with the CURLE_SSL_CERTPROBLEM error.  This includes not only a bad
password, but potentially other client certificate related problems.
Since we cannot get more information from curl, we'll go ahead and
reject the credential upon receiving that error, just to be safe and
avoid caching or saving a bad password.

Signed-off-by: John Szakmeister <john@szakmeister.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http.c

diff --git a/http.c b/http.c
index f8ea28bb2ed2bd7189378c2a39c9f222964081cd..60d01c6e83907f8e6f92d9308d48818a95c7dfdb 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1637,7 +1637,17 @@ static int handle_curl_result(struct slot_results *results)
                credential_approve(&http_auth);
                if (proxy_auth.password)
                        credential_approve(&proxy_auth);
+               credential_approve(&cert_auth);
                return HTTP_OK;
+       } else if (results->curl_result == CURLE_SSL_CERTPROBLEM) {
+               /*
+                * We can't tell from here whether it's a bad path, bad
+                * certificate, bad password, or something else wrong
+                * with the certificate.  So we reject the credential to
+                * avoid caching or saving a bad password.
+                */
+               credential_reject(&cert_auth);
+               return HTTP_NOAUTH;
        } else if (missing_target(results))
                return HTTP_MISSING_TARGET;
        else if (results->http_code == 401) {