首页 > 解决方案 > git clone 时连接中出现未知的 SSL 协议错误

问题描述

我必须通过代理访问互联网,所以在我的环境中进行以下配置:

export https_proxy=https://proxy.xxx.xxx:xxx

但是当我通过“https”链接从 github(或任何其他 git repo)克隆代码时,出现错误:

sunyi-ubuntu# git clone https://github.com/git/git.git
fatal: unable to access 'https://github.com/git/git.git/': Unknown SSL protocol error in connection to github.com:443

但是,奇怪的是它可以工作,只要我跑了一个curl权利,git clone如下所示:

sunyi-unbunt:~# git clone https://github.com/git/git.git
Cloning into 'git'...
fatal: unable to access 'https://github.com/git/git.git/': Unknown SSL protocol error in connection to github.com:443
sunyi-ubuntu:~# curl https://github.com/git/git.git >& /dev/null
sunyi-ubuntu:~# git clone https://github.com/git/git.git
Cloning into 'git'...
remote: Enumerating objects: 138, done.
remote: Counting objects: 100% (138/138), done.
remote: Compressing objects: 100% (74/74), done.
Receiving objects:   0% (1/271365)

我正在使用 Ubuntu 16.04.3 我安装了 libcurl4-openssl-dev 我构建并安装了最新的 git 源代码。以下是我的日志export GIT_CURL_VERBOSE=1

Cloning into 'git'...
* Couldn't find host github.com in the .netrc file; using defaults
*   Trying 10.239.4.80...
* Connected to proxy.xxx.xxx (10.239.4.80) port xxx (#0)
* Establish HTTP proxy tunnel to github.com:443
> CONNECT github.com:443 HTTP/1.1
Host: github.com:443
User-Agent: git/2.22.0.545.g9c9b961
Proxy-Connection: Keep-Alive

< HTTP/1.1 407 Proxy Authentication Required
< Proxy-Authenticate: NEGOTIATE
< Proxy-Authenticate: NTLM
< Proxy-Authenticate: BASIC realm="CORP_AD"
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: text/html; charset=utf-8
< Proxy-Connection: close
< Connection: close
< Content-Length: 849
<
* Ignore 849 bytes of response-body
* Connect me again please
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* Unknown SSL protocol error in connection to github.com:443
* Closing connection 0
* Couldn't find host github.com in the .netrc file; using defaults
* Hostname proxy.xxx.xxx was found in DNS cache
*   Trying 10.239.4.80...
* Connected to proxy.xxx.xxx (10.239.4.80) port 914 (#1)
* Establish HTTP proxy tunnel to github.com:443
> CONNECT github.com:443 HTTP/1.1
Host: github.com:443
User-Agent: git/2.22.0.545.g9c9b961
Proxy-Connection: Keep-Alive

< HTTP/1.1 407 Proxy Authentication Required
< Proxy-Authenticate: NEGOTIATE
* gss_init_sec_context() failed: : SPNEGO cannot find mechanisms to negotiate
< Proxy-Authenticate: NTLM
< Proxy-Authenticate: BASIC realm="CORP_AD"
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: text/html; charset=utf-8
< Proxy-Connection: close
< Connection: close
< Content-Length: 849
<
* Received HTTP code 407 from proxy after CONNECT
* Closing connection 1
fatal: unable to access 'https://github.com/git/git.git/': Unknown SSL protocol error in connection to
 github.com:443

========更新========

Git 通过代理。克隆时出现 407 错误的原因是什么?

我已经尝试了上一页提到的几乎所有选项,但没有一个有效。但是我刚刚找到了一种解决方法,它git在运行 a 后会很好地工作curl,无论给 curl 提供什么样的参数。所以以下别名对我来说总是很有效: alias git='curl u >& /dev/null & git' 但我仍然好奇这个问题的根本原因!

标签: gitsslcurlproxyopenssl

解决方案


推荐阅读