Secure (TLS/SSL) SuperWebSocket Async

Nov 9, 2012 at 8:35 AM

Hi Kerry,

Have you got support for async secure websocket? I have tried to set it up using your test certificate in async mode, however, the server does not seems to receive any event (NewSession, NewMessage, etc).

Do you mind guiding me through it?

Thanks

Coordinator
Nov 9, 2012 at 11:36 AM

Did you import the certificate into your trust store? Double click it and then enter the password "supersocket".

Nov 9, 2012 at 11:35 PM

Yes I did.

1. Install pfx file into certificate store
2. Start the socket server with async and tls security and certificate

Socket seems to be started and listening the port I set (port 3501) and test client (using your WebSocketNET) seems to be connecting, but not receiving any reply. Tried to send data, the server is receiving any (I tried to debug your SocketBase too and AcceptNewClient is not firing the event).

Also, my client is actually running on the same machine, if that matters.

Do we need to run anything on the client, i.e. the certificate since it is self-signed?

Coordinator
Nov 10, 2012 at 2:29 AM
Did you check the error log?

Sent from my Windows Phone

From: technogear
Sent: 11/10/2012 7:36 AM
To: kerry-jiang@hotmail.com
Subject: Re: Secure (TLS/SSL) SuperWebSocket Async [SuperSocket:402518]

From: technogear

Yes I did.

1. Install pfx file into certificate store
2. Start the socket server with async and tls security and certificate

Socket seems to be started and listening the port I set (port 3501) and test client (using your WebSocketNET) seems to be connecting, but not receiving any reply. Tried to send data, the server is receiving any (I tried to debug your SocketBase too and AcceptNewClient is not firing the event).

Also, my client is actually running on the same machine, if that matters.

Do we need to run anything on the client, i.e. the certificate since it is self-signed?

Nov 12, 2012 at 2:01 AM

Nothing on the logs. I get a client disconnect (timeout reason) after connecting. Debugging your code - it seems that EndStream is never fired.

On the server:

            m_SocketServer = new WebSocketServer();

            string rootFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string certificatePassword = "supersocket";
            string certificatePath = rootFolder + @"\certificate.pfx";

            if (!m_SocketServer.Setup(new RootConfig(), new ServerConfig
            {
                Port = 5000,
                Ip = "Any",
                Mode = SocketMode.Async,
                Name = "SecureMarketDataWebSocket",
                Security = "tls",
                Certificate = new SuperSocket.SocketBase.Config.CertificateConfig
                {
                    FilePath = certificatePath,
                    Password = certificatePassword,
                    IsEnabled = true
                },
                LogCommand = true
            }, SocketServerFactory.Instance))
                return;

            m_SocketServer.NewMessageReceived += new SessionEventHandler(m_SocketServer_NewMessageReceived);
            m_SocketServer.NewSessionConnected += new SessionEventHandler(m_SocketServer_NewSessionConnected);
            m_SocketServer.SessionClosed += new SessionEventHandler(m_SocketServer_SessionClosed);
            // stop the socket server, if starts unsuccesful
            if (!m_SocketServer.Start())
            {
                m_SocketServer.Stop();
                m_SocketServer = null;

                Update(listBox1, "Service failed to start");
            }
            else
            {
                Update(listBox1, "Service started");
            }

On the client:

        private WebSocket client = null;

        private void button1_Click(object sender, EventArgs e)
        {
            if (client != null)
                return;

            client = new WebSocket("wss://localhost:5000/websocket", "basic", WebSocketVersion.None);
            client.Open();
            client.MessageReceived += new EventHandler<MessageReceivedEventArgs>(client_MessageReceived);
            client.DataReceived += new EventHandler<DataReceivedEventArgs>(client_DataReceived);
            client.Opened += new EventHandler(client_Opened);
            client.Closed += new EventHandler(client_Closed);
        }

Nov 12, 2012 at 2:53 AM

Hi Kerry,

I subscribe to error event on WebSocketClient and it returns:

System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
   at SuperSocket.ClientEngine.SslStreamTcpSession.OnAuthenticated(IAsyncResult result) in C:\Sc\Source\Third Party\SuperSocket.ClientEngine\Core\SslStreamTcpSession.cs:line 61

I'm using your localhost.pfx certificate. Have you got any success in doing it in your development machine using self-signed certififcate?

Coordinator
Nov 12, 2012 at 6:02 AM
WHat’s your URI you connect the server?
The certificate’s CN should be same as the host of the URI.
From: [email removed]
Sent: Monday, November 12, 2012 10:53 AM
To: [email removed]
Subject: Re: Secure (TLS/SSL) SuperWebSocket Async [SuperSocket:402518]

From: technogear

Hi Kerry,

I subscribe to error event on WebSocketClient and it returns:

System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at SuperSocket.ClientEngine.SslStreamTcpSession.OnAuthenticated(IAsyncResult result) in C:\Sc\Source\Third Party\SuperSocket.ClientEngine\Core\SslStreamTcpSession.cs:line 61

I'm using your localhost.pfx certificate. Have you got any success in doing it in your development machine using self-signed certififcate?