-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Given that you are using SslStream on Windows with .NET Core 3.1 (or .NET Framework), a TLS handshake failure presents itself as "The message received was unexpected or badly formatted.":
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception.
---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted --- End of inner exception stack trace --- at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
In actuality, this was a fatal TLS alert 40 that occurred because the client and server did not have any cipher suites in common.
This makes troubleshooting a little bit difficult and requires understanding how SChannel maps TLS alerts to SEC_E error codes. This is also complicated by SChannel mapping multiple TLS alerts to the same error code.
It would be very helpful if the exception included, or exposed, the actual handshake alert to make troubleshooting easier. Ideally, something along the lines of:
"TLS failed with fatal alert 40 (handshake_failure)"
I'm not clear at the moment what OpenSSL / SecureTransport does at the moment, but ideally troubleshooting TLS handshake issues is roughly the same on all platforms.
I'm also not clear if this is possible, if SChannel gives you the ability to get the raw alert. If not, perhaps there is still a way to improve the exception so people have a better time determining the root cause of the problem.