sta / sta/websocket-sharp

On the server side, the ClientCertificateValidationCallback arguments certificate and chain return null values.

Open
#759 0 comments 0 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

We are using websocket-sharp version 1.0.2.59611. We're attempting to archive mutual authentication between the client and server using self-signed certificates. When we add callbacks for certificate validation on the client and server, we obtain the correct values for the certificate and chain arguments at ServerCertificateValidationCallback, but we get NULL for the certificate and chain in ClientCertificateValidationCallback. Is there anything missing here? How can we get the client certificate in ClientCertificateValidationCallback?

We have the below code at client ->

            string certFile = txtBoxCertFile.Text.Trim();
            string password = txtBoxCertFilePassword.Text.Trim();
            string server = txtBoxServer.Text.Trim();
            string port = txtBoxPort.Text.Trim();
            string connection = "wss://" + server + ":" + port;

            WebSocket myWss = new WebSocket(connection); 
            myWss.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls13 | SslProtocols.Tls12;

            if (!String.IsNullOrEmpty(certFile))
            {
                    X509Certificate2 certificate = new X509Certificate2(certFile, password);
                    X509CertificateCollection certs = new X509CertificateCollection();
                    certs.Add(certificate);
                    myWss.SslConfiguration.ClientCertificates = certs;
             }

             myWss.SslConfiguration.ServerCertificateValidationCallback =
                  (Server, certificate, chain, sslPolicyErrors) =>
                  {
                      // Do something to validate the server certificate.
                      return true; // If the server certificate is valid.
                  };

We have the below code at server ->

                            string file = wssConfiguration["file"];
                            string password = wssConfiguration["password"];
                            X509Certificate2 certificate = new X509Certificate2(file, password);;
                            WebSocketServer wss = new WebSocketServer(wssPort, true);
                            wss.SslConfiguration.ServerCertificate = certificate;

                            wss.SslConfiguration.ClientCertificateValidationCallback =
                                  (sender, ClientCertificate, chain, sslPolicyErrors) => {
                                      // Do something to validate the server certificate.
                                    return true; // If the server certificate is valid.
                                  };

In policy errors we are getting the error as RemoteCertificateNotAvailable even though we have supplied the certificate to SslConfiguration.ClientCertificates at client.
While debugging we are getting the null values for certificate, chain can be seen below:

image

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 with the WebSocket client and server SslConfiguration setup shown in the issue, especially ClientCertificates and ClientCertificateValidationCallback. Reproduce mutual TLS with the supplied self-signed certificates and verify why the callback receives RemoteCertificateNotAvailable; done means the server callback receives the client certificate and chain or the missing configuration is clearly documented.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.