Botbuilder-samples: You have to specify TLS version during create WebSocketSharp.WebSocket in C# sample code.

Created on 7 Jul 2018  路  5Comments  路  Source: microsoft/BotBuilder-Samples

My issue is about DirectLine sample code of BotBuilder SDK for .NET, which is located at:
Samples/blob/master/core-DirectLineWebSockets/DirectLineClient

SDK platform is .NET

URL of Code Sample

https://github.com/Microsoft/BotBuilder-Samples/blob/master/CSharp/core-DirectLineWebSockets/DirectLineClient/Program.cs#L40

Problem Description

When I use above code to create a WebSocket to connect DirectLine I always get below error:
WebSocketSharp.WebSocketException: An error has occurred during a TLS handshake. ---> System.NotSupportedException: The requested security protocol is not supported.
at System.Net.SecurityProtocol.ThrowOnNotAllowed(SslProtocols protocols, Boolean allowNone)
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()

Actually, the root cause is web server of DirectLine service forced TLS v1.2 but WebSocketSharp doesn't specified yet.

How to fix

Add below line after created WebSocketSharp.WebSocket object:
// You have to specify TLS version to 1.2 or connection will be failed in handshake. WebSocketClient.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;

Support help wanted

Most helpful comment

OK, I will do it soon.

All 5 comments

Would you like to submit a PR to add this code to the sample?

OK, I will do it soon.

Let's make sure we take the PR in the v3 branch

@EricDahlvang, to get the PR ready.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daveRendon picture daveRendon  路  6Comments

arunprasathv picture arunprasathv  路  3Comments

HesselWellema picture HesselWellema  路  9Comments

pesarkhobeee picture pesarkhobeee  路  9Comments

clearab picture clearab  路  4Comments