【发布时间】:2019-06-27 00:33:55
【问题描述】:
我有一个自签名证书,我想在我的 websockets 服务器上使用它来处理来自 wss://localhost:443 的请求。我从任何网络浏览器连接到服务器。
但是,我似乎无法正确进行身份验证。每次我尝试通过 Advanced Rest Client (ARC) 软件连接到 WebSockets 服务器时,我都会输入 wss://localhost:443 或 wss://127.0.0.1:443、
我遇到了异常
“System.Security.Authentication.AuthenticationException:对 SSPI 的调用失败,请参阅内部异常。---> System.ComponentModel.Win32Exception:处理证书时发生未知错误”。
我使用 openssl for windows 创建了证书,并创建了一个非常简单的证书。我仍然无法获得正确的身份验证。有什么帮助吗?
这是我尝试使用 C# 代码的方法
var serverCertificate = new X509Certificate2("E:\\TestsFolder\\test-cert.pfx", "12345");
var certificates = new X509CertificateCollection { serverCertificate };
Stream stream = tcpClient.GetStream();
SslStream sslStream = new SslStream(stream, false,
(o, x509Certificate, chain, errors) => true,
(o, s, collection, x509Certificate, issuers) => certificates[0]);
await sslStream.AuthenticateAsServerAsync(serverCertificate, false, SslProtocols.Tls12, false);
WebSocketHttpContext context = await _webSocketServerFactory.ReadHttpHeaderFromStreamAsync(sslStream, source.Token);
我到底会错过什么?
这是我的控制台的截图,但有例外
【问题讨论】:
-
您是否从 ARC 收到任何错误?您是否将证书添加到受信任列表中?
-
好吧,重新启动计算机后,我尝试使用 ARC 并且我得到了很好的身份验证。但是当我从 websocket.org/echo.html 运行它并浏览 wss://localhost:443 时,我得到 A call to SSPI failed, see inner exception
-
ARC 和您用于访问 websocket.org 的浏览器是否使用相同的受信任证书根列表?
-
他们肯定使用相同的证书。 websockets 服务器作为控制台应用程序运行。浏览器和 ARC 都使用上述相同的地址访问它
-
当然他们使用的是同一个证书。问题是他们是否都信任该证书。 Chrome 使用 Windows 受信任的根 CA 列表,Firefox 有不同的列表,等等。如果 ARC 是桌面应用程序,它很可能使用 Windows 列表。要做的一件事是在 Chrome 中打开 websocket.org 页面,打开开发人员工具,然后在尝试连接到端点时查看“网络”选项卡中报告的内容。
标签: c# .net websocket ssl-certificate