c# - 使用 TLS 1.2 从 HttpClient 连接到 Azure FrontDoor 后面的 API
问题描述
Azure Front Door 配置了最低 TLS 1.2。后端 Azure 应用服务也配置为使用最低 TLS 1.2。
在 Windows Server 2012 R2 上使用以下代码运行 .Net Framework 4.7.1 控制台应用程序时:
class Program
{
static async Task Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var client = new HttpClient();
try
{
var OK = await client.GetAsync("https://foo-appservice.azurewebsites.net/"); // App service.
var NotOK = await client.GetAsync("https://foo.myfoo.io/"); // Front door.
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
我在第二次通话中收到以下异常。
An error occurred while sending the request.
The underlying connection was closed: An unexpected error occurred on a send.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
但是,在同一台服务器上使用 curl 运行它是可行的:
curl https://foo.myfoo.io/ -i --tlsv1.2 --tls-max 1.2
相同的 .net 代码在我的其他 Windows 10 笔记本电脑上运行良好。
windows server box上调用失败的原因是什么?
编辑:
我认为这与自定义域有关,因为对前门分配的域执行简单的 GET 即可。
解决方案
原来“某人”在 Windows Server 上禁用了很多密码套件。
我使用 wireshark 查看 TLS 握手,并注意到 Client Hello 中列出的密码套件与服务器不匹配。
因此,对于任何为 TLS 错误而苦苦挣扎的人来说,看看 Wireshark 中的 TLS 握手是值得的!
推荐阅读
- php - 如何禁用和启用有条件的按钮
- python - np.where 计算不正确?
- javascript - 将嵌套数组导出为 xlsx 格式
- r - 阿尔法美学显示箭头的骨架而不是简单的形状 - 如何防止它?
- django-urls - 有没有一种在 django 中编写路径 url 的正确方法?
- sql-server - 在 CASE 表达式的 THEN 部分使用 IN 子句
- transactions - 有没有办法为交易记录上的名称字段提供全局搜索功能?
- flutter - 有没有办法降低 Flutter 中 TextFormField 小部件的高度
- mongodb - MongoDB一次多个查询
- apache-kafka - 接收数据时触发 Kafka Consumer