We are trying to connect to APNS via .NET project (Framework 4.0).
We know JWT mechanism wont work due to HTTP/2 requirement.
We are trying to achieve this via TLS certificated based authentication, as below:
No erros/exception. Code works but no notification received on iPhone.
int port = 443;;
var payload = JsonHelper.Serialize (notification);
String certificatePath = "apns.pem"; //Not working for .p12/pfx
X509Certificate2 clientCertificate = new X509Certificate2 (System.IO.File.ReadAllBytes (certificatePath), "password");
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection (clientCertificate);
TcpClient client = new TcpClient ("Production", port);
SslStream sslStream = new SslStream (client.GetStream (), false, new RemoteCertificateValidationCallback (ValidateServerCertificate), null);
try {
sslStream.AuthenticateAsClient ("api.push.apple.com", certificatesCollection, (SslProtocols)3072, false);
MemoryStream memoryStream = new MemoryStream ();
BinaryWriter writer = new BinaryWriter (memoryStream);
writer.Write ((byte)0);
writer.Write ((byte)0);
writer.Write ((byte)32);
writer.Write (HexStringToByteArray (deviceToken.ToUpper ()));
writer.Write ((byte)0);
writer.Write ((byte)payload.Length);
byte [] b1 = System.Text.Encoding.UTF8.GetBytes (payload);
writer.Write (b1);
writer.Flush ();
byte [] array = memoryStream.ToArray ();
sslStream.Write (array);
sslStream.Flush ();
client.Close ();