对 SSPI 的调用失败 - 收到的消息是意外的或格式错误

A call to SSPI Failed - The message received was unexpected or badly formatted

我们使用的是稍微修改过的 PushSharp v2.2.1.0 版本,该版本最近在我们的最新版本中停止工作。由于重写的时间限制,我们无法将其更新到 4.x 或 3.x 版本。在对代码的大多数方面进行了几天的修改之后,我不确定还有什么可能导致该问题。

每当我们尝试处理数据时,我们都会收到以下错误(到目前为止,它似乎只发生在 Apple 方面):

A call to SSPI failed, see inner exception.
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
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.StartReceiveBlob(Byte[] buffer, 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.StartReceiveBlob(Byte[] buffer, 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.StartReceiveBlob(Byte[] buffer, 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.StartReceiveBlob(Byte[] buffer, 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.StartReceiveBlob(Byte[] buffer, 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 PushSharp.Apple.FeedbackService.Run(ApplePushChannelSettings settings, CancellationToken cancelToken)
at PushSharp.Apple.ApplePushService.<>c__DisplayClass4.<.ctor>b__1(Object state) 

Inner Exception: System.ComponentModel.Win32Exception (0x80004005)
The message received was unexpected or badly formatted

我们已经有了 here 提到的修复。由于没有发布大量代码,我不确定哪些信息有助于调试。我们在检索和加载证书时没有收到任何问题或错误(日志记录表明它已正确加载且版本正确)。我们最近确实对该证书进行了更新,因为旧证书已过期,但新证书正在正确加载。

我们的基础设施没有任何变化,这意味着入站数据发生变化。对安全帐户信息进行了一些屏蔽更改,但删除这些更改并没有解决问题,而且它应该只在日志记录期间发生。我错过了什么?

因为我找到了几个接近这个问题但没有完全解决它的答案(并且因为 PushSharp 的 Git 页面表明他们对 2.x 的问题不感兴趣)我'我会提出我的具体答案,希望它能帮助某人:

我的问题与新证书有关。虽然我们确实安装了新证书,但我们没有添加保存证书私钥的 p12 文件,因此无法正确加密消息。

将 p12 文件安装到服务器解决了该问题。

总而言之,对于一个被忽略的问题,这是一个相当明显的解决方案。