问题
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