Closed okarpov closed 1 year ago
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones See info in area-owners.md if you want to be subscribed.
Author: | okarpov |
---|---|
Assignees: | - |
Labels: | `area-System.Net.Security` |
Milestone: | - |
Do you know if this fails with Tls12 only @okarpov? I would expect so as Server 2012 does not support TLS 13. I also think this is not actionable as written. Could you please some up with minimal runable repro and possible server that can be used for testing?
This issue has been marked needs-author-action
and may be missing some important information.
this should be completely standalone working method you can run udner Console. Unfortunately i have no other server like that and can not share my client's server credentials, sorry. do not know about Tls12 only or not
void CheckBrokerFMCSA(string mcNum="235546")
{
try
{
string resp = string.Empty;
var socketsHandler = new System.Net.Http.HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.All,
SslProtocols = System.Security.Authentication.SslProtocols.Tls13 | System.Security.Authentication.SslProtocols.Tls12,
ServerCertificateCustomValidationCallback = CertValidCallback,
ClientCertificateOptions = ClientCertificateOption.Automatic,
CheckCertificateRevocationList = false,
};
var sockHandler = (System.Net.Http.SocketsHttpHandler)GetUnderlyingSocketsHttpHandler(socketsHandler);
sockHandler.SslOptions = new SslClientAuthenticationOptions()
{
AllowRenegotiation = true,
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls13 | System.Security.Authentication.SslProtocols.Tls12,
RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; })
};
using (System.Net.Http.HttpClient wc = new System.Net.Http.HttpClient(socketsHandler, true))
{
wc.DefaultRequestVersion = System.Net.HttpVersion.Version20;
wc.DefaultVersionPolicy = System.Net.Http.HttpVersionPolicy.RequestVersionOrLower;
wc.DefaultRequestHeaders.Accept.TryParseAdd("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
wc.DefaultRequestHeaders.AcceptEncoding.TryParseAdd("gzip, deflate, br");
wc.DefaultRequestHeaders.AcceptLanguage.TryParseAdd("en-US,en;q=0.9");
wc.DefaultRequestHeaders.TryAddWithoutValidation("sec-ch-ua", "\"Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104\"");
wc.DefaultRequestHeaders.TryAddWithoutValidation("ContentType", "application/x-www-form-urlencoded");
wc.DefaultRequestHeaders.TryAddWithoutValidation("origin", "https://safer.fmcsa.dot.gov");
wc.DefaultRequestHeaders.Referrer = new Uri("https://safer.fmcsa.dot.gov/");
wc.DefaultRequestHeaders.UserAgent.TryParseAdd("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36");
resp = wc.PostAsync("https://safer.fmcsa.dot.gov/query.asp", new StringContent(
"searchtype=ANY&query_type=queryCarrierSnapshot&query_param=MC_MX&query_string=" + mcNum
)).Result.Content.ReadAsStringAsync().Result;
}
resp = resp;
}
catch (System.Net.WebException wex)
{
try
{
using (var wexstream = new System.IO.StreamReader(wex.Response.GetResponseStream()))
{
wex=wex;
}
}
catch(Exception wwex)
{
wwex=wwex;
}
}
catch (Exception ex)
{
ex=ex;
}
return res;
}
protected static bool CertValidCallback(HttpRequestMessage s, X509Certificate2 e, X509Chain a, SslPolicyErrors b)
{
return true;
}
public static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) { return true; }
protected static object GetUnderlyingSocketsHttpHandler(System.Net.Http.HttpClientHandler handler)
{
return typeof(System.Net.Http.HttpClientHandler).GetField("_underlyingHandler", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.GetValue(handler);
}
@okarpov I am unable to reproduce the issue with the console code you provided on Win 11. Does removing Tls13
from the SslProtocols
fix the problem on your machine?
I'm afraid that without more info the this issue is not actionable for us.
This issue has been marked needs-author-action
and may be missing some important information.
This issue has been automatically marked no-recent-activity
because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity
.
This issue will now be closed since it had been marked no-recent-activity
but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.
Description
Reproduction Steps
Expected behavior
should return HTML content
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
IIS Server .Net 3.1 - .Net 7.0
Other information
Windows Server 2012 R2 Standard