【问题标题】:A call to SSPI failed, see inner exception - The Local Security Authority cannot be contacted对 SSPI 的调用失败,请参阅内部异常 - 无法联系本地安全机构
【发布时间】:2016-10-21 21:14:43
【问题描述】:

我有一个 WPF 应用程序,它使用 SSLStream 连接到服务器并发送/接收一些消息。我的代码很大程度上基于这个例子(SslTcpClient):https://msdn.microsoft.com/en-us/library/system.net.security.sslstream(v=vs.110).aspx

这几个月都运行良好。但是,在获得此 Windows 更新后(Windows 10 版本 1511 和 Windows Server 2016 技术预览版 4 的累积更新:2016 年 6 月 14 日 - https://support.microsoft.com/en-us/kb/3163018)。我的应用开始报告此异常:

System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The Local Security Authority cannot be contacted
   --- End of inner exception stack trace ---
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.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at MyAPP.Core.Services.Network.Impl.SslTcpClient.ClientSideHandshake()
at MyAPP.Core.Services.Network.Impl.SslTcpClient.Connect()
at MyAPP.Core.Services.Impl.MessageService.SendMessage(String message)

我能做什么?

【问题讨论】:

  • 在我们的 Windows 10 机器上进行此更新后,我们遇到了同样的问题。我们正在使用 MySQL .NET 连接器通过 SSL 连接到远程 MySQL 数据库。
  • 乔恩,你找到解决办法了吗?我在连接到 MySQL 数据库时遇到了同样的问题。

标签: c# .net networking network-programming sspi


【解决方案1】:

这意味着对方正在使用另一个版本的 TLS,而您使用的是旧版本。
在建立连接之前将安全属性设置为 TLS12。 这是一个广为人知的问题,因为许多提供商开始使用 TLS12(例如 paypal、amazon 等)。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

【讨论】:

  • 在我的情况下,消息是“安全包中没有可用的凭据”,它也有效,救生员!
【解决方案2】:

这是解决方案,在注册表中设置:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman]
"ClientMinKeyBitLength"=dword:00000200

如上所述here

【讨论】:

  • This link 参考了 MS 技术讨论,了解为什么删除了 DH 512 支持。
【解决方案3】:

如果您使用的是 SslStream,那么您需要在 AuthenticateAsClient 调用中显式设置 TLS 版本,例如:

ssl.AuthenticateAsClient(url, null, SslProtocols.Tls12, false);

【讨论】:

  • 我无法让它以任何其他方式工作,所以感谢您的提示。
【解决方案4】:

使用C# 连接到Oracle 数据库时遇到此异常,使用Oracle.ManagedDataAccess.dll

“Oracle.ManagedDataAccess.Client.OracleException (0x80004005): Oracle 无法连接到服务器或无法解析连接字符串 ---> OracleInternal.Network.NetworkException (0x80004005): Oracle : Oracle 无法连接到服务器或无法解析连接字符串---> System.Security.Authentication.AuthenticationException: 对 SSPI 的调用失败,请参阅内部异常。 ---> System.ComponentModel.Win32Exception: 安全包中没有可用的凭据\r\n --- 内部异常堆栈跟踪结束 ---\r\n 在 System.Net.Security.NegoState.StartSendAuthResetSignal(LazyAsyncResult lazyResult, Byte[] message, Exception exception)\r\n在 System.Net.Security.NegoState.StartSendBlob(Byte[] message, LazyAsyncResultlazyResult)\r\n 在............

找了好久,终于找到This Answer有效,添加settings部分,在app.config中设置name="SQLNET.AUTHENTICATION_SERVICES" value=""

<oracle.manageddataaccess.client>
  <version number="*">
    <dataSources>
      <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
    </dataSources>
    <settings>
      <setting name="SQLNET.AUTHENTICATION_SERVICES" value=""/>
    </settings>
  </version>
</oracle.manageddataaccess.client>

在上面答案的参考链接中,你可以再试一步,设置:

SQLNET.AUTHENTICATION_SERVICES= ()

Oracle Client 文件夹中的sqlnet.ora 中也可以使用。

【讨论】:

  • 这和有问题的不是同一个例外,所以你的答案是无关紧要的
【解决方案5】:

尝试将 servicePrincipalName 添加到您的客户端 App.config 文件中

<client>
 <endpoint ............................
  <identity>
  <servicePrincipalName/>
  </identity>
 </endpoint>
</client>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-10
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多