How to set up a certificate to make a connection to Javascript Websockets

Asked

Viewed 270 times

1

How to configure a certificate to make a connection with Javascript Websockets, using c’s Superwebsocket server#?

I need to create a websocket connection on an https page, the only way is using "wss", which has SSL protrocole, 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"
            };
  • 2

    Which lib is used? This https://github.com/kerryjiang/SuperWebSocket?

  • Exactly this.

  • There is the indication that the project was completed, joining the SuperSocket. There is the possibility to use this other project?

  • Superwebsocket is being merged into Supersocket as an Additional module Supersocket.WebSocket. You can use Supersocket.Websocket in the same way with Superwebsocket but with a Different namespace. https://github.com/kerryjiang/SuperWebSocket

  • @tvdias use Supersocket in my project? yes, I will implement.

1 answer

2


The original example (below) uses the latest version of SuperSocket, beta version 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 the SuperWebSocket), follows how it 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.