简体   繁体   English

使用 TLS 1.2 从 HttpClient 连接到 Azure FrontDoor 后面的 API

[英]Connecting from HttpClient to API behind Azure FrontDoor using TLS 1.2

Azure Front Door is configured with minimum TLS 1.2. Azure Front Door 配置了最低 TLS 1.2。 The backend Azure App Service is also configured to use minimum TLS 1.2.后端 Azure 应用服务也配置为使用最低 TLS 1.2。

When running the .Net Framework 4.7.1 console app with the following code on Windows Server 2012 R2:在 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();
        }
    }

I get the following exception on the second call.我在第二次调用时收到以下异常。

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.

Running this with curl from the same server works, however:但是,在同一台服务器上使用 curl 运行它是可行的:

curl https://foo.myfoo.io/ -i --tlsv1.2 --tls-max 1.2

The same .net code runs fine from my other windows 10 laptop.相同的 .net 代码在我的其他 Windows 10 笔记本电脑上运行良好。

What can be the reason why the call fails on the windows server box?在 Windows 服务器机器上调用失败的原因可能是什么?

Edit:编辑:

I think this has to do with custom domains, since performing a simple GET to the front door assigned domain works.我认为这与自定义域有关,因为对前门分配的域执行简单的 GET 操作。

Turns out "someone" had disabled a lot of cipher suites on the Windows Server.结果是“某人”在 Windows Server 上禁用了很多密码套件。

I used wireshark to look at the TLS handshake and noticed that the cipher suites listed at the Client Hello didn't match the servers.我使用wireshark查看TLS握手并注意到Client Hello中列出的密码套件与服务器不匹配。

So for anyone struggling with TLS errors, it can be worthwile to look at the TLS handshake in Wireshark!因此,对于任何在 TLS 错误中苦苦挣扎的人来说,看看 Wireshark 中的 TLS 握手是值得的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM