CertificateCheckHandler callback uses a different return type in libgit2sharp compared to libgit2 · Issue #2195 · libgit2/libgit2sharp · GitHub
Skip to content

CertificateCheckHandler callback uses a different return type in libgit2sharp compared to libgit2 #2195

Open

Description

@kastagg

In common with a number of others here, I'm having challenges getting certificates to work in C# code. I've gotten to proving the there is a difference in data types expected from the certificate check callback used by C and C#, documented differences in the "valid" value, and very different enumerations for the certificate types.

libgit2sharp Handlers.cs has
public delegate bool CertificateCheckHandler(Certificate certificate, bool valid, string host);

meanwhile, libgit2 cert.h has:
typedef int GIT_CALLBACK(git_transport_certificate_cb)(git_cert cert, int valid, const charhost, void *payload);

The C int return and C# bool return are treated in ways that can mean opposite treatment:

  • C# uses 'true' (certificate valid) and 'false'.
  • C uses: 0 = proceed (certificate valid)
    <0 = fail the connection
    >0 = callback failed to act, use the existing validity determination.
    Since a 'true' is a '1' is >0, there needs to be a shim of code to translate the result or the documented use (return true to say the certificate is valid) isn't producing the expected value. I've been unable to dig deep enough to locate the shim, could someone with more knowledge take a closer look?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions