通过SSL连接身份验证的安全Websocket C#

时间:2020-09-11 15:13:32

标签: c# websocket ssl-certificate x509certificate2 sslstream

我正在使用X509Certificate2类和sslStream进行安全的WebSocket实现。调用 AuthenticateAsServer 时,它给出错误 。该操作不允许在已通过身份验证的安全上下文中使用, 以及在客户端上,在WebSocket握手期间收到错误 错误:net :: ERR_SSL_PROTOCOL_ERROR 。下面是我的服务器实现代码:

加载证书:
serverCertificate = X509Certificate.CreateFromCertFile("Certificate.cer");

身份验证:此行出现错误
sslStream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls12, false);

如果删除了 AuthenticateAsServer 的上述方法,则在以下行上出现所需的身份验证错误:
await sslStream.ReadAsync(buffer, 0, buffer.Length, cts.Token);

0 个答案:

没有答案