Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SuryawanshiAmol opened this issue Oct 25, 2024 · 0 comments

Comments

@SuryawanshiAmol
Copy link

SuryawanshiAmol commented Oct 25, 2024

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

@SuryawanshiAmol SuryawanshiAmol changed the title On the server side, in ClientCertificateValidationCallback parameters certificate and chain are receiving null. On the server side, the ClientCertificateValidationCallback arguments certificate and chain return null values. Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant