10

我正在使用该_netrc文件来存储客户端凭据以进行基本身份验证,并注意到 msysgit 总是在第 63 个字符处截断用户名。

这是我的%HOME%\_netrc样子:

# username for local repos
machine localhost
login 12345678901234567890123456789012345678901234567890123456789012345
password secret

我定义了一个 65 个字符的用户名。

然后我尝试克隆一个存储库:

C:\work>git clone https://localhost:44305/git myrepo

这是输出(带有GIT_CURL_VERBOSE=1GIT_SSL_NO_VERIFY=true):

Cloning into 'myrepo'...
* About to connect() to localhost port 44305 (#0)
*   Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 44305 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt CApath: none
* 0x214a410 is at send pipe head!
* Expire cleared
* SSL connection using AES128-SHA
* Server certificate:
*        subject: CN=localhost
*        start date: 2012-10-23 06:41:25 GMT
*        expire date: 2022-10-23 00:00:00 GMT
*        issuer: CN=localhost
*        SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> GET /git/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Unauthorized
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/8.0
< WWW-Authenticate: Basic Realm="MyRealm"
< X-AspNet-Version: 4.0.30319
< X-SourceFiles: =?UTF-8?B?Yzpcd29ya1xUb0REXFdlYkFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcZ2l0XGluZm9ccmVmcw==?=
< X-Powered-By: ASP.NET
< Date: Thu, 21 Feb 2013 13:05:56 GMT
< Content-Length: 4975
<
* Ignoring the response-body
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'https://localhost:44305/git/info/refs?service=git-upload-pack'
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 44305 (#0)
* 0x214a410 is at send pipe head!
* Server auth using Basic with user '123456789012345678901234567890123456789012345678901234567890123☻'
> GET /git/info/refs?service=git-upload-pack HTTP/1.1
Authorization: Basic MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzAjpzZWNyZXQ=
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/plain; charset=utf-8
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-SourceFiles: =?UTF-8?B?Yzpcd29ya1xUb0REXFdlYkFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcZ2l0XGluZm9ccmVmcw==?=
< X-Powered-By: ASP.NET
< Date: Thu, 21 Feb 2013 13:05:56 GMT
< Content-Length: 2
<
* Expire cleared
* Connection #0 to host localhost left intact
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 44305 (#0)
* 0x214a410 is at send pipe head!
* Server auth using Basic with user '123456789012345678901234567890123456789012345678901234567890123☻'
> GET /git/HEAD HTTP/1.1
Authorization: Basic MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzAjpzZWNyZXQ=
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/plain; charset=utf-8
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-SourceFiles: =?UTF-8?B?Yzpcd29ya1xUb0REXFdlYkFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcZ2l0XEhFQUQ=?=
< X-Powered-By: ASP.NET
< Date: Thu, 21 Feb 2013 13:05:56 GMT
< Content-Length: 2
<
* Expire cleared
* Connection #0 to host localhost left intact
warning: You appear to have cloned an empty repository.

请注意 msysgit 如何在第 63 个字符处截断用户名:

123456789012345678901234567890123456789012345678901234567890123☻

然后我禁用了该_netrc文件并尝试以交互方式输入用户名和密码,但这次我尝试输入 256 个字符:

C:\work>git clone https://localhost:44305/git myrepo

这是交互式会话:

Cloning into 'myrepo'...
* Couldn't find host localhost in the _netrc file; using defaults
* About to connect() to localhost port 44305 (#0)
*   Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 44305 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt CApath: none
* 0x22ea410 is at send pipe head!
* Expire cleared
* SSL connection using AES128-SHA
* Server certificate:
*        subject: CN=localhost
*        start date: 2012-10-23 06:41:25 GMT
*        expire date: 2022-10-23 00:00:00 GMT
*        issuer: CN=localhost
*        SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> GET /git/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

* The requested URL returned error: 401
* Closing connection #0
Username for 'https://localhost:44305': 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 
Password for 'https://1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456@localhost:44305':
* Couldn't find host localhost in the _netrc file; using defaults
* About to connect() to localhost port 44305 (#0)
*   Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 44305 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt CApath: none
* SSL re-using session ID
* 0x22ea410 is at send pipe head!
* Expire cleared
* SSL connection using AES128-SHA
* Server certificate:
*        subject: CN=localhost
*        start date: 2012-10-23 06:41:25 GMT
*        expire date: 2022-10-23 00:00:00 GMT
*        issuer: CN=localhost
*        SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> GET /git/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Unauthorized
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/8.0
< WWW-Authenticate: Basic Realm="GitApi"
< X-AspNet-Version: 4.0.30319
< X-SourceFiles: =?UTF-8?B?Yzpcd29ya1xUb0REXFdlYkFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcZ2l0XGluZm9ccmVmcw==?=
< X-Powered-By: ASP.NET
< Date: Thu, 21 Feb 2013 13:16:35 GMT
< Content-Length: 4975
<
* Ignoring the response-body
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'https://localhost:44305/git/info/refs?service=git-upload-pack'
* Couldn't find host localhost in the _netrc file; using defaults
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 44305 (#0)
* 0x22ea410 is at send pipe head!
* Server auth using Basic with user '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345'
> GET /git/info/refs?service=git-upload-pack HTTP/1.1
Authorization: Basic MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1OnNlY3JldA==
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/plain; charset=utf-8
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-SourceFiles: =?UTF-8?B?Yzpcd29ya1xUb0REXFdlYkFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcZ2l0XGluZm9ccmVmcw==?=
< X-Powered-By: ASP.NET
< Date: Thu, 21 Feb 2013 13:16:35 GMT
< Content-Length: 2
<
* Expire cleared
* Connection #0 to host localhost left intact
* Couldn't find host localhost in the _netrc file; using defaults
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 44305 (#0)
* 0x22ea410 is at send pipe head!
* Server auth using Basic with user '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345'
> GET /git/HEAD HTTP/1.1
Authorization: Basic MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1OnNlY3JldA==
User-Agent: git/1.7.11.msysgit.1
Host: localhost:44305
Accept: */*
Pragma: no-cache

< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/plain; charset=utf-8
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-SourceFiles: =?UTF-8?B?Yzpcd29ya1xUb0REXFdlYkFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcZ2l0XEhFQUQ=?=
< X-Powered-By: ASP.NET
< Date: Thu, 21 Feb 2013 13:16:35 GMT
< Content-Length: 2
<
* Expire cleared
* Connection #0 to host localhost left intact
warning: You appear to have cloned an empty repository.

这次用户名在第 255 个字符处被截断。

我曾尝试在标准 MS-DOS 提示以及 PowerShell 提示和 Git Bash 提示下使用 msysgit,结果相同。

所以这是我的问题:

  1. 这是 msysgit 的一些限制吗?
  2. 是否可以增加此限制(对于_netrc文件和交互式提示)?
  3. 有什么解决方法吗?

如果你问我为什么需要这么长的用户名,那是因为我的目标是为自定义 GIT 服务器发送 OAuth 令牌,就像 GitHub 一样(除了他们的 OAuth 令牌很短)。


更新:

进一步调查似乎问题在于cURLGIT用于HTTP客户端的内容。我可以使用以下命令重现完全相同的行为:

curl --netrc -kv https://localhost:44305/git

所以我重新提出这个问题。


更新 2:

进一步调查netrc.c

/* make sure we have room for at least this size: */
#define LOGINSIZE 64
#define PASSWORDSIZE 64

我开始失去对由此产生良好结果的乐观情绪。

4

1 回答 1

9

是的,这似乎是 curl 的限制。您引用的代码不是最新的:我认为 this 是,并且具有相同的值。

对于 windows,cygwin 版本的 git 修复了 msysgit 的一些限制,例如路径大小限制。但是,由于这是 curl 而不是 msysgit 的限制,因此它无能为力,而且当我测试时确实存在相同的行为。

请注意,这似乎是 .netrc 文件使用的限制,因为HTTP 规范curl 编程接口都没有这个限制。实际上,如果您只是在 url 中指定它,它似乎可以工作:

C:\REMenu>git remote add origin https://1234567890123456789012345678901234567890123456789012345678901234567890@github.com/romaonthego/REMenu.git

C:\REMenu>git push origin master
...
* Server auth using Basic with user '1234567890123456789012345678901234567890123456789012345678901234567890'
..
Password for 'https://1234567890123456789012345678901234567890123456789012345678
901234567890@github.com':

如果您需要使用 _netrc,我认为您唯一的选择是自己编译 curl 如果您需要它工作。

如果您不必这样做,您还有其他选择:

  • 运行为您指定用户/密码的本地代理,并在连接时使用该代理,为 git 或 curl 指定无用户/密码
  • 在 url 中使用用户名
  • 使用基于 ssh 的 url

编辑:回顾一下,到目前为止我们看到的限制:

  • _netrc:64(卷曲 .netrc 限制)
  • 互动:256
  • credential.helper wincred: 512 (windows credential store limit)
  • credential.helper 平原:4000+
  • 网址:4000+
  • 代理:无限制(应仅受 HTTP 和代理软件限制)
于 2013-02-21T15:17:14.540 回答