由于 ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY,ASP.NET Core 3.0 应用在 Windows Server 2012 R2 上无法正常工作。

13
我拿了一个工作中的ASP.NET Core 2.2应用程序,将其升级到3.0后,突然在Windows Server 2012上无法正常工作。它出现以下错误: ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY
Chrome: enter image description here Firefox: enter image description here 似乎以前我必须选择HTTP/2,现在它与HTTP1.1一起成为默认值。这里有一篇文章 https://github.com/aspnet/AspNetCore/issues/14350 ,但是那完全令人困惑,没有真正的解决方案。
我尝试了各种启用/禁用不安全协议的方法,但都没有成功。例如:https://www.admin-enclave.com/de/articles-by-year/11-data-articles/website_articles/articles/exchange_articles/405-resolved-error-err_spdy_inadequate_transport_security-when-using-google-chome-and-owa.html 在Windows 10上运行良好,因为我认为它具有更好的协议套件。但是在Fiddler中检查时,与Kestrel进行协商的唯一区别是:

Windows Server 2012 R2:

[0A0A]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[1301]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[1302]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[1303]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[C02B]  TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
[C02F]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[C02C]  TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
[C030]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[CCA9]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[CCA8]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[C013]  TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
[C014]  TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
[009C]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[009D]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[002F]  TLS_RSA_AES_128_SHA
[0035]  TLS_RSA_AES_256_SHA
[000A]  SSL_RSA_WITH_3DES_EDE_SHA

Windows 10:

[3A3A]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[1301]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[1302]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[1303]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[C02B]  TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
[C02F]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[C02C]  TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
[C030]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[CCA9]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[CCA8]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[C013]  TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
[C014]  TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
[009C]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[009D]  Unrecognized cipher - See http://www.iana.org/assignments/tls-parameters/
[002F]  TLS_RSA_AES_128_SHA
[0035]  TLS_RSA_AES_256_SHA
[000A]  SSL_RSA_WITH_3DES_EDE_SHA

顶部的行不同,但这就是全部。不确定它是什么,它是一些{{GREASE}}值。

Program.cs:

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
      WebHost.CreateDefaultBuilder(args)
      .UseKestrel(opts => {
        opts.ListenAnyIP(5000);
        opts.ListenAnyIP(5001, listenOpts => {
          listenOpts.UseHttps(new HttpsConnectionAdapterOptions {
            ServerCertificate = new X509Certificate2("certificate-server.pfx", "...")
          });
        });
        opts.Limits.MaxRequestBodySize = null;
      })
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>();
  }

更新

看起来我正在正确的轨道上,感谢@chris-pratt。将证书密码更改为ECDSA_nistP256使Web应用程序工作。但不幸的是,我也使用证书签名JWT令牌,现在出现了错误:

System.NotSupportedException:不支持证书密钥算法。在 System.Security.Cryptography.X509Certificates.PublicKey.get_Key()

签名代码如下:

  var privateKey = new X509SecurityKey(new X509Certificate2("certificate-server.pfx", "..."));
  var token = new JwtSecurityToken(
    issuer: "Sentry",
    claims: claims,
    notBefore: DateTime.Now,
    expires: DateTime.Now.AddDays(1),
    signingCredentials: new SigningCredentials(privateKey, SecurityAlgorithms.RsaSha256Signature));

  return new JwtSecurityTokenHandler().WriteToken(token);

我尝试更改SecurityAlgorithms枚举,但没有成功。


你有任何在该服务器上运行的ASP.NET Core 3.0应用程序吗?我想您可能需要通过服务器管理器添加角色/功能到服务器。 - Icculus018
@ChrisPratt 这是我使用PowerShell创建的自签名证书,命令为New-SelfSignedCertificate -DnsName localhost -NotAfter (Get-Date).AddMonths(120) -CertStoreLocation cert:\LocalMachine\My,我该如何查找正在使用的密码套件? - Colton Scottie
@ChrisPratt IE 11 报告连接为“TLS 1.2,128 位加密的 AES(高级);2048 位交换的 RSA”。 - Colton Scottie
Windows 的默认密码套件不支持 HTTP/2。请尝试使用 -AlternateSignatureAlgorithm 参数重新生成它。 - Chris Pratt
有任何进展吗? - McVitas
显示剩余8条评论
2个回答

