Commit b2ed778a by Edward Thomson

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.
parent 2ce2315c
...@@ -692,25 +692,25 @@ static int check_certificate( ...@@ -692,25 +692,25 @@ static int check_certificate(
void *cert_cb_payload) void *cert_cb_payload)
{ {
git_cert *cert; git_cert *cert;
git_error_state last_error = {0};
int error; int error;
if ((error = git_stream_certificate(&cert, stream)) < 0) if ((error = git_stream_certificate(&cert, stream)) < 0)
return error; return error;
giterr_clear(); giterr_state_capture(&last_error, GIT_ECERTIFICATE);
error = cert_cb(cert, is_valid, url->host, cert_cb_payload);
if (error == GIT_PASSTHROUGH) error = cert_cb(cert, is_valid, url->host, cert_cb_payload);
error = is_valid ? 0 : GIT_ECERTIFICATE;
if (error) { if (error == GIT_PASSTHROUGH && !is_valid)
if (!giterr_last()) return giterr_state_restore(&last_error);
giterr_set(GITERR_NET, "user cancelled certificate check"); else if (error == GIT_PASSTHROUGH)
error = 0;
else if (error && !giterr_last())
giterr_set(GITERR_NET, "user rejected certificate for %s", url->host);
return error; giterr_state_free(&last_error);
} return error;
return 0;
} }
static int http_connect(http_subtransport *t) static int http_connect(http_subtransport *t)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment