【问题标题】:AuthenticationException: A call to SSPI failed with Secured Web SocketsAuthenticationException:使用安全 Web 套接字调用 SSPI 失败
【发布时间】:2021-09-21 00:04:34
【问题描述】:

我有一个相当复杂的实时 Web 应用程序,它以 C# 服务器作为后端,同时运行 Websocket 服务器。

我目前正在升级它以支持 HTTPS, 已经这样做了(使用 OWIN 自主机,.NET Framework 4.6.1) 我还需要为 Websockets 这样做(用于在服务器更改时更新客户端)

Websocket 服务器是使用奇妙的websocket-sharp 库实现的

我面临的问题是: 无论我做什么,在调用SslStream.AuthenticateAsServer 之后,我似乎总是在我的服务器端遇到这个令人沮丧的异常。 现在,我也尝试使用不同的 Websocket 服务器 (Fleck),但问题仍然存在,所以我很确定它与我的证书有关。 我正在使用自签名证书,并且我尝试以多种方式创建此证书,包括内置 Windows 证书注册、PowerShell 'New-SelfSignedCertificate',无论我使用什么证书,我总是得到这个例外:

 AuthenticationException
 
   HResult=0x80131501
 
   Message=A call to SSPI failed, see inner exception.
 
   Source=System
 
   StackTrace:
 
    at
 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken
 message, AsyncProtocolRequest asyncRequest, Exception exception)
 
    at
 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken
 message, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming,
 Int32 count, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer,
 Int32 count, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32
 readBytes, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
 AsyncProtocolRequest asyncRequest)
 
    at
 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken
 message, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming,
 Int32 count, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer,
 Int32 count, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32
 readBytes, AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
 AsyncProtocolRequest asyncRequest)
 
    at System.Net.Security.SslState.ForceAuthentication(Boolean
 receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
 
    at
 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult
 lazyResult)
 
    at
 System.Net.Security.SslStream.AuthenticateAsServer(X509Certificate
 serverCertificate, Boolean clientCertificateRequired, SslProtocols
 enabledSslProtocols, Boolean checkCertificateRevocation)
 
    at
 WebSocketSharp.Net.WebSockets.TcpListenerWebSocketContext..ctor(TcpClient
 tcpClient, String protocol, Boolean secure, ServerSslConfiguration
 sslConfig, Logger log) in
J:\Common\OpenSource\websocket-sharp\websocket-sharp\Net\WebSockets\TcpListenerWebSocketContext.cs:line
91
 
  
 
Inner Exception 1:
 
Win32Exception: An unknown error occurred while processing the
certificate

P.S 我找到了几个地方告诉将EnabledSslProtocols 设置为SslProtocols.Tls12,我这样做了,但没有用。

【问题讨论】:

    标签: c# websocket certificate owin x509certificate2


    【解决方案1】:

    好的,所以我能够弄清楚。 在此处发布答案,以防其他人遇到此问题。

    我需要将证书中的通用名称设置为某个名称,然后将该名称添加到主机文件并在寻址服务器时使用该名称(在我使用我的计算机名称之前) 所以可以说我用

    创建证书

    CN=网络服务器

    然后在hosts文件中添加

    127.0.0.1 网络服务器

    它成功了。

    我只是不明白为什么证书在服务器中被拒绝,而不是在客户端。

    【讨论】:

      猜你喜欢
      • 2020-07-22
      • 2014-05-31
      • 1970-01-01
      • 2011-04-01
      • 2016-05-28
      • 2011-04-06
      • 2012-10-18
      • 2018-12-02
      • 2023-03-06
      相关资源
      最近更新 更多