【问题标题】:PushSharp APNS production: The credentials supplied to the package were not recognized (development works fine though)PushSharp APNS 生产:无法识别提供给软件包的凭据(尽管开发工作正常)
【发布时间】:2014-06-13 06:55:12
【问题描述】:

我的应用程序刚刚准备好在 App Store 上销售,但我的生产设备(已从 App Store 安装应用程序的设备)都没有收到推送通知。当我尝试向生产设备发送推送通知时,出现此错误:

"The credentials supplied to the package were not recognized" 
(System.ComponentModel.Win32Exception)

这个异常在内部被抛出并陷入无限循环:

ApplePushChannel.cs文件的第539行抛出:

    try
{
    stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, 
        System.Security.Authentication.SslProtocols.Ssl3, false);
    //stream.AuthenticateAsClient(this.appleSettings.Host);
}
catch (System.Security.Authentication.AuthenticationException ex)
{
    throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex);
}

这是应用程序在 Visual Studio 输出中的输出:

...
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
...(it keeps getting thrown until I stop it manually)

以下是我尝试过的事情:

  • 仔细检查我尝试使用的设备 ID 是否已使用生产设备令牌注册。
  • 撤销并重新生成 APNS 生产证书,使用私钥将其导出到新的.p12 文件,并使用新证书再次尝试。 (我在开发推送通知方面遇到了同样的问题,这解决了我的问题)
  • 将 SSL 协议从 Ssl3 更改为 Tls。 (前几天协议版本有问题,暂时解决了一个问题。应该不需要这个,但我得到的错误与我之前得到的错误相同)
  • 检查我实际上是在尝试使用生产证书而不是开发服务器/证书连接到生产服务器。
  • 检查我是否可以直接访问 APNS 服务器(我的 ASP.NET 应用程序位于我的 Mac 上的 Parallels VM Windows 8.1 中,这是我的 Mac 的输出,只是为了避免混淆:

(终端输出) 编辑:我在 ping 沙箱服务器,我已经 ping 生产服务器,我验证我也可以连接到它,所以这不是问题。

can$ sudo nmap -p 2195 gateway.sandbox.push.apple.com
Starting Nmap 6.40-2 ( http://nmap.org ) at 2014-04-28 00:06 EEST
Nmap scan report for gateway.sandbox.push.apple.com (17.149.34.189)
Host is up (0.49s latency).
Other addresses for gateway.sandbox.push.apple.com (not scanned): 17.149.34.187 17.149.34.188
PORT     STATE SERVICE
2195/tcp open  unknown

为什么 PushSharp 不与 APNS 服务器协商?

【问题讨论】:

    标签: ssl apple-push-notifications production-environment pushsharp


    【解决方案1】:

    我发现了问题所在。我再次撤销并重新生成了证书,这次我只导出了私钥(没有证书)。在钥匙串访问中,我导出为.p12 并使用了新文件,它工作正常。出于某种原因,当文件中同时存在证书和私钥时,PushSharp 不能很好地与 .p12 配合使用。

    【讨论】:

    • 谢谢,我刚刚重新办了证书,它成功了!尽管我不认为 PushSharp 有问题,但我认为在制作这些证书的非常复杂的过程中出现了一些问题。所以重新开始似乎可以纠正这一点。
    • @rich97 在这个过程中肯定有问题,无论是在 Apple 还是在 PushSharp 方面。
    • 好吧,我只是想我应该分享我的经验。有一天可能会帮助某人。
    • 这个。这。这。所有文档都告诉您导出这两个项目,然后它就失败了。在这上面浪费了好几个小时。谢谢@CanPoyrazoğlu。
    • 由于某种原因,在 mac 中从 php 导出这两项工作,但在 c# 服务器中失败。仅使用私钥即可使其工作。
    【解决方案2】:

    当使用 Windows 证书存储时(恕我直言,这是在生产服务器上管理证书的最简单方法),请务必在私钥上设置正确的权限。

    【讨论】:

    • 我在生产环境中收到了这个错误(在开发中它工作)。重新创建证书不起作用。这里给出的答案确实如此。
    【解决方案3】:

    我收到了同样的异常,在我的情况下,我必须为我的 IOS 推送服务证书添加权限。

    在mmc中右键证书->所有任务->管理私钥... 我添加了 NETWORK SERVICE,因为我的网络应用程序的 iis 应用程序池使用了该帐户。

    查看详情:http://blog.falafel.com/apple-push-notifications-certificates-and-iis/

    【讨论】:

      【解决方案4】:

      “无法识别提供给包的凭据”异常通常表示运行代码的用户没有足够的权限。

      如果您从 Azure Web 应用程序或 Web 作业发送推送通知,请不要从文件或 base64 编码字符串加载 APNS 证书。转至 Azure 门户并将证书添加到网站。注意指纹。

      接下来添加 WEBSITE_LOAD_CERTIFICATES 设置并将其设置为 *(星号)。

      现在可以从 C# 代码中使用 APNS 证书:

      string thumbprint = "YOUR THUMBPRINT";
      var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
      store.Open(OpenFlags.ReadOnly);
      var certificate = store.Certificates.Find(
          X509FindType.FindByThumbprint, thumbprint, validOnly: false)
          .Cast<X509Certificate2>().SingleOrDefault();
      var apnsConfig = new ApnsConfiguration(
          ApnsConfiguration.ApnsServerEnvironment.Production, certificate);
      

      参考文献

      【讨论】:

      • 这个答案帮助了我,但做了一些改变。现在使用新的 Azure 门户,您可以在应用服务/SSL 设置/私有证书 (.pfx)/上传证书中添加证书。 有趣的是,您不需要更改 OP 使用的代码 (stream.AuthenticateAsClient),因此您无需在此答案中使用缩略图或代码。旧代码将在证书上传后立即开始工作,当然还有 WEBSITE_LOAD_CERTIFICATES。可悲的是,您需要付费计划(至少是基本计划)才能上传任何证书。
      【解决方案5】:

      没有一个答案对我有用。最后,我最终将证书和私钥导入 Windows 证书存储区,然后导出为 .pfx

      【讨论】:

        【解决方案6】:

        我一次又一次地测试它。

        p12 文件转换为pem 格式,它将适用于IIS 受限用户,并且可能适用于Azure....

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-09
          • 1970-01-01
          • 2013-05-02
          • 1970-01-01
          • 2021-05-31
          • 1970-01-01
          • 1970-01-01
          • 2014-07-27
          相关资源
          最近更新 更多