Mic*_*ter 6 c# git certificate http-proxy libgit2sharp
我的组织运行自己的GitHub服务器和Web代理.我已经配置了git,以便我可以从命令行使用github.com和我们的内部GitHub.但是使用LibGit2Sharp,我无法对我们的GitHub服务器执行操作.CloneOptions调用的唯一回调是RepositoryOperationStarting.不会调用其他回调.我在下面发布了相关的代码和配置(名称已更改以保持匿名).我正在使用NuGet的LibGit2Sharp v0.25.2.
使用LibGit2Sharp的代码.注释表明在击中我们的内部github时会触发哪些回调.点击github.com时,会按预期调用所有回调.
private static void Main(string[] args)
{
var options = new CloneOptions
{
CertificateCheck = (certificate, valid, host) => true, // never called
CredentialsProvider = (url, fromUrl, types) => null, // never called
OnCheckoutProgress = (path, steps, totalSteps) => { }, // never called
OnProgress = output => true, // never called
OnTransferProgress = progress => true, // never called
OnUpdateTips = (name, id, newId) => true, // never called
RepositoryOperationCompleted = context => { }, // never called
RepositoryOperationStarting = context => true // ONLY THIS ONE IS CALLED
};
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; // never called
Repository.Clone(args[0], args[1], options);
}
Run Code Online (Sandbox Code Playgroud)
例外:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: failed to send request: The operation timed out
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 136
at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 354
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in C:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 715
at gitex.Program.Main(String[] args) in D:\dev\mgunter\gitex\gitex\Program.cs:line 71
Run Code Online (Sandbox Code Playgroud)
从命令行克隆工作:
C:\> git clone https://github.my-domain.com/organization/project
Cloning into 'project'...
remote: Counting objects: 1373, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 1373 (delta 8), reused 0 (delta 0), pack-reused 1350R
Receiving objects: 100% (1373/1373), 383.10 KiB | 0 bytes/s, done.
Resolving deltas: 100% (862/862), done.
Run Code Online (Sandbox Code Playgroud)
这是我的git配置的相关部分.我也试过HTTP_PROXY和HTTPS_PROXY环境变量,但没有运气.
[http "https://github.my-domain.com"]
proxy = http://proxy-for-internal.my-domain.com:80
[http "https://github.com"]
proxy = http://proxy-for-external.my-domain.com:81
sslCAinfo = ~/certificates/my-domain-root-ca.cer
[credential]
helper = wincred
[hub]
host = github.my-domain.com
protocol = https
Run Code Online (Sandbox Code Playgroud)
使用WireShark,我看到命令行git确实命中了我的代理服务器.但是,我使用LibGit2Sharp的.NET程序根本没有命中代理服务器.
这里还有其他想法吗?看来 LibGit2Sharp 只是不尊重代理信息
.gitconfig
情况似乎确实如此,来自libgit2/libgit2sharp 问题 1429,其中Brandon Ording ( bording)评论道:
看起来像是在88cf9a7
GitProxyOptions中添加的,并且它们正在 Commands.Fetch 中使用,正如您在此处看到的那样。然而,目前看来,在代码库中的任何地方, of
GitProxyType总是GitProxyOptions被初始化为0,即None。
查看 的 libgit2 代码git_proxy_t,似乎 None 禁用使用任何代理。
爱德华·汤姆森 (Edward Thomson ethomson)证实:
是的,看起来确实是禁用代理... Windows 上的默认传输 (WinHTTP) 不支持代理,IIRC,所以这基本上是一个无用的东西。但是,当 libgit2 本身是支持构建时,打开自动支持会有所帮助
libcurl。
所以:提交 0d72f67f2确实提到:
proxy:不要在类型中指定协议
我们将其留给 url 字段中的方案。
该类型应该只告诉我们是否需要代理以及是否要自动检测它。
这是为了响应问题 3110,该问题涉及一个月后提交 1dc4491,带有代理配置示例,但带有 libgit2 和 Java 程序。
HTTP(S)_PROXY虽然应该选择,但是:对于像您自己的 GitHub 服务器这样的内部服务,请检查您是否确实需要代理。
大多数情况下,您会进行设置NO_PROXY=localhost,.mycompany.com,以便在联系内部(LAN 而不是 WAN)服务器时不使用任何代理。