I'm getting the following error message trying to send a push notification to my iPhone:
Apple Notification Failed: ID={12}, Code= {PushSharp.Apple.ApnsConnectionException: SSL Stream Failed to Authenticate as Client---> System.Security.Authentication.AuthenticationException: Could not make a call to SSPI; see the internal exception. ---> System.ComponentModel.Win32Exception: Message received unexpectedly, or its format is incorrect}
I'm using PushSharp library and the following code:
- using PushSharp.Apple;
- using PushSharp.Core;
- using Newtonsoft.Json.Linq;
- string p12fileName = "C:\\webroot\\PKI\\myCertificate.p12";
- string p12password = "myPassword";
- string deviceToken = "myiPhoneToken";
- var appleCert = System.IO.File.ReadAllBytes(p12fileName);
- var config = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, p12password);
- config.ValidateServerCertificate = false;
- var apnsBroker = new ApnsServiceBroker(config);
- apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
- aggregateEx.Handle(ex => {
- // See what kind of exception it was to further diagnose
- if (ex is ApnsNotificationException)
- {
- var notificationException = (ApnsNotificationException)ex;
- // Deal with the failed notification
- var apnsNotification = notificationException.Notification;
- var statusCode = notificationException.ErrorStatusCode;
- Response.Write("Apple Notification Failed: ID={" + apnsNotification.Identifier + "}, Code={" + statusCode + "}");
- }
- else
- {
- // Inner exception might hold more useful information like an ApnsConnectionException
- Response.Write("Notification Failed for some unknown reason : {" + ex.InnerException + "}");
- }
- // Mark it as handled
- return true;
- });
- };
- apnsBroker.OnNotificationSucceeded += (notification) => {
- Response.Write("Apple Notification Sent!");
- };
- apnsBroker.Start();
- apnsBroker.QueueNotification(new ApnsNotification
- {
- DeviceToken = deviceToken,
- Payload = JObject.Parse("{\"aps\":{\"alert\":\"" + "Hi,, This Is a Sample Push Notification For IPhone.." + "\",\"badge\":1,\"sound\":\"default\"}}")
- });
- apnsBroker.Stop();
I created the certificate more than once trying to avoid any error at create certificate moment.
What I'm doing wrong? What is missing in my code?
Can anyone help me?
Kind regards in advance.
ashwinikumar shendePosted Aug 27, 2020, 7:04 AM
Manel PiPosted Oct 4, 2017, 11:56 AM
Mikkel NepperChristensenPosted Oct 4, 2017, 10:38 AM
I suspect it is server configuration issue or something related to the network/firewall.
Any progress for you since you posted this?
------
Update:
We have now found a solution to this problem.
The exact scenario was that APNs push with PushSharp worked from my local machine and from an internal (behind firewall) server running Windows Server 2012R2. But when deploying the exact same code to a staging server also running Windows Server 2012R2 in our DMZ, we got the following error:
PushSharp.Apple.ApnsConnectionException: SSL Stream Failed to Authenticate as Client --->
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. --->
We also tried to migrate to .net framework 4.7 on all servers. No luck. We pulled PushSharp from Git and modified it to use only TLS1.1 and TLS1.2. Still no cigar.
Last year we paid a lot of intention to hardening the webserver hosting our main website - in this case the same server as the one used for staging our APNs provider build with PushSharp. We did that by tweeking the configured cipher suites on the server.
I'm really not into cryptography, but when comparing the cipher suites configured and enabled on the two servers, there turned out to be some slight differences and it appears now, that adjusting the cipher suites to the ones listed below did the trick:
In order to do that, we used IIS Crypto on the server that didn't send notifications. Now it does.
To everyone experiencing similar problems, I really recommend that you try out either IIS Crypto (https://www.nartac.com/Products/IISCrypto) or some other similiar tool to check and adjust the security of your websites to best practice.