0

I am working on a secure WebSocket implementation using the X509Certificate2 class and sslStream. While AuthenticateAsServer is called it gives the error of This operation is not allowed on a security context that has already been authenticated and on the client, I am getting error Error during WebSocket handshake: net:: ERR_SSL_PROTOCOL_ERROR. Below is my code for server implementation:

Loading Certificate:
serverCertificate = X509Certificate.CreateFromCertFile("Certificate.cer");

Authentication: getting error on this line
sslStream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls12, false);

If the above method of AuthenticateAsServer is removed then got error of authentication required on the following line:
await sslStream.ReadAsync(buffer, 0, buffer.Length, cts.Token);

Hassan
  • 1
  • 1
  • Most likely and judging by your file extension, you do not have the private keys in your certificate. You need the private keys to authenticate either side of the TLS connection. – zaitsman Oct 13 '20 at 23:06
  • I've changed it using pfx certificate file also and providing password with it but got the same error – Hassan Oct 20 '20 at 08:56

0 Answers0