当TLSv1失败并显示"忽略的未知记录"时,使git恢复为SSLv3

Yas*_*ser 5 git libcurl

不能用git:

git clone https://github.com/foo/bar
Run Code Online (Sandbox Code Playgroud)

失败:

fatal: unable to access 'https://github.com/foo/bar': Unknown SSL  protocol error in connection to github.com:443
Run Code Online (Sandbox Code Playgroud)

我如何强制git使用SSLv3?我试图从源代码编译git,但没有设置超出:( --with-openssl默认).在第408行之前添加以下行remote-curl.c也不起作用:

 curl_easy_setopt(slot->curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
Run Code Online (Sandbox Code Playgroud)

以下是一些线索:

  • 案例1:当我的浏览器尝试访问时https://github.com/foo/bar,它首先尝试TLSv1.握手似乎没问题:服务器密钥交换,服务器问候完成(在Wireshark).但它遵循服务器的"忽略的未知记录",最后来自服务器的"连接重置".那么新的连接,但用的SSLv3踢和每一件事情是罚款(见图片).

  • 案例2:curl使用TLSv1失败

    curl https://github.com/foo/bar
    
    Run Code Online (Sandbox Code Playgroud)

    失败:

    curl: (35) Unknown SSL protocol error in connection to github.com:443
    
    Run Code Online (Sandbox Code Playgroud)

    设置--sslv3修复了问题.

  • 案例3:拿这一个

    sudo add-apt-repository  ppa:cassou/emacs
    
    Run Code Online (Sandbox Code Playgroud)

    失败:

    pycurl.error: (35, 'gnutls_handshake() failed: A TLS packet with unexpected length was received.')
    
    Run Code Online (Sandbox Code Playgroud)

编辑:curl 7.22.0(i686-pc-linux-gnu)libcurl/7.22.0 OpenSSL/1.0.1.

编辑:调试信息

Cloning into 'bar'...
* Couldn't find host github.com in the .netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 192.30.252.130... * Connected to github.com (192.30.252.130) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
    CApath: /etc/ssl/certs
* Unknown SSL protocol error in connection to github.com:443
* Closing connection #0
fatal: unable to access 'https://github.com/foo/bar/': Unknown SSL       protocol error in connection to github.com:443
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 5

2015年8月更新:Git 2.6 +(2015年第3季度)将允许明确指定SSL版本:

http:添加对指定SSL版本的支持

请参阅Elia Pinto()提交01861cb(2015年8月14日). 帮助:Eric Sunshine().(由Junio C Hamano合并- -提交ed070a4,2015年8月26日)devzero2000
sunshineco
gitster

http.sslVersion
Run Code Online (Sandbox Code Playgroud)

如果要强制使用默认值,则在协商SSL连接时使用的SSL版本.
可用和默认版本取决于libcurl是针对NSS还是OpenSSL构建的,以及正在使用的加密库的特定配置.在内部设置' CURLOPT_SSL_VERSION'选项; 有关此选项的格式以及支持的ssl版本的更多详细信息,请参阅libcurl文档.
实际上,此选项的可能值为:

  • SSLV2
  • SSLV3
  • 使用TLSv1
  • tlsv1.0
  • tlsv1.1
  • TLSv1.2工作

可以被' GIT_SSL_VERSION'环境变量覆盖.
要强制git使用libcurl的默认ssl版本并忽略任何显式http.sslversion选项,请将'GIT_SSL_VERSION'设置为空字符串.


原答案Dec:2013

当我的PROXY环境变量未正确设置时,我通常会看到错误消息:

export HTTP_PROXY=http://user:password@proxy.mycompany.com:port
export HTTPS_PROXY=http://user:password@proxy.mycompany.com:port
export NO_PROXY=.mycompany.com
Run Code Online (Sandbox Code Playgroud)

您还可以设置~/.netrc file GitHub凭据.

确保您git config http.sslcainfo确实引用了您的/path/to/git/bin/curl-ca-bundle.crt,以便curl能够验证与GitHub服务器关联的证书.


如果https确实不起作用,一种解决方法是使用ssh url

git clone ssh://user@server:project.git
Run Code Online (Sandbox Code Playgroud)

(如果您先生成了私钥和公钥,并将该公钥注册到您的GitHub帐户)