Reputation: 6524
Currently trying to clone a gitlab repository (which can only be accessed by VPN). A normal access (without vpn) through a gitlab repo works with libgit2sharp.
var localFolder = "test";
var gitLabUrl = "some url";
var userNamePasswordCredentials = new UsernamePasswordCredentials()
{
Username = gitConnection.UserName,
Password = gitConnection.Password
};
Directory.CreateDirectory(localFolder);
var cloneOptions = new CloneOptions();
cloneOptions.CertificateCheck += (certificate, valid, host) => true;
try
{
cloneOptions.CredentialsProvider = (_url, _user, _cred) => new DefaultCredentials();
Repository.Clone(gitLabUrl, localFolder, cloneOptions);
}
catch (LibGit2SharpException ex)
{
cloneOptions.CredentialsProvider = (_url, _user, _cred) => userNamePasswordCredentials;
Repository.Clone(gitLabUrl, localFolder, cloneOptions);
}
var repository = new Repository(localFolder);
I am getting an error:
No error message has been provided by the native library
Please suggest.
Upvotes: 0
Views: 1079
Reputation: 6524
I was able to clone git repository by using the command:
git -c http.sslVerify=false clone https://example.com/path/to/git
Currently LibGit2Sharp doesnt have facility to clone git by turning sslVerify false. One way to turn this off was by using the code from this link:
SmartSubtransportRegistration<MockSmartSubtransport> registration = null;
RemoteCertificateValidationCallback certificateValidationCallback = (sender,
certificate, chain, errors) => { return true; };
try
{
ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;
registration = GlobalSettings.RegisterSmartSubtransport<MockSmartSubtransport>("https");
var cloneOptions = new CloneOptions();
cloneOptions.CertificateCheck += (certificate, valid, host) => true;
cloneOptions.CredentialsProvider = (_url, _user, _cred) => new DefaultCredentials();
Repository.Clone("https://url", "localFolder", cloneOptions);
}
finally
{
GlobalSettings.UnregisterSmartSubtransport(registration);
ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
}
Some other links:
How can I make git accept a self signed certificate?
Upvotes: 2