我刚刚按照这里的程序进行操作: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-预览1-002702
- 1.0.0-预览2-003100
我已经使用以下命令配置了curl.curlrc
:
cacert=/etc/ssl/certs/ca-certificates.crt
它已修复curl -I https://api.nuget.org
调用。
However 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
明显地。
编辑:2016 年 6 月 21 日
也尝试使用 mozroots 更新证书数据库,但没有任何效果。 (即使 dotnet core 构建页面提到它,似乎与 mono 的关系比与 dotnetcore 的关系更密切)。
深入研究 corefx 代码后,System.Net.Http 的 Curl 处理程序似乎并未在所有情况下设置正确的 ssl 选项(例如简单的 Curl SSL 示例).
我试过了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 构建(只是因为他们的开发页面讲述 openssl 版本(并且它们是互斥的)。顺便说一句,我尝试使用 libcurl 的 nss 构建,但 dotnet 恢复仍然失败。
恕我直言,这个问题与错误的证书注册无关,但更多的是关于curl内置证书验证未正确禁用的事实(因为证书验证是在System.Net.Http中完成的,并且必须向客户端代码提供以下能力:自定义此验证)。
为什么它发生在我的机器上而不是其他地方?
肯定和我的libcurl版本有关。
然而,所有这些目前都只是假设。
编辑2016年5月22日:
通过更彻底地查看代码,特别是在比较 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 core中处理它,但在master上的当前代码中,情况仍然不是这样,它更像是两者的混合)。
对于根本原因,我认为我正在进行特定的设置:
- libcurl 构建时没有任何默认证书捆绑路径。
curlconfig --ca
返回一个空字符串。并且它不读取CURL_CA_BUNDLE
环境变量或.curlrc
file.
- System.Net.Http(dotnet-core 的)既不设置 ca 默认值,也不禁用证书验证。