无法找到 Kestrel 使用的自签名受信任证书

Cant find self signed trusted certificate used by Kestrel

我有一个非常基本的自托管 .NET 核心 2.1 应用程序,配置如下:

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
             .UseKestrel()
             .UseContentRoot(Directory.GetCurrentDirectory())
             .UseStartup<Startup>()
             .Build();

        host.Run();
    }
}

和非常典型的简单控制器如下:

   [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }

这个应用程序在我测试它并导航到我的 HTTPS 本地端点端口(在我的例子中是 44325)时工作得很好:

https://localhost:44325/api/values

到目前为止一切都很好。现在我想弄清楚这个 HTTPS 连接的证书来自哪里,因为我没有使用 IIS Express,而且证书确实不属于 IIS Express:

当我搜索其指纹时,我无法在我的证书库中找到上述证书。这个证书是如何生成的?我在哪里可以找到它?为什么此证书在 Edge 和 chrome 中有效,但在 Firefox 中却不受信任?它是即时生成的吗?

我的启动设置如下:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:55894",
      "sslPort": 44325
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Experimental1": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "applicationUrl": "https://localhost:44325;http://localhost:55894",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

我使用的是 Experimental1 配置文件而不是 IIS Express,当我 运行 应用程序时我看到了我的小控制台。

How does this certificate gets generated?

.NET Core SDK 在我们第一次生成证书时 运行 dotnet new

https://blogs.msdn.microsoft.com/webdev/2018/02/27/asp-net-core-2-1-https-improvements/

Where can I find it?

SDK 将 ASP.NET 核心 HTTPS 开发证书安装到本地用户证书存储中。

why does this certificate work in Edge and chrome but in Firefox its not trusted?

确实如此。即使在 运行ning dotnet dev-certs https --trust 之后,Firefox 也不信任该证书并抱怨说,“该证书不受信任,因为它是自签名的。

可能只是 。我的解决方法是添加安全例外。