Skip to content

Commit b2ed778

Browse files
committed
http transport: reset error message on cert failure
Store the error message from the underlying TLS library before calling the certificate callback. If it refuses to act (demonstrated by returning GIT_PASSTHROUGH) then restore the error message. Otherwise, if the callback does not set an error message, set a sensible default that implicates the callback itself.
1 parent 2ce2315 commit b2ed778

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/transports/http.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -692,25 +692,25 @@ static int check_certificate(
692692
void *cert_cb_payload)
693693
{
694694
git_cert *cert;
695+
git_error_state last_error = {0};
695696
int error;
696697

697698
if ((error = git_stream_certificate(&cert, stream)) < 0)
698699
return error;
699700

700-
giterr_clear();
701-
error = cert_cb(cert, is_valid, url->host, cert_cb_payload);
701+
giterr_state_capture(&last_error, GIT_ECERTIFICATE);
702702

703-
if (error == GIT_PASSTHROUGH)
704-
error = is_valid ? 0 : GIT_ECERTIFICATE;
703+
error = cert_cb(cert, is_valid, url->host, cert_cb_payload);
705704

706-
if (error) {
707-
if (!giterr_last())
708-
giterr_set(GITERR_NET, "user cancelled certificate check");
705+
if (error == GIT_PASSTHROUGH && !is_valid)
706+
return giterr_state_restore(&last_error);
707+
else if (error == GIT_PASSTHROUGH)
708+
error = 0;
709+
else if (error && !giterr_last())
710+
giterr_set(GITERR_NET, "user rejected certificate for %s", url->host);
709711

710-
return error;
711-
}
712-
713-
return 0;
712+
giterr_state_free(&last_error);
713+
return error;
714714
}
715715

716716
static int http_connect(http_subtransport *t)

0 commit comments

Comments
 (0)