【问题标题】:Any way to restrict ASP.NET Core 2.0 HTTPS to TLS 1.2?有什么方法可以将 ASP.NET Core 2.0 HTTPS 限制为 TLS 1.2?
【发布时间】:2017-10-19 14:31:02
【问题描述】:

我有一个运行良好的 ASP.NET Core 2.0 REST 服务器,但我需要限制对 TLS1.2 的访问 - 我该怎么做?似乎找不到任何关于它的文档。 服务器在 Kestrel 上运行。 谢谢!

【问题讨论】:

    标签: c# asp.net asp.net-core .net-core


    【解决方案1】:

    有一个UseHttps 重载允许您提供一个HttpsConnectionAdapterOptions 实例来配置它。以下是您的情况的示例:

    listenOptions.UseHttps(new HttpsConnectionAdapterOptions
    {
        ...
        SslProtocols = SslProtocols.Tls12
    });
    

    供参考,SslProtocols defaultsSslProtocols.Tls12 | SslProtocols.Tls11

    【讨论】:

      【解决方案2】:

      .net core 2.1 Kestrel 配置:

      .UseKestrel(c =>
                  {
                      c.ConfigureHttpsDefaults(opt =>
                      {
                          opt.SslProtocols = SslProtocols.Tls12;
                      });
                  })
      

      【讨论】:

        【解决方案3】:

        在 .Net Core 3.1 中,您可以通过在 Program.cs 的 ConfigureWebHostDefaults 中添加以下代码来强制使用 TLS 1.2

           webBuilder.UseKestrel(opt =>
                            {
                                opt.AddServerHeader = false;
                                opt.ConfigureHttpsDefaults(s =>
                                {
                                    s.SslProtocols = SslProtocols.Tls12;
                                });
                            });
        

        完整代码可见性如下图:

        【讨论】:

          猜你喜欢
          • 2018-12-02
          • 2018-08-30
          • 2019-06-06
          • 2016-06-26
          • 1970-01-01
          • 1970-01-01
          • 2018-03-02
          • 2019-06-28
          相关资源
          最近更新 更多