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

MHO*_*OOS 4 https kestrel-http-server asp.net-core asp.net-core-webapi asp.net-core-2.0

我有一个非常基本的自托管.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();
    }
}
Run Code Online (Sandbox Code Playgroud)

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

   [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)
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我测试它并导航到我的HTTPS本地端点端口(在我的情况下为44325)时,此应用程序工作正常:

HTTPS://本地主机:44325/API /值

在此输入图像描述

到目前为止都很好.现在我想弄清楚这个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"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

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

Sha*_*tin 9

该证书是如何生成的?

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

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

我在哪里可以找到它?

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

在此输入图像描述

为什么这个证书在Edge和chrome中有效,但在Firefox中它不受信任?

确实.即使运行后dotnet dev-certs https --trust,Firefox不信任证书,并抱怨说," 该证书不被信任,因为它是自签名的. "

可能只是Firefox不再信任自签名证书.我的解决方法是添加安全性异常.

在此输入图像描述