使用mono和ubuntu连接到gateway.sandbox.push.apple.com时出错

时间:2014-05-27 10:52:00

标签: c# ios ssl mono push-notification

我尝试连接到apns并获得异常:从服务器收到的证书无效。我发现一个可能的解决方案是禁用验证,但它没有工作:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, ssl) => true;

其他解决方案是将单据存储空白的证书添加到单声道,默认为空 但是也不起作用:

certmgr -ssl https://gateway.sandbox.push.apple.com 

以下是连接的代码:

 //load certificate
        var clientCertificate = new X509Certificate2 ("cert.pem", "xxx");
        var clientCertificate2 = new X509Certificate2 ("entrust_ca.pem");
        var certificatesCollection = new X509Certificate2Collection();
        certificatesCollection.Add (clientCertificate);
        certificatesCollection.Add (clientCertificate2);
        ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, ssl) => true;

        var client = new TcpClient(hostname, port);
        var sslStream = new SslStream (client.GetStream (), false);

        try
        {
            sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Default, false); //crash here
        }
        catch (Exception ex)
        {
            Console.WriteLine (ex);
            //client.Close();
            //return;
        }

请提出任何想法

0 个答案:

没有答案