noobot / SlackConnector

A simple to use connector/client for the Slack API in C#
http://github.com/noobot
MIT License
73 stars 44 forks source link

Cannot get SlackConnector to work with Slack TLS 1.2 #87

Closed creeveswelton closed 4 years ago

creeveswelton commented 4 years ago

I am using .net version 4.6.1, and I have verified that TLS 1.2 is available and enabled on the server, Windows Server 2012 R2.

I have tried adding this line of code to the startup section of the program.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

This is the code I use to connect to slack, but the connection fails because I suspect that TLS encryption is failing.

var connector = new SlackConnector.SlackConnector();
            _connection = await connector.Connect(slackKey);
            _connection.OnMessageReceived += MessageReceived;
            _connection.OnDisconnect += OnDisconnect;
            _connection.OnReconnecting += OnReconnecting;
            _connection.OnReconnect += OnReconnect; 

This is the exception we get when initially trying to connect to the Slack server.

02:00:03.3613 ERROR [5] - Bot: Start - Error connecting to Slack: System.AggregateException: One or more errors occurred. ---> WebSocketSharp.WebSocketException: An error has occurred during a TLS handshake. ---> System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The function requested is not supported --- End of inner exception stack trace --- at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) at WebSocketSharp.WebSocket.setClientStream() --- End of inner exception stack trace --- at WebSocketSharp.WebSocket.setClientStream() at WebSocketSharp.WebSocket.doHandshake() at WebSocketSharp.WebSocket.connect() --- 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 SlackConnector.SlackConnector.d6.MoveNext() --- 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 SlackConnector.SlackConnector.d5.MoveNext() --- 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 Welton.SlackbotApi.WBotCore.d__7.MoveNext() in C:\BuildAgent1\work\ebdb82161931e455\Company.SlackbotApi\WBotCore.cs:line 47 --- End of inner exception stack trace ---

The program tries to reconnect to slack multiple times in a loop an we eventually get this timeout which is because we are flooding the server with reconnect messages that fail.

---> (Inner Exception #0) SlackConnector.Exceptions.CommunicationException: Error occured while sending message '429' at SlackConnector.Connections.Clients.ResponseVerifier.VerifyResponse[T](IRestResponse response) at SlackConnector.Connections.Clients.RequestExecutor.d4`1.MoveNext() --- 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 SlackConnector.Connections.Clients.Handshake.HandshakeClient.d3.MoveNext() --- 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 SlackConnector.SlackConnector.d__5.MoveNext() --- 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)

Any tips would be helpful. Not sure if this is an issue with the package itself or I am just using it incorrectly.

Thanks!