gpt4 book ai didi

c# - HTTP/2 与 ASP.NET Core 2.2

转载 作者:行者123 更新时间:2023-12-02 01:03:50 24 4
gpt4 key购买 nike

我正在尝试让 HTTP/2 与 ASP.Net Core 2.2 一起使用。我正在 Windows 10 x64 1809 上进行测试。

我将基本模板与以下网络主机构建器一起使用:

public static IWebHostBuilder CreateWebHostBuilderKestrel(string[] args)
{
var builder = WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Any, 35000,
lo =>
{
lo.Protocols = HttpProtocols.Http1AndHttp2;
lo.UseHttps(@"path to cert");
});
});
return builder;
}

使用 Chrome 时,它​​接受证书并通过 HTTPS 显示网站。问题在于,在检查 devtools 部分中的网络请求时,它使用的是 HTTP/1.1 而不是 h2。

使用openssl s_client -connect 'host:35000' -cipher "EDH" 给出以下输出:

New, TLSv1.2, Cipher is DHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : DHE-RSA-AES256-GCM-SHA384
Session-ID: FA0F0000C66FFFD36BE15AE79B2F48DF631EB83D0425DD534DAA278622CB30AE
Session-ID-ctx:
Master-Key: 2B10E9FD71B42328CAFAFBE18789777132565A98CE8CFD9B8E0452F6490929CB6D1B20AB57A000EDBFF40372C93EB547
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1552937526
Timeout : 7200 (sec)
Verify return code: 20 (unable to get local issuer certificate)
Extended master secret: yes
---

看起来不合适的一件事是“未协商 ALPN”和“支持安全重新协商”。我在这里错过了什么吗?

The msdn site lists the following requirements :

TLS version 1.2 or later
Renegotiation disabled
Compression disabled
Minimum ephemeral key exchange sizes:
Elliptic curve Diffie-Hellman (ECDHE) [RFC4492] – 224 bits minimum
Finite field Diffie-Hellman (DHE) [TLS12] – 2048 bits minimum
Cipher suite not blacklisted

不确定如何检查大部分设置。其中一些看起来像是证书的设置,而另一些则似乎是特定于应用程序的。

最佳答案

我不确定这是否是你的情况,但遇到类似的问题,我发现了一件奇怪的事情 -

这是代码中的设置不起作用 -

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(opt =>
{
int port = 44336;
opt.ListenAnyIP(port, listenOptions =>
{
listenOptions.UseHttps(@"cert.pfx", "...");
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
});
})
.UseStartup<Startup>();

现在,如果我通过 appsettings.json 配置相同的内容,它会突然开始通过 HTTP/2 提供请求 -

  public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseStartup<Startup>();

"AllowedHosts": "*",
"Kestrel": {
"EndPoints": {
"HttpsInlineCertFile": {
"Url": "https://localhost:44336",
"Protocols": "Http1AndHttp2",
"Certificate": {
"Path": "./cert.pfx",
"Password": "..."
}
}
}
}

除此之外,以下是我对要求的看法:

  • TLS 版本 1.2 或更高版本 - 我想任何浏览器/Fiddler/Postman 都能够为您提供此信息。
  • 重新协商已禁用 - 如果我没记错的话,自 TLS 1.2 以来,服务器重新协商已被禁用。否则,将DisableRenegoOnServer注册表项设置为非零值将有所帮助 - HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\DisableRenegoOnServer| DWORD=1
  • 压缩已禁用 - 不确定,但可能与您在启动代码中设置的响应压缩有关
  • 最小临时 key 交换大小 - 您可以检查 Chrome 中的 DevTools/Security 选项卡,我知道 FireFox 可以为您提供更多详细信息。查看How-to-identify-the-Cipher-used-by-an-HTTPS-Connection .
  • 密码套件未列入黑名单 - 一旦您了解连接,您可以检查 BadCipherSuites

关于c# - HTTP/2 与 ASP.NET Core 2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55228929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com