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:
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 ->
We have the below code at server ->
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: