我刚刚遵循了下面的步骤: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证书。我尝试过的版本:
我使用.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核心使用libcurl
,但它显然不使用.curlrc
。
编辑:2016年6月21日
也尝试用mozroot更新证书数据库,但没有产生任何效果。(与dotnetcore相比,即使dotnet核心构建页面提到了它,它似乎更与mono相关)。
在深入研究corefx代码之后,System.Net.Http的Curl处理程序似乎没有在所有情况下都设置正确的ssl选项(比如在简单卷SSL样本中)。
我尝试过泰勒解决方案:
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核心使用libcurl构建(仅仅因为他们的开发页面告诉了openssl版本(而且它们是相互排斥的)。顺便说一句,我尝试过使用libcurl的nss构建,而dotnet还原仍然失败。
IMHO,该问题与证书注册错误无关,但更多的原因是没有正确禁用curl内置证书验证(因为证书验证是在System.Net.Http中完成的,并且必须向客户端代码提供自定义此验证的能力)。
为什么它发生在我的机器上而不是在其他地方?一定是和我的利伯尔版本有关。
然而,所有这些都只是暂时的假设。
编辑22/05/2016:
通过更深入地查看代码,特别是在比较主分支和RC2发行版时,可以清楚地看到SSL处理代码仍然有很大的变化。
因此,我只需获取RC2代码并修改它,以反映主分支所做的事情:
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核心中处理它,但在主程序上的当前代码中,情况仍然不是这样,更多的是两者的混合)。
对于根本原因,我认为我处于一个特定的设置中:
curlconfig --ca
返回一个空字符串。而且它不读取CURL_CA_BUNDLE
环境变量或.curlrc
文件。发布于 2016-06-23 10:40:49
打开SSL缺少的包证书
openssl
.的根本原因缺少配置
如果运行以下命令(或类似的命令):
openssl verify /usr/share/ca-certificates/nuget.crt
您将得到以下结果:
/usr/share/ca-certificates/nuget.crt: C = US, ST = Washington, L = Redmond, O = Microsoft Corporation, OU = Microsoft IT, CN = Microsoft IT SSL SHA2
error 2 at 1 depth lookup:unable to get issuer certificate
140075910137504:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:703:Expecting: TRUSTED CERTIFICATE
140075910137504:error:0B06F009:x509 certificate routines:X509_load_cert_file:PEM lib:by_file.c:162:
这是因为openssl
( dotnet / libcurl最终依靠它进行ssl检查)不知道在哪里找到ca包。我在/etc/ssl/openssl.cnf
中没有看到任何相关的参数
export OPENSSL_CONF=/etc/ssl/openssl.cnf
不会对openssl验证失败有所帮助。
但是,下面的修复了两个问题(openssl和nuget)
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
现在openssl
的输出
zsh/2 906 [1] # openssl verify /usr/share/ca-certificates/nuget.crt
/usr/share/ca-certificates/nuget.crt: OK
对于dotnet restore
zsh 904 # dotnet restore
log : Restoring packages for /home/user/test/project.json...
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json 412ms
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json 409ms
info : Committing restore...
log : Lock file has not changed. Skipping lock file write. Path: /home/user/test/project.lock.json
log : /home/user/test/project.json
log : Restore completed in 4412ms.
NuGet Config files used:
/home/user/.nuget/NuGet/NuGet.Config
Feeds used:
https://api.nuget.org/v3/index.json
特别感谢泰勒,他帮助我保持了修复这个问题的动力。
发布于 2016-06-21 04:15:48
从何处导入证书当前重定向到在建/停工页面。维护完成后,再试一次。我认为这对Mozilla或mozroot的维护者来说都是一个小小的错误。您在控制台输出中看到的要么是堆栈跟踪,要么是Couldn't retrieve the file using the supplied information.
,这取决于您构建的mozroot。
解决方法是以某种方式使用certmgr导入正确的CA证书,然后导入端点证书(使用certmgr -ssl -m https://api.nuget.org
)。如果证书的CA丢失,则证书被视为无效。如果证书被认为无效,则可以导入它们,但还原仍然会造成恐慌,调用证书缺少匹配的颁发机构CA cert。
我说,不知怎么说,因为我还没有想出一个好的安全的方法来建议你这么做。我肯定会在我构建的下一个mono+dotnet码头图像中使用适当的mozroot证书。
较新版本的mozroot有命令行参数来替代证书数据端点。现在将使用web.archive.org副本作为mozroots --url ...
的替代品。看看我是否可以只使用这或者这,或者使用Mozilla的另一个certdata.txt
。
发布于 2019-12-19 09:42:28
如果在码头容器中出现此错误,则运行
那就停止你机器里的对接程序。重新启动机器并从一开始就运行所有内容。
https://stackoverflow.com/questions/37838500
复制相似问题