我在Windows上使用Git。我安装了msysGit包。我的测试存储库在服务器上有一个自签名证书。我可以毫无问题地使用HTTP访问和使用存储库。移动到HTTPS会出现以下错误:

SSL证书问题:无法获得本地颁发者证书。

我在Windows 7客户端机器的受信任根证书颁发机构中安装了自签名证书。我可以在Internet Explorer中浏览到HTTPS存储库URL,而不会出现错误消息。

Philip Kelley的这篇博客文章解释了cURL不使用客户端机器的证书存储。我按照博客文章的建议创建了curl-ca-bundle的私有副本。然后配置Git使用它。我确定Git正在使用我的副本。如果我重命名副本;Git抱怨文件丢失。

我粘贴了我的证书,正如博客文章中提到的,我仍然得到“无法获得本地发行人证书”的消息。

我通过HTTPS克隆GitHub仓库来验证Git仍然在工作。

我看到的唯一不同于博客文章的地方是我的证书是根证书——没有链可以到达它。我的证书最初来自点击IIS8 IIS管理器链接“创建自签名证书”。也许这使得证书在某种程度上与cURL所期望的有所不同。

如何让Git/cURL接受自签名证书?


当前回答

在我的例子中,我必须为不同的git存储库使用不同的证书。

遵循以下步骤(如果您拥有存储库的证书,则可以从步骤5中读取)

转到远程存储库的站点。例如:github.com, bitbucket.org, tfs.example… 单击左上方的“锁定”图标,单击“证书”。 转到证书路径选项卡,双击到..根证书 转到详细信息选项卡,并单击复制到文件。 导出/复制证书到任何您想要的地方。例:C: \ certs \ example.cer 在本地存储库文件夹中打开git bash,输入: $ git config http。sslCAInfo“C: \ certs \ example.cer”

现在您可以为每个存储库使用不同的证书。

记住,使用——global参数调用也会改变其他文件夹中git存储库的证书,所以在执行此命令时不应该使用——global参数。

其他回答

我刚刚遇到了同样的问题,但是在windows上使用sourcetree,在windows上使用正常GIT的步骤也是一样的。按照以下步骤,我能够解决这个问题。

Obtain the server certificate tree This can be done using chrome. Navigate to be server address. Click on the padlock icon and view the certificates. Export all of the certificate chain as base64 encoded files (PEM) format. Add the certificates to the trust chain of your GIT trust config file Run "git config --list". find the "http.sslcainfo" configuration this shows where the certificate trust file is located. Copy all the certificates into the trust chain file including the "- -BEGIN- -" and the "- -END- -". Make sure you add the entire certificate Chain to the certificates file

这应该可以解决自签名证书和使用GIT的问题。

我尝试使用“http。”Sslcapath”配置,但这没有工作。此外,如果我没有包括证书文件中的整个链,那么这也会失败。如果有人对这些有指示,请让我知道,因为以上必须重复新的安装。

如果这是系统GIT,那么您可以使用TOOLS ->选项中的选项 GIt选项卡来使用系统GIt,这就解决了源树中的问题。

我已经通过在${HOME}/中添加以下条目解决了这个问题。gitconfig文件

(远程“起源”)

代理=

在大多数情况下,当你的机器启用代理时,就会发生这种情况,所以上面提到的条目将解决这个问题。

git config --global http.sslbackend secure-transport

(必须在更新到Big sssr后这样做)

我也遇到过这个问题。最终在MSDN博客的指导下得到了解决。

更新

实际上,你需要在git的证书文件curl-ca-bundel中添加证书。位于Git\bin目录下。

步骤

Open your github page in browser, and click over lock icon in address bar. In the opened little popup up navigate to 'view certificate' link, it will open a popup window. In which navigate to certificates tab (3rd in my case). Select the top node that is root certificate. And press copy certificate button in the bottom and save the file. In file explorer navigate Git\bin directory and open curl-ca-bundle.crt in text editor. Open the exported certificate file (in step 3) in text editor as well. Copy all of the content from exported certificate to the end of curl-ca-bundle.crt, and save.

最后检查状态。请注意备份curl-ca-bundle。CRT文件之前编辑,以保持安全。

如果要完全禁用SSL验证,则打开Git Bash并运行该命令。

git config --global http.sslVerify false

注意:此解决方案使您容易受到中间人攻击等攻击。 因此,尽快再次开启验证:

git config --global http.sslVerify true