-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behavior in SslStream.AuthenticateAsClient
across win/linux
#81590
Comments
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsDescriptionOn .NET 7.0, While this appears to be host specific and is dependent on the parameters to On Linux, you will simply get a connection reset:
Reproduction StepsRun this code across both Windows and Linux: using System.Net.Security;
using System.Net.Sockets;
public class Program
{
public static void Main()
{
TcpClient client = new TcpClient("143.166.83.22", 443);
SslStream sslStream = new SslStream(client.GetStream(), false);
sslStream.AuthenticateAsClient(new SslClientAuthenticationOptions(){TargetHost = "143.166.83.22",RemoteCertificateValidationCallback = (sender, x509Certificate, chain, errors) => true});
}
} Expected behaviorAs seen on Windows: A connection is established. Actual behaviorAs seen on Linux: Connection is reset:
Regression?No response Known WorkaroundsNot settings ConfigurationWindows:
Linux, wsl:
Other informationNo response
|
This is kinda interesting. I can replicate this using openssl cli
If I omit the -servername parameter (equivalent to not specifying The difference in behavior is caused by difference between SChannel and OpenSSL. SChannel will not send the SNI extension when you specify the From RFC 6066 - transport Layer Security (TLS) Extensions: Extension Definitions
The specific server in question (pc-premierce80.us.dell.com) is kinda picky about SNI and will close the connection when SNI can be interpreted as IP address. Not all servers behave like this btw. We can probably check if the Not critical for 8.0, moving to future. This should also be relatively simple, so it is a good candidate for external contribution. |
https://www.rfc-editor.org/rfc/rfc6066#page-7
I think we should fix it @rzikm even if the server behavior is finicky. |
I did not realize the issue cannot be avoided with HttpClient. So fixing the issue in 8.0 makes more sense. I think fixing it on SslStream level (not passing TargetHost to underlying platform crypto) should be enough, no need to do the same on HttpClient level. |
Description
On .NET 7.0,
SslStream.AuthenticateAsClient
behaves differently on Windows and Linux. WhenTargetHost
is set for theSslClientAuthenticationOptions
parameter, in some cases on Linux it will lead to the connection not establishing successfully, while it does on Windows.While this appears to be host specific and is dependent on the parameters to
AuthenticateAsClient
, the fact that the very same code does not function the same across OS is problematic, leading to a lot of wasted time.On Linux, you will simply get a connection reset:
Reproduction Steps
Run this code across both Windows and Linux:
Expected behavior
As seen on Windows: A connection is established.
Actual behavior
As seen on Linux: Connection is reset:
Regression?
No response
Known Workarounds
Not setting
TargetHost
can help in some cases.Configuration
Windows:
Linux, wsl:
Other information
No response
The text was updated successfully, but these errors were encountered: