代码之家  ›  专栏  ›  技术社区  ›  aherrick

Windows不接受自签名的SSL证书

  •  0
  • aherrick  · 技术社区  · 8 年前

    在本地,我使用IIS创建并导出了一个自签名证书。结果是一个pfx文件。

    我已将其加载到我的ASP.NET核心解决方案中,并按如下方式旋转Kestrel:

    var certificatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "cert.pfx"));
    var certificate = new X509Certificate2(certificatePath, "certpass");
    
    HostWeb = builder
        .UseKestrel(options =>
        {
            options.Listen(IPAddress.Loopback, 44321, listenOptions =>
            {
                listenOptions.UseHttps(certificate);
            });
        })
        .UseUrls("https://localhost:44321")
        .UseEnvironment("Test").Build();
    HostWeb.Start();
    

    当我在这个Web服务器上运行chrome时,它仍然显示不安全。

    我这里缺什么?还有什么需要我配置的吗?

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  1
  •   PKI Guy    8 年前

    从chrome导出证书,方法是单击“不安全”,然后单击“证书”、“详细信息”选项卡,然后单击“复制到文件…”,然后选择一个文件将证书写入磁盘。

    然后,双击证书,单击“安装证书…”,将“存储位置”保留为“当前用户”,选择“将所有证书放在以下存储中”,选择“受信任的根证书颁发机构”,然后完成向导。

    你得到的警告将消失。

    注意:这只能应用于开发环境。

        2
  •  0
  •   Daboul    8 年前

    我相信您需要在操作系统级别注册此证书,以便将其视为有效证书。默认情况下,自签名证书不会是。我用那个链接来做: https://www.humankode.com/asp-net-core/develop-locally-with-https-self-signed-certificates-and-asp-net-core

    尤其是这部分:

    # import the pfx certificate
    Import-PfxCertificate -FilePath $pfxFilePath Cert:\LocalMachine\My -Password $pfxPassword -Exportable
    
    # trust the certificate by importing the pfx certificate into your trusted root
    Import-Certificate -FilePath $cerFilePath -CertStoreLocation Cert:\CurrentUser\Root
    
    # optionally delete the physical certificates (don’t delete the pfx file as you need to copy this to your app directory)
    # Remove-Item $pfxFilePath
    Remove-Item $cerFilePath
    

    更新:您的代码正在设置您的服务器在安全连接初始化(握手)期间将提供给客户机的证书。但是,您的客户必须能够将此证书识别为有效证书,他需要信任它,以信任发出此证书的颁发机构。例如,您信任StackOverflow,因为您信任将其服务器提供给您的客户机的证书的授权Digicert。

    enter image description here

    更新2:关于主题的新文章: https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx