【问题标题】:Cant find self signed trusted certificate used by Kestrel找不到 Kestrel 使用的自签名可信证书
【发布时间】:2018-12-18 09:54:53
【问题描述】:

我有一个非常基本的自托管 .NET core 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,我在运行应用程序时看到了我的小控制台。

【问题讨论】:

    标签: asp.net-core https asp.net-core-2.0 asp.net-core-webapi kestrel-http-server


    【解决方案1】:

    这个证书是如何生成的?

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

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

    我在哪里可以找到它?

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

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

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

    可能只是Firefox no longer trusts self-signed certificates。我的解决方法是添加一个安全例外。

    【讨论】:

    • 如果它对某人有帮助,我可能会遇到与此类似的问题,因为我以不同的 AD 用户身份运行 VS 并且必须生成新证书。在使用了一段时间之后,我加载了 MMC 并看到了很多 localhost 的证书。我删除了所有这些,重新生成了一个新的,然后我又恢复了业务。我的具体消息类似于在“null”处找不到证书
    猜你喜欢
    • 1970-01-01
    • 2013-09-28
    • 2020-12-15
    • 2015-11-25
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2018-09-28
    相关资源
    最近更新 更多