doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
715 stars 124 forks source link

Custom ServerCertificateValidationCallback [3.1.1] #360

Closed YetAnotherGeorge closed 3 months ago

YetAnotherGeorge commented 4 months ago

Right now our team is using self-signed certificates for testing and socket io for communication. To use custom certificate validation the solution I've found is:

var socket = new SocketIOClient.SocketIO("https://localhost:8443") {
   HttpClient = new DefaultHttpClient2()
};
socket.ClientWebSocketProvider = () => new DefaultClientWebSocket2();
await socket.ConnectAsync();
// ...

Where DefaultHttpClient2 and ClientWebSocket2 are the exact same classes as their definition on github with the following changes:

public DefaultClientWebSocket2() {
   _ws = new ClientWebSocket();
   _ws.Options.RemoteCertificateValidationCallback = CUSTOM_PREDICATE;
}

public DefaultHttpClient2() {
   _handler = new HttpClientHandler();
   _handler.ServerCertificateCustomValidationCallback = CUSTOM_PREDICATE;
   _httpClient = new HttpClient(_handler);
}

This works for version 3.1.1, is there a better way to provide a predicate that will reach both the http client and the web socket client?

doghappy commented 3 months ago

The feature has been done on master, it will be releasing on next version. thanks for the issue.