Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APN fails with "Authentication failed because the remote party has closed the transport stream"

I am trying to send APN from C# using SslStream.AuthenticateAsClient method by passing server IP, SslProtocols.Tls and X509Certificate2Collection. But I am getting an error message:

Authentication failed because remote party has closed the transport stream

I have tried every solution discussed here but nothing works. Please help below is the code

X509Certificate2Collection certs = new X509Certificate2Collection();

X509Certificate2 xcert = new X509Certificate2();
xcert.Import(@"D:\certify.p12", "password", X509KeyStorageFlags.UserKeySet);


certs.Add(xcert);

// Apple development server address
string apsHost;

if (xcert.ToString().Contains(ProductionKeyFriendName))
  apsHost = "gateway.push.apple.com";
else
  apsHost = "gateway.sandbox.push.apple.com"; 

// Create a TCP socket connection to the Apple server on port 2195

TcpClient tcpClient = new TcpClient();
tcpClient.Connect(apsHost, 2195);

// Create a new SSL stream over the connection
sslStream = new SslStream(tcpClient.GetStream());

// Authenticate using the Apple cert

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
sslStream.AuthenticateAsClient(apsHost, certs, System.Security.Authentication.SslProtocols.Tls, false);

return true;
like image 276
shweta singh Avatar asked Jul 10 '15 07:07

shweta singh


1 Answers

I faced the same situation after disabling SSL3. After generating new certificate it got worked.

like image 138
user2505533 Avatar answered Nov 09 '22 08:11

user2505533