4

Windows 2012 R2不支持HTTP/2所允许的加密套件。我猜测从Core 3.0开始,HTTP/2协议将默认启用。我通过以下方式在kestrel中禁用HTTP/2来解决我的问题:

public static IHostBuilder CreateHostBuilder(string[] args) =>

  Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
  {
      webBuilder.UseKestrel(options =>
      {
        options.Listen(System.Net.IPAddress.Parse(DomainIp), 80);
        options.Listen(System.Net.IPAddress.Parse(DomainIp), 443, l =>
        {
          l.UseHttps(
            DomainCertificateFile,
            DomainCertificatePassword);
          l.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1;
        });
      });
      webBuilder.UseStaticWebAssets();
      webBuilder.UseStartup<Startup>();
   });

这对我来说是有效的,但这会产生后果。我的 API 本身会发出外部 https GET 请求,由于 https 协商错误而失败。 - baouss
1
@baouss 在我的 Blazor 项目中,我使用 HttpClient 进行出站 HTTPS 调用。这在 Http1(在 W2012 Server 上)和 Http2(在 Windows 10 上)上都可以工作。 - Holger Schmeken
感谢确认在该设置上运行正常。我今天才意识到,机器的注册表中禁用了TLS 1.2,但我调用的服务需要它。 - baouss

1
我将添加其他可能对他人有用的信息。在IIS中,HTTP/2支持从Windows 10和Windows Server 2016开始。请参见: IIS上的HTTP/2
然而,在Windows 10中您也可能会遇到这个问题。在这种情况下,请确保禁用HTTP/2是否真的是您要寻找的,特别是涉及安全问题。让我们参考OP提到的GitHub线程

“这将禁用HTTP/2,“INADEQUATE_TRANSPORT_SECURITY”问题是一个特定于HTTP/2的问题,所以虽然它可以解决问题,但不是真正的解决方案。”

来源: GitHub讨论 为了解决在Windows 10下出现的此问题,首先建议确保SSL密码套件顺序正确。
为了配置SSL密码套件顺序组策略设置,请按以下步骤操作:
  1. 在命令提示符中输入gpedit.msc。出现组策略对象编辑器
  2. 展开计算机配置、管理模板、网络,然后单击SSL配置设置
  3. SSL配置设置下,单击SSL密码套件顺序设置。
  4. SSL密码套件顺序窗格中,滚动到窗格底部。
  5. 按照标记为如何修改此设置的说明进行操作。
参见:优先使用Schannel密码套件

Cipher Suite Order

它可能与默认值不同并引起问题。或者如果默认值引起问题,这是您可以进行调整的地方。

回到最初的问题。@hristijankiko给我们发送了一些非常有用的细节(包括一个非常有帮助的Wireshark跟踪)。我们确定服务器选择了HTTP/2块列表上的一个密码套件,因为“安全性不足”。事实证明,这是由于从早期的Windows版本升级而导致的机器级配置问题。解决方法是手动配置TLS密码套件以匹配新的Windows 10默认设置 (请参见https://learn.microsoft.com/en-us/windows/win32/secauthn/tls-cipher-suites-in-windows-10-v1903)。 有趣的是,即使@hristijankiko使用的是Windows 10 v1903,但仍然需要这样做,我们将在内部检查这个问题。在ASP.NET Core中原始问题无需进一步操作。

来源: 进一步的GitHub讨论

在此,您可以检查给定Windows版本支持哪些TLS密码套件和优先级顺序:

TLS/SSL(Schannel SSP)中的密码套件

对于Windows Server 2012 R2和Windows 8.1支持的密码套件,请参见:

Windows 8.1中的TLS密码套件

您可以在开发人员工具的安全选项卡下快速查看所选密码套件: 开发人员工具的安全选项卡


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接