【问题标题】:curl always truncates the username after 63 characterscurl 总是在 63 个字符后截断用户名
【发布时间】:2013-02-06 20:10:32
【问题描述】:

我正在使用 _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 令牌很短)。


更新:

进一步调查似乎问题出在cURL,这是 GIT 用于 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

我开始失去对这件事的好结果的乐观态度。

【问题讨论】:

  • 我的猜测是 GitHub 使用短标记的原因正是您在上面找到的 ;-)

标签: git curl msysgit


【解决方案1】:

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

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

请注意,这似乎是 .netrc 文件使用的限制,因为 neither HTTP speccurl programmatic interface 有这个限制。事实上,如果你只是在 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 指定用户/密码
  • 在网址中使用用户名
  • 使用基于 ssh 的网址

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

  • _netrc: 64 (curl .netrc 限制)
  • 互动:256
  • credential.helper wincred: 512(Windows 凭据存储限制)
  • credential.helper 普通:4000+
  • 网址:4000+
  • 代理:无限制(应仅受 HTTP 和代理软件限制)

【讨论】:

  • 非常感谢您证实了我的怀疑。实际上,在 url 中发送用户名不受此限制的影响。我遇到的问题是我的令牌可能包含任意字符,我不知道如何在 url 中正确编码它们。自己编译 cURL 以及使用本地代理绝对是不可能的。您知道如何正确编码 url 中的用户名(假设它可能已经包含 :@=、...等字符)?
  • 如果这只是为了 Git 使用,也许 git-credentials 支持可以帮助你。使用 wincred 或 winstore 提供了一种使用 Windows 凭据 API 存储凭据的单独机制,因此比 .netrc 文件更安全。我没有测试过这些限制,但可能这些限制提供了更大的用户 ID。使用 wincred 就像 git config --global credential.helper wincred 一样简单。一旦您被要求提供 https url 的登录详细信息,此帮助程序会将它们存储在后备存储中以供下次重用。
  • @DarinDimitrov 标准 url 编码也适用于用户名和密码,如果它们被用作 url 方案的一部分
  • 我正在尝试 Windows 凭据存储方法。它看起来很有希望。我还不能让它工作,但一旦我做到了,我会发布更新并接受你的回答。
  • Windows Credential Store 运行良好。感谢您的宝贵支持。非常感谢。
猜你喜欢
  • 2015-08-11
  • 1970-01-01
  • 2019-12-01
  • 2016-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多