Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone certificate error in apns sharp A call to SSPI failed

i have a data service hosted in azure from which i am sending notification to iphone but while establishing connection with apns i am getting following error "A call to SSPI failed. The message received was unexpected or badly formatted." i also refered following links for the same error but still getting the error

apple push notification with APNS sharp and C# iPhone push server?

        try
        {
            using (TcpClient client = new TcpClient())
            {

                try
                {
                    client.Connect("gateway.sandbox.push.apple.com", 2195);
                    Logging("TSSLProDi :Connected to Apple");
                }
                catch (Exception ex)
                {
                    Logging("TSSLProDi :" + ex.Message + "-IE-" + ex.InnerException);

                }
                using (NetworkStream networkStream = client.GetStream())
                {
                    Logging("TSSLProDi :Client connected.");

                    X509Certificate clientCertificate = new X509Certificate(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"startup\certname.pfx"), "mycertpassword");
                    X509CertificateCollection clientCertificateCollection = new X509CertificateCollection(new X509Certificate[1] { clientCertificate });

                    // Create an SSL stream that will close the client's stream.
                    SslStream sslStream = new SslStream(
                        client.GetStream(),
                        false,
                        new RemoteCertificateValidationCallback(validateServerCertificate),
                        null
                        );

                    try
                    {
                        sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, System.Security.Authentication.SslProtocols.Default, false);
                        Logging("TSSLProDi :slStreamAuthenticated");
                    }
                    catch (AuthenticationException ex)
                    {
                        Logging("TSSLProDi :" + "Exception: " + ex.Message.ToString());
                        if (ex.InnerException != null)
                        {
                            Logging("Inner exception: " + ex.InnerException.Message.ToString());
                        }
                        Logging("TSSLProDi :" + "Authentication failed - closing the connection.");
                        client.Close();
                        return;
                    }
                }

            }
        }
        catch (Exception ex)
        {

            Logging("TSSLProCert :" + ex.Message + "-IE-" + ex.InnerException);
        }

i have installed the needed certificates on VM also. one warning i am getting on iphone developer_identity certificate which i got from apple is that "Windows does not have enough information to verify this certificate" is there is some thing wrong with my iphone certificate. please help me i am stuck

like image 961
Rahul Parate Avatar asked Jul 15 '11 13:07

Rahul Parate


People also ask

What is APNS certificate in iOS?

APNs, or Apple Push Notification Service, is a an operating system notification service that delivers notifications to iOS devices. In order to securely send notifications through APNs, you'll need an Apple Push Certificate among other requirements.

What is an APNS error?

It usually means that your JSS can't communicate properly with Apple's "feedback" APNS server, which is "feedback.push.apple.com" on port 2196. The JSS sends push notifications via port 2195, and Apple reports their success (or failure) back to the JSS via port 2196.

Is APNS certificate free?

APNS is a free service. However, you need to maintain a server to send Push Messages.

What is development APNS certificate?

Apple Push Notification Service (commonly referred to as Apple Notification Service or APNS) is a platform service created by Apple Inc. that enables third party application developers to send push notifications to iOS users. You must have Paid Apple Developer account to create certificates.


1 Answers

got the solution i have just changed X509Certificate to X509Certificate2 and X509CertificateCollection to X509Certificate2Collection

like image 106
Rahul Parate Avatar answered Sep 24 '22 07:09

Rahul Parate