websocket-client icon indicating copy to clipboard operation
websocket-client copied to clipboard

Ignore SSL errors caused by self signed certificate

Open NateKomodo opened this issue 4 years ago • 7 comments

I am unable to connect to a websocket based API running locally as it uses a self signed certificate. How can i disable certificate validation?

NateKomodo avatar Feb 29 '20 17:02 NateKomodo

Disabling SSL validation is done globally in .NET and not specific to websocket client. See: https://stackoverflow.com/questions/38138952/bypass-invalid-ssl-certificate-in-net-core

Marfusios avatar Mar 01 '20 10:03 Marfusios

I'm using .NET framework, not .NET core

NateKomodo avatar Mar 03 '20 18:03 NateKomodo

The same approach, they brought it back to .NET core for backward compatibility.

Marfusios avatar Mar 03 '20 18:03 Marfusios

I'm not sure why youre pointing me to that post, ServicePointManager.ServerCertificateValidationCallback has no effect on this, and ServerCertificateCustomValidationCallback requires a http handler

NateKomodo avatar Mar 03 '20 18:03 NateKomodo

Then, unfortunately, cannot help you, I used ServicePointManager.ServerCertificateValidationCallback sometime in the past and it worked.

It seems they added a new API for this in version 2.1 of netstandard (which is not covered by .NET Framework). https://social.msdn.microsoft.com/Forums/vstudio/en-US/8fb8dc56-580e-42a0-a89d-706f2d1417aa/add-remotecertificatevalidationcallback-to-clientwebsocket?forum=netfxbcl

Marfusios avatar Mar 03 '20 19:03 Marfusios

_ws = new System.Net.WebSockets.ClientWebSocket();
// Please do not use in production environment
_ws.Options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

doghappy avatar Jul 21 '20 06:07 doghappy

If you are using .NET Framework, add this line at some point before attempting connection: ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => { return true; };

alexCharters avatar Jun 16 '22 21:06 alexCharters