【问题标题】:Adding self-signed SSL certificate without disabling authority-signed ones添加自签名 SSL 证书而不禁用授权签名证书
【发布时间】:2023-04-02 09:45:01
【问题描述】:

我有一个使用自签名证书通过 https 工作的公司 git 服务器。本地克隆包含两个远程——一个指向该服务器的源,另一个指向 github。 默认情况下,从源拉取失败:

$ git pull
fatal: unable to access 'https://user@code.example.com/git/fizzbuzz.git/': SSL certificate problem: self signed certificate

github 远程工作正常。

有两种经常被推荐的解决方案:

git config http.sslVerify false

这是一个坏主意,在configure Git to accept a particular self-signed server certificate for a particular https remote 建议的那个:

git config http.sslCAInfo <downloaded certificate>.pem

修复了从原点拉取,但破坏了 github 远程:

$ git pull github
fatal: unable to access 'https://github.com/user/fizzbuzz.git/': SSL certificate problem: unable to get local issuer certificate

如何在不中断从 github 拉取的情况下从企业服务器拉取工作?

【问题讨论】:

    标签: git ssl github


    【解决方案1】:

    如果您使用的是 Git 1.8.5+(2013 年 8 月),您可以specify http directives per URL(!)

    在你的情况下:

    git config --global http."https://code.example.com/".sslVerify false
    #
    # or, if not on default 443 port:
    #
    git config --global http."https://code.example.com:<aPort>/".sslVerify false
    

    这将仅对code.example.com 禁用 SSL 验证,而不是对其他 URL。

    或者:

    git config --global http."https://code.example.com/".sslCAInfo <downloaded certificate>.pem
    

    同样的想法:sslCAInfo 将指向 &lt;downloaded certificate&gt;.pem 仅用于 code.example.com URL。

    可以将您的证书添加到 Git 系统证书存储中,使用 git-for-windows 将在 C:\path\to\PortableGit-2.6.1-64-bit\usr\ssl\certs\ca-bundle.crt 中。
    不过,这不是最佳做法,除非您必须分发包含内部证书的 Git 发行版。

    【讨论】:

    • 如何使用 *.mycompany.com 之类的通配符来匹配所有子域?
    • @bbodenmiller 我不知道你是否可以:这是一个很好的问题。
    • 第一个示例似乎不适用于全局。我们有一个带有自签名证书的 Intranet git 服务器,我尝试使用 URL 示例将 sslVerify 设置为 false。这对我们来说很有意义,因为我们在该域上有几十个项目,并且在本地配置文件中为每个项目配置它会很烦人。但它似乎根本不起作用。
    • @IroNEDR 你使用的是什么版本的 Git?该设置是在客户端设置的,而不是服务器端。
    • @IroNEDR 我想这个问题会在 Git 2.12 中持续存在吗?你看到了什么错误信息?
    【解决方案2】:

    Git for Windows 的v2.5.0 开始,已安装的证书文件已移至C:\Program Files (x86)\Git\mingw32\ssl\certs\ca-bundle.crt。您必须将您的证书添加到此文件中。

    【讨论】:

    • 对于其他人,请记住如果您拥有 64 位版本,Git 可能位于 `C:\Program Files\Git\mingw64` 中
    猜你喜欢
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 2020-10-25
    • 2011-12-03
    • 2020-09-20
    • 1970-01-01
    相关资源
    最近更新 更多