【发布时间】:2021-05-19 01:11:15
【问题描述】:
我正在尝试创建一个 Windows 服务,该服务打开一个安全的 Web 套接字并侦听某个端口 (wss://localhost:1234) 上的连接。示例代码包括引用供服务器使用的证书:
var serverCertificate = new X509Certificate2(certificatePath, "mypassword");
这很好用。
当客户端尝试连接时会出现问题:
using (SslStream n = new SslStream(client.TcpClientInstance.GetStream()))
{
n.AuthenticateAsServer(serverCertificate, clientCertificateRequired: false, enabledSslProtocols: System.Security.Authentication.SslProtocols.Tls12, checkCertificateRevocation: false);
此行错误并出现通用“对 SSPI 的调用失败,请参阅内部异常”、“InnerException = {“处理证书时发生未知错误”}”:
这发生在受信任的根证书颁发机构中注册的自签名证书。
有趣的是,如果我使用由 Visual Studio 生成的通用 localhost 证书,它就可以工作。
欢迎任何想法。
TIA
【问题讨论】:
标签: ssl websocket x509certificate