How to configure a certificate to make a connection to JavaScript WebSockets

How to configure a certificate to make a connection to JavaScript WebSockets, using C # SuperWebSocket as a server?

I need to create a websocket connection on an https page, the only way is using "wss", which has the SSL protrocolo, but I do not know how to properly use this type of connection.

        public static void startServer()
        {

            ServerConfig config = new ServerConfig()
            {
                Name = "SuperWebSocket",
                Ip = "Any",
                Port = 8088,
                Mode = SocketMode.Tcp,
                Security = "tls"
            };

            CertificateConfig certificate = new CertificateConfig()
            {
                FilePath = @"C:/meucaminho",
                Password = "123"
            };
Author: Null, 2020-01-20

1 answers

The original example (below) uses the latest version of SuperSocket, still in beta and only for .NET core (as indicated in the repository readme). However, the project documentation contains instructions on how to do the same in version 1.6: http://docs.supersocket.net/v1-6/en-US/Enable-TLS-SSL-trasnferring-layer-encryption-in-SuperSocket


(ORIGINAL)

As an example in the project SuperSocket (substitute for SuperWebSocket), it follows how you can be done, using the version for .NET core (master branch).

var host = WebSocketHostBuilder.Create()
    .ConfigureWebSocketMessageHandler(async (session, message) =>
    {
        // echo message back to the client
        await session.SendAsync(message.Message);
    })
    .ConfigureLogging((hostCtx, loggingBuilder) =>
    {
        // register your logging library here
        loggingBuilder.AddConsole();
    }).Build();

await host.RunAsync();

For the above code to work the following configuration file is required appsettings.json

{
    "serverOptions": {
        "name": "TestWebSocketServer",
        "listeners": [
            {
                "ip": "Any",
                "port": 4040
            },
            {
                "ip": "Any",
                "port": 4041,
                "security": "Tls12",
                "certificateOptions" : {
                    "filePath": "certificado.pfx",
                    "password": "SENHA DO CERtIFICADO"
                }
            }
        ]
    }
}

Example available in https://raw.githubusercontent.com/kerryjiang/SuperSocket/master/samples/WebSocketServer/Program.cs

 2
Author: tvdias, 2020-01-23 14:53:54