gpt4 book ai didi

c# - 在 Ubuntu 上使用 Mono 连接到 APNS 服务

转载 作者:行者123 更新时间:2023-12-04 18:53:38 26 4
gpt4 key购买 nike

我正在尝试建立与 Apple 的 APNS 服务的连接。我在 Ubuntu 上运行 Mono。用于建立连接的代码可以在 Windows 环境中正常工作。该代码是 NT 服务(系统进程)的一部分,而不是网站或服务。

以下是一些关于环境的信息:
Ubuntu 12.10。
单声道 3.0.5。
使用 Mono 的 Certmgr:

  • 我在 Mono 机器证书存储 (MY) 中安装了 APNS 证书。
  • 我在 Mono 机器证书存储( key 对)中安装了 APNS 证书私钥。
  • 我在 Mono 机器证书存储区 (TRUST) 中安装了 Entrust.net 证书颁发机构 (2048) 根证书。
  • 我在 Mono 机器证书存储 (CA) 中安装了 Entrust 证书颁发机构 - 1LC 中间证书。

  • Telnet 能够到达 gateway.push.apple.com:2195。
    我正在调试 MonoDevelop 中的代码。
    MonoDevelop 以 Root (gksudo) 身份运行。

    这是我收到的错误:
    System.IO.IOException: The authentication or decryption has failed. --->
    Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
    at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
    --- End of inner exception stack trace ---
    at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 }

    这是我用来建立连接的代码:
    m_client = new TcpClient("gateway.push.apple.com", 2195);
    m_ssl = new SslStream(m_client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
    m_ssl.AuthenticateAsClient("gateway.push.apple.com", m_certColl, System.Security.Authentication.SslProtocols.Tls, false);

    来自调试器的更多信息:

    m_certColl contains 1 Certificate, the APNS Certificate, as it should. I confirmed in the debugger that the public key and private key are both being populated. The RemoteCertificateValidationCallback returns NO SslPolicyErrors. I can confirm that the chain includes 3 certificates. 1 containing Apple's public key for gateway.push.apple.com, 1 containing Entrust's Intermediate Certificate, and 1 containing Entrust's Root Certificate.



    我已经两次和三次检查了所有内容,但我只是不知道从这里去哪里。任何帮助将不胜感激!

    最佳答案

    想通了。事实证明,当涉及到 AuthenticateAsClient 时,Windows 和 Mono(至少在 Linux 上)的行为不同。根据您的证书链,Windows 将对身份验证时使用的证书做出“最佳猜测”(因为 APNS 证书是链中唯一的证书,所以很容易猜测)

    Mono 根本不会“猜测”。您必须使用 LocalCertificateSelectionCallback 指定证书。你不能像我一样让它“空”

    关于c# - 在 Ubuntu 上使用 Mono 连接到 APNS 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13882185/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com