libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.17k stars 886 forks source link

"LibGit2Sharp.LibGit2SharpException: could not initialize security context" while cloning #2108

Open avy99 opened 3 months ago

avy99 commented 3 months ago

Reproduction steps

providing valid credential to the CredentialProvider using the below snippet cloneOptions.FetchOptions.CredentialsProvider = (url, usernameFromUrl, password) => new UsernamePasswordCredentials{ Username = gitCredential.UserName, Password = gitCredential.Password };

cloneOptions.FetchOptions.CertificateCheck = (certificate, valid, host) => true;

Repository.Clone(Credential.RepositoryUrl, workingDirectory, cloneOptions);

Expected behavior

Should clone the repository to the working directory.

Actual behavior

LibGit2Sharp.LibGit2SharpException: could not initialize security context: at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in //LibGit2Sharp/Core/Ensure.cs:line 154 at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in //LibGit2Sharp/Core/Ensure.cs:line 172 at LibGit2Sharp.Core.Proxy.gitclone(String url, String workdir, GitCloneOptions& opts) in //LibGit2Sharp/Core/Proxy.cs:line 278 at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in /_/LibGit2Sharp/Repository.cs:line 824

Version of LibGit2Sharp (release number or SHA1)

v0.30.0

Operating system(s) tested; .NET runtime tested

.NET8, windows OS

ethomson commented 3 months ago

What are you trying to clone from? GitHub.com? GHES? On prem azure devops? Hosted Azure DevOps? Something else?

Does it have a valid SSL cert or is it self signed?

What sort of auth mechanism is it trying to use? Basic? Kerberos? Something else?

happy2ganesh commented 2 months ago

i am also facing the same error during git clone by using libgit2sharp version 0.30 i am able to do git clone from cmd line script inside the server. facing "could not initialize security context: The parameter is incorrect." error while trying to clone from libgit2sharp only

ethomson commented 2 months ago

@happy2ganesh Same questions if you can help:

What are you trying to clone from? GitHub.com? GHES? On prem azure devops? Hosted Azure DevOps? Something else?

Does it have a valid SSL cert or is it self signed?

What sort of auth mechanism is it trying to use? Basic? Kerberos? Something else?

avy99 commented 2 months ago

@ethomson below are the details: Cloning from, a private repository it is self-signed Auth mechanism is Basic

Another thing to mention is while testing it using "libgit2sharp-proxy-enabled" Version="0.0.0-preview.0.1901" it is able to clone the repository successfully (minor adjustment is made to adapt clone option changes)

happy2ganesh commented 2 months ago

@ethomson please find the requested details: private repo self signed certificate basic authentication.

avy99 commented 2 months ago

@ethomson any update on it @happy2ganesh were u able to resolve the issue, if so, some help would be highly appreciable