我刚刚按照这里的程序: 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
我已经使用以下方式配置了 curl .curlrc
:
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 更新证书数据库,但没有任何效果。(似乎与单声道比与 dotnetcore 更相关,即使 dotnet 核心构建页面提到它)。
在深入研究 corefx 代码后,System.Net.Http 的 Curl 处理程序似乎并未在所有情况下都设置正确的 ssl 选项(如Simple Curl SSL sample 中)。
我试过泰勒解决方案:
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 构建(只是因为他们的开发页面讲述了 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默认值,也不禁用证书验证。