Modifying TLS SNI with HttpClient or HttpWebRequest

折月煮酒 提交于 2019-12-08 02:05:38

问题


This question is the equivalent of this Go question in which it was trivial (albeit rather hacky) to obtain the desired behavior: I am looking for a way to modify the TLS SNI information that ultimately ends up in the TCP segments created when using the high-level web clients in .NET.

The final paragraph in this answer suggests that a hack would be to do something like

static void Main(string[] args)
{
    HttpResponseMessage response;
    var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://desiredsni.com");
    httpRequestMessage.Headers.Add("Host", "example.com");
    var handler = new HttpClientHandler
    {
        CookieContainer = new CookieContainer()
    };
    using (var client = new HttpClient(handler))
    {
        response = client.SendAsync(httpRequestMessage).Result;
    }
}

to perform a request to desiredsni.com with a host of example.com and an SNI of desiredsni.com. Nevertheless, in my testing, and contrary to what is suggested by the answer, the SNI tag is changed to example.com, which is no good in my case, as what I want is really for the Host header field to be one thing, and the SNI field to be something else (and I'll settle for removing SNI entirely). Similarly, letting httpRequestMessage.RequestUri = new Uri("https://example.com"); also updates the SNI tag to example.com.

Is there a straightforward way to modify what ends up in the SNI field using HttpClient, HttpWebRequest, or something similar, without modifying anything else in the TCP segment?

来源:https://stackoverflow.com/questions/54186478/modifying-tls-sni-with-httpclient-or-httpwebrequest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!