【问题标题】:OS X: Git with client certificates rejectedOS X:客户端证书被拒绝的 Git
【发布时间】:2015-01-14 03:07:34
【问题描述】:

我们通过将以下行添加到 ~/.gitconfig 来使用客户端证书访问我们的 Git 服务器

[http]
        sslCAInfo = /path/to/git-ca.crt
        sslCert = /path/to/git-client.crt
        sslKey = /path/to/git-client.pem

这在具有完全相同文件的 Linux、Windows 和 OS X

bash-3.2$ git fetch
fatal: unable to access 'https://ourserver:12345/repository.git/': SSL: Can't load the certificate "/path/to/git-client.crt" and its private key: OSStatus -25299

git version 1.9.3 (Apple Git-50)git version 2.0.1 都会出现问题。

更新 从 KeyChain 中删除相应的项目后,我遇到了以下崩溃:

bash-3.2$ git fetch
2014-11-17 09:58:51.257 git-remote-https[2787:12194] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff9828164c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8f91c6de objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff98125068 -[__NSPlaceholderArray initWithObjects:count:] + 360
    3   CoreFoundation                      0x00007fff98124a2d CFArrayCreate + 141
    4   libcurl.4.dylib                     0x00007fff8f75169e darwinssl_connect_common + 2089
    5   libcurl.4.dylib                     0x00007fff8f75073a Curl_ssl_connect_nonblocking + 36
    6   libcurl.4.dylib                     0x00007fff8f719673 Curl_http_connect + 77
    7   libcurl.4.dylib                     0x00007fff8f727977 Curl_protocol_connect + 129
    8   libcurl.4.dylib                     0x00007fff8f739cef multi_runsingle + 799
    9   libcurl.4.dylib                     0x00007fff8f73993d curl_multi_perform + 170
    10  git-remote-https                    0x0000000109815c8a step_active_slots + 25
    11  git-remote-https                    0x0000000109815cfb run_active_slot + 77
    12  git-remote-https                    0x0000000109817621 http_request + 459
    13  git-remote-https                    0x0000000109816148 http_request_reauth + 34
    14  git-remote-https                    0x0000000109813f76 discover_refs + 476
    15  git-remote-https                    0x00000001098131e4 main + 1556
    16  libdyld.dylib                       0x00007fff94bd25c9 start + 1
    17  ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException

在这次崩溃之后,证书条目再次出现在钥匙串中。奇怪的是,在 OS X 10.8 上,从存储库中获取任何内容都不会添加到我的钥匙串中。

更新 2 当我在 OS X 10.9 上尝试相同的操作时,出现以下错误:

bash-3.2$ git fetch
fatal: unable to access 'https://ourserver:12345/repository.git/': SSL certificate problem: Invalid certificate chain

更新 3 即使在 OS X 10.9 上,我也可以使用这些证书成功连接 openssl

bash-3.2$ openssl s_client -connect ourserver:12345 -cert /path/to/git-client.crt -key /path/to/git-client.pem
CONNECTED(00000003)
depth=1 /C=de/O=companyca/CN=internal-ca
verify error:num=19:self signed certificate in certificate chain
verify return:0
---
Certificate chain
 0 s:/C=de/O=companyserv/CN=smart
   i:/C=de/O=companyca/CN=internal-ca
 1 s:/C=de/O=companyca/CN=internal-ca
   i:/C=de/O=companyca/CN=internal-ca
---
Server certificate
...
<----------------------snip---------------------->
...
---
SSL handshake has read 2348 bytes and written 1360 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: E5873AF43D24CEE6529178B4EFD7FE3368711DF1BFBC6CA89C50F8D39DE0B014
    Session-ID-ctx: 
    Master-Key: <**********>
    Key-Arg   : None
    Start Time: 1416486728
    Timeout   : 300 (sec)
    Verify return code: 19 (self signed certificate in certificate chain)
---
closed

问题看起来类似于this one for GitHub,但我们使用的是自签名证书。

【问题讨论】:

  • 25299 表示“指定的项目已存在于钥匙串中”。也许您将公钥两次复制到 crt 文件中?
  • 感谢您的提示。我从 KeyChain 中删除了该项目。
  • @ThomasS。那么,它解决了你的问题吗?
  • 不,请参阅上面的更新。我现在遇到了崩溃。
  • 您是如何创建.pem 文件的?

标签: git curl osx-mavericks osx-yosemite client-certificates


【解决方案1】:

您似乎面临与this docker issue 相同的问题,他们认为这可能是 OSX curl 中的错误。

在一些other post 他们建议,这可能是由于证书序列号为 1 或太大而无法容纳 32 位。

在您的 OS X 10.9 案例中,我认为“无效证书”应该通过将证书添加到系统密钥链作为受信任来解决(在 this question 中讨论)。

This post 描述了 OS X curl 的一些变化,这似乎是相关的。据我了解,切换到不同的curl implementation 可能是一种解决方案(但可能只有在使用 brew 安装 git 时才有效)。

【讨论】:

  • 不幸的是,我在链接中找到的信息都没有帮助解决问题。我不得不在 OS X 10.9+ 上从带有客户端证书的 https 切换到 SSH。
【解决方案2】:

正如 Michal 已经提到的,这是一个 OSX curl 错误。一个可能的解决方案是安装一个不依赖 osx curl 实现的 git 版本

  1. 安装macports:https://www.macports.org/install.php
  2. $port -v 自我更新
  3. $port 安装 git

【讨论】:

  • 不幸的是,这不是一个选项,因为我们不能指望最终用户的机器上安装 macports。
  • 在 10.11 上对我不起作用 .. 我用自制的,但它仍然失败
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-17
相关资源
最近更新 更多