简体   繁体   English

Visual Studio:“信任证书失败”

[英]Visual Studio: "Failed trusting the certificate"

On Windows 10/11, With Visual Studio 2017-2022, when serving a web API via HTTPS with Kestrel or IIS, Visual Studio prompts me to trust the self-signed certificate that ASP.NET Core has generated. On Windows 10/11, With Visual Studio 2017-2022, when serving a web API via HTTPS with Kestrel or IIS, Visual Studio prompts me to trust the self-signed certificate that ASP.NET Core has generated.

If I click 'Yes', I receive the following error:如果我单击“是”,我会收到以下错误:

Adding the certificate to the Trusted Root Certificates store failed with the following error: Failed trusting the certificate.将证书添加到受信任的根证书存储失败并出现以下错误:信任证书失败。 (running Kestrel) or Access is denied. (运行 Kestrel)或访问被拒绝。 (running IIS) (运行 IIS)

Navigating to the swagger UI page via Chrome verifies that the certificate is indeed not valid and the connection is not secure.通过 Chrome 导航到 swagger UI 页面验证证书确实无效并且连接不安全。

Running dotnet dev-certs https --trust results in运行dotnet dev-certs https --trust结果

There was an error trusting HTTPS developer certificate.信任 HTTPS 开发者证书时出错。

From certmgr I can see the ASP.NET Core HTTPS development certificate has been installed in the Current User/Personal -store.从 certmgr 我可以看到 ASP.NET 核心 HTTPS 开发证书已安装在当前用户/个人商店中。 I also see the Trusted Root Certification Authorities -store, and the certificates inside.我还看到了Trusted Root Certification Authorities -store 和里面的证书。

If I try to drag and drop the certificate to the Trusted Root Certification Authorities -store, I receive the following error message:如果我尝试将证书拖放到 Trusted Root Certification Authorities -store,我会收到以下错误消息:

The certificate cannot be pasted into the Trusted Root Certification Authorities -store.无法将证书粘贴到受信任的根证书颁发机构 - 存储中。 Access is denied.访问被拒绝。

If I try to import the certificate to said store, I receive the following error message:如果我尝试将证书导入所述商店,我会收到以下错误消息:

The import failed because the store was read-only, the store was full, or the store did not open correctly.导入失败,因为存储是只读的、存储已满或存储未正确打开。

If I try to install the certificate from the exported file, via 'Install certificate' -> 'Current User' -> 'Place all certificates in the following store' -> Browse , I can't see the Trusted Root Certification Authorities -store at all.如果我尝试从导出的文件安装证书,通过'Install certificate' -> 'Current User' -> 'Place all certificates in the following store' -> Browse ,我看不到Trusted Root Certification Authorities -store一点也不。

If I select the 'Certificates - Current User' -header, go to View -> Options, and enable 'Physical certificate stores' , I am able to drag and drop the certificate into the physical store Trusted Root Certification Authorities/Local Computer/Certificates如果我 select 'Certificates - Current User' -header, go to View -> Options, and enable 'Physical certificate stores' ,我可以将证书拖放到物理存储Trusted Root Certification Authorities/Local Computer/Certificates

The certificate is now visible in the Trusted Root Certification Authorities store, but Visual Studio still throws the same error, browser thinks the cert is not trusted, and dotnet dev-certs https --check --trust outputs:该证书现在在受信任的根证书颁发机构存储中可见,但 Visual Studio 仍然抛出相同的错误,浏览器认为该证书不受信任,并且dotnet dev-certs https --check --trust输出:

No valid certificate found.未找到有效证书。

If I leave the original certificate in Personal , export it without the private key and import the export into the physical store Trusted Root Certification Authorities/Local Computer/Certificates , dotnet dev-certs https --check --trust prints:如果我将原始证书留在Personal中,则在没有私钥的情况下将其导出并将导出导入实体店Trusted Root Certification Authorities/Local Computer/Certificatesdotnet dev-certs https --check --trust打印:

A trusted certificate was found: ...找到受信任的证书:...

...but the browser still thinks the cert is invalid, and Visual Studio throws the error. ...但浏览器仍然认为证书无效,并且 Visual Studio 会抛出错误。

Same result with dotnet run , without the trusting error in Visual Studio.dotnet run的结果相同,在 Visual Studio 中没有信任错误。 It seems dotnet CLI does not check or attempt to trust the cert. dotnet CLI 似乎不检查或尝试信任证书。

Same same but different: if I save the cert from Chrome and attempt to add it to the Trusted Root Certification Authorities via Chrome -> Settings -> Privacy and security -> Manage certificates -> Trusted Root Certification Authorities -> Import , I also receive:相同但不同:如果我从 Chrome 保存证书并尝试通过Chrome -> Settings -> Privacy and security -> Manage certificates -> Trusted Root Certification Authorities -> Import将其添加到Trusted Root Certification Authorities ,我也会收到:

The import failed because the store was read-only, the store was full, or the store did not open correctly.导入失败,因为存储是只读的、存储已满或存储未正确打开。

I've run out of things to try, and there is probably something basic here I'm missing.我已经用完了可以尝试的东西,而且我可能缺少一些基本的东西。 What should I do?我应该怎么办?

So turns out that while I did delete all the localhost certificates in both user and machine stores, and reinstall IIS, somehow wrong localhost certificates were installed in the process, and I needed to delete them again, and install the one visible from the browser to the Local Computer certificates Trusted Root Certification store.事实证明,虽然我确实删除了用户和机器存储中的所有 localhost 证书,并重新安装了 IIS,但在此过程中安装了某种错误的 localhost 证书,我需要再次删除它们,然后将浏览器中可见的安装到本地计算机证书受信任的根证书存储。

Hope this helps someone in the future.希望这对将来的某人有所帮助。 Always check your serial numbers.始终检查您的序列号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM