【问题标题】:Nuget Package restore failing on Ubuntu 20.04 with remote certificate is invalid在 Ubuntu 20.04 上使用远程证书的 Nuget 包还原失败无效
【发布时间】:2022-01-07 18:10:37
【问题描述】:

我尝试在 Ubuntu 20.04 虚拟机上构建一个 .net core 3.1 项目。

项目构建成功,我现在需要更新项目中的一个 NuGet 包。一旦我将 .csproj 文件中的包版本更改为所需版本,当我构建或执行“dotnet restore”时,我会收到以下消息:

/usr/share/dotnet/sdk/3.1.415/NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/home/ic/Source/redacted.csproj]
/usr/share/dotnet/sdk/3.1.415/NuGet.targets(128,5): error :   The SSL connection could not be established, see inner exception. [/home/ic/Source/redacted.csproj]
/usr/share/dotnet/sdk/3.1.415/NuGet.targets(128,5): error :   The remote certificate is invalid according to the validation procedure. [/home/ic/Source/redacted.csproj]

如果我浏览到https://api.nuget.org/v3/index.json,我可以在浏览器中成功查看json,并且证书似乎是受信任的。

我有:

【问题讨论】:

  • 你用的是什么浏览器?例如,Firefox 有自己的证书存储。此外,根证书可能有效,而叶证书无效 - 这对于 api.nuget.org 仍然很奇怪。
  • Edge、Chrome 和 Firefox(都在 Ubuntu 中)都报告证书正常。

标签: c# .net ssl nuget ubuntu-20.04


【解决方案1】:

不确定到底是什么真正解决了我的问题,但是,长话短说,我认为以下方法有效:

在 api.nuget.org 上运行 wget 给出:

--2021-12-02 09:38:34--  https://api.nuget.org/v3/index.json
Resolving api.nuget.org (api.nuget.org)... 152.199.40.167
Connecting to api.nuget.org (api.nuget.org)|152.199.40.167|:443... connected.
ERROR: cannot verify api.nuget.org's certificate, issued by 'CN=Microsoft Azure TLS Issuing CA 05,O=Microsoft Corporation,C=US’:
  Unable to locally verify the issuer's authority.
To connect to api.nuget.org insecurely, use `--no-check-certificate'.

在研究该错误时,我重新安装了 ca-certificates(不确定这是否与解决问题有关):

sudo apt-get install --reinstall ca-certificates

最终,我发现:"dotnet restore" fails with "SSL peer certificate or SSH remote key was not OK" 导致我设置 SSL_CERT_FILE 环境变量:

export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

这似乎是关键,现在 dotnet restore 可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多