socket.io-client-csharp icon indicating copy to clipboard operation
socket.io-client-csharp copied to clipboard

Custom ServerCertificateValidationCallback [3.1.1]

Open YetAnotherGeorge opened this issue 1 year ago • 0 comments

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?

YetAnotherGeorge avatar Mar 16 '24 19:03 YetAnotherGeorge