【发布时间】:2016-10-16 17:59:18
【问题描述】:
我刚刚按照这里的程序进行了操作: https://www.microsoft.com/net/core#ubuntu
这是dotnet restore的输出
log : Restoring packages for /home/test/project.json...
error: Unable to load the service index for source https://api.nuget.org/v3/index.json.
error: An error occurred while sending the request.
error: SSL peer certificate or SSH remote key was not OK
我已将相关证书添加到受信任的证书中,以使curl 工作,但dotnet restore 的错误仍然存在。
我试图挖掘核心源代码以了解 Nuget 如何检查 SSL 证书却没有运气。 我尝试过的版本:
- 1.0.0-preview1-002702
- 1.0.0-preview2-003100
我已经使用 .curlrc 配置了 curl:
cacert=/etc/ssl/certs/ca-certificates.crt
它已修复 curl -I https://api.nuget.org 调用。
但是dotnet restore -v Debug 仍然失败:
trace: Running restore with 8 concurrent jobs.
trace: Reading project file /home/user/test/project.json.
log : Restoring packages for /home/user/test/project.json...
trace: Restoring packages for .NETCoreApp,Version=v1.0...
error: Unable to load the service index for source https://api.nuget.org/v3/index.json.
error: An error occurred while sending the request.
error: SSL peer certificate or SSH remote key was not OK
trace: System.AggregateException: One or more errors occurred. (Unable to load the service index for source https://api.nuget.org/v3/index.json.) ---> NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://api.nuget.org/v3/index.json. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: SSL peer certificate or SSH remote key was not OK
trace: at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
所以 dotnet core 使用 libcurl,但显然没有使用 .curlrc。
编辑:21/06/2016
也尝试使用 mozroots 更新证书数据库,但没有任何效果。 (即使 dotnet core 构建页面提到它,似乎与 mono 的关系比与 dotnetcore 更相关)。
深入研究 corefx 代码后,System.Net.Http 的 Curl 处理程序似乎并未在所有情况下都设置正确的 ssl 选项(如在Simple Curl SSL sample 中)。
我已经尝试过Tyler 解决方案:
certmgr -ssl -m https://api.nuget.org
即使我输入 'y', 'yes', '1', 'true' 或其他任何内容,这也不会添加最后一个证书。
mozroots --url https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt --sync --import
这会做一些事情:
Importing certificates into user store...
194 new root certificates were added to your trust store.
Import process completed.
我不相信 dotnet core 使用了 libcurl nss 构建(只是因为他们的 development page 讲述了 openssl 版本(并且它们是互斥的)。顺便说一下,我尝试使用 libcurl 的 nss 构建并且 dotnet restore 仍然失败。
恕我直言,问题与错误的证书注册无关,而更多是因为 curl 内置证书验证未正确禁用(因为证书验证是在 System.Net.Http 中完成的,并且必须提供给客户端代码自定义此验证的能力)。
为什么它发生在我的机器上而不是其他地方? 它必须与我的 libcurl 版本有关。
然而,所有这些都只是暂时的假设。
编辑 22/05/2016:
通过更彻底地查看代码,尤其是在比较 master 分支和 RC2 版本时,很明显 SSL 处理代码仍然有很大的变化。
所以我只是抓取 RC2 代码并对其进行修改以反映 master 分支的作用:
easy.SetCurlOption(Interop.Http.CURLoption.CURLOPT_SSL_VERIFYHOST, 0);
然而,它并没有改变任何东西......但预测它是。 所以这里是我使用的代码:
easy.SetCurlOption(Interop.Http.CURLoption.CURLOPT_SSL_VERIFYPEER, 0);
然后将 System.Net.Http.dll 替换为禁用 ssl 证书检查。 不安全,但暂时解除对我的阻止。
我没有将其添加为答案,因为它更像是破解而不是修复。
(真正的解决方法是完全禁用 curl 完成的证书检查,并始终在 .Net 核心中处理它,但在 master 上的当前代码中,情况仍然不是这样,它更像是两者的混合)。
对于根本原因,我认为我处于特定设置中:
- libcurl 构建时没有任何默认证书捆绑路径。
curlconfig --ca返回一个空字符串。而且它不会读取CURL_CA_BUNDLE环境变量或.curlrc文件。 - System.Net.Http(dotnet-core)既不设置 ca 默认值,也不禁用证书验证。
【问题讨论】:
标签: .net ssl-certificate ubuntu-14.04 dotnet-cli