sta / sta/websocket-sharp

wss communication problem

Open
#411 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

I have a C# client in Unity with Framework 3.5, and a C# Server with Framework 4.5.2
They suppose to communicate securely through wss.
I created a ssl certificate.

The server security code:

var webSocketServer = new WebSocketServer(5963, true);
webSocketServer.SslConfiguration.ServerCertificate = new X509Certificate2("localhost.pfx", "Test");
webSocketServer.AuthenticationSchemes = AuthenticationSchemes.Digest;
webSocketServer.Realm = "WebSocket Test";
webSocketServer.UserCredentialsFinder = id =>
{
       var name = id.Name;
       return name == "userName"
                       ? new WebSocketSharp.Net.NetworkCredential(name, "User@user", "UserDomain")
                       : null;
};
webSocketServer.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls;
string service = System.Configuration.ConfigurationManager.AppSettings["webSocketService"];

webSocketServer.AddWebSocketService<MyService>(service);
`webSocketServer.Start();`

The client code:

string url = "wss://localhost:5963/MyService";// single ip:4649. security ip: 5963
_webSocket = new WebSocket(url);
 _webSocket.SslConfiguration.ServerCertificateValidationCallback =
(sender, certificate, chain, sslPolicyErrors) =>
{
          if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
          {
                 return true;
          }

         if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
         {
               if (chain != null && chain.ChainStatus != null)
              {
                   foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
                            {
                                if ((certificate.Subject == certificate.Issuer) &&
                                   (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
                                {
                                    // Self-signed certificates with an untrusted root are valid. 
                                    continue;
                                }
                                else
                                {
                                    if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
                                    {
                                        // If there are any other errors in the certificate chain, the certificate is invalid,
                                        // so the method returns false.
                                        return false;
                                    }
                                }
                            }
                        }

                        // When processing reaches this line, the only errors in the certificate chain are 
                        // untrusted root errors for self-signed certificates. These certificates are valid
                        // for default Exchange server installations, so return true.
                        return true;
                    }
                    else
                    {
                        // In all other cases, return false.
                        return false;
                    }
                };
            _webSocket.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls;
            _webSocket.SetCredentials("userName", "User@user", true);
            // ---------------------------------------

            // invoke when the client connect to the server 
            _webSocket.OnOpen += (sender, e) =>
                   log.Info(DateTime.Now + "  start comuunication");

            // invoke when the server send message
            _webSocket.OnMessage += (sender, e) =>
                    HandleMessage(e.Data);

            // invoke when error occurred
            _webSocket.OnError += (sender, e) =>
                log.Info(DateTime.Now + " get error: " + e.Exception.Data + " " + e);

            // invoke when the client unconnected to the server
            _webSocket.OnClose += (sender, e) =>
                    log.Info(DateTime.Now + " closed " + e.Reason + " " + e);

            // connect to the server
            _webSocket.Connect();

Yet, when I try to make them communicate the following error occurs:

Fatal|QueueUserWorkItemCallback.WaitCallback_Context|System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm
--- End of inner exception stack trace ---

Can anyone help me figure out what is the source of the problem.
Thanks in advance.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the server's WebSocketServer SslConfiguration and the client's WebSocket.Connect call, then inspect the full inner SSPI exception and compare the TLS settings used by both C# Framework versions. Done means identifying the incompatible algorithm or configuration and confirming that the Unity client and server establish the intended wss connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.