Skip to content

SSL/TLS authentication failure with "An unknown error occurred while processing the certificate #349

Description

@lircy

Description:
I've implemented a WebSocket server using Fleck, but encountering SSL/TLS authentication failures when clients attempt to connect. The server throws an AggregateException with nested AuthenticationException and Win32Exception.

Error Log:

Failed to Authenticate System.AggregateException: One or more errors occurred. ---> System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
   --- 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.EndAuthenticateAsServer(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
   --- 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.EndAuthenticateAsServer(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)<---

Environment:

  • Fleck version: 1.2
  • .NET Runtime: .NetFramework4.7.2
  • OS: Win10 Pro

Reproduction Steps:

  1. Configure WebSocket server with SSL:
    static void Main(string[] args)
         {
             FleckLog.Level = LogLevel.Debug;
             var allSockets = new List<IWebSocketConnection>();
             var server = new WebSocketServer("wss://0.0.0.0:8181");
             server.Certificate = new X509Certificate2("test.com.pfx", "930718");
             server.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
             server.ListenerSocket.NoDelay = true;
             server.RestartAfterListenError = true;
             server.Start(socket =>
             {
                 socket.OnOpen = () =>
                 {
                     Console.WriteLine("Open!");
                     allSockets.Add(socket);
                 };
                 socket.OnClose = () =>
                 {
                     Console.WriteLine("Close!");
                     allSockets.Remove(socket);
                 };
                 socket.OnMessage = message =>
                 {
                     Console.WriteLine(message);
                     allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
                 };
             });
             var input = Console.ReadLine();
             while (input != "exit")
             {
                 foreach (var socket in allSockets.ToList())
                 {
                     socket.Send(input);
                 }
                 input = Console.ReadLine();
             }
         }
  2. Attempt connection from WebSocket client
  3. Server immediately throws the authentication exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions