首页 > 解决方案 > 通过 SSL 连接身份验证问题的安全 Websocket C#

问题描述

我正在使用 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);

标签: c#websocketssl-certificatex509certificate2sslstream

解决方案


推荐阅读