APN失败,"身份验证失败,因为远程方已关闭传输流"

shw*_*ngh 6 .net openssl sslstream x509certificate apple-push-notifications

我试图SslStream.AuthenticateAsClient通过传递服务器IP,从C#发送APN使用方法,SslProtocols.TlsX509Certificate2Collection.但我收到一条错误消息:

Authentication failed because remote party has closed the transport stream
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这里讨论的每个解决方案,但没有任 请帮助下面的代码

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;
Run Code Online (Sandbox Code Playgroud)

小智 1

禁用 SSL3 后我遇到了同样的情况。生成新证书后,它就开始工作了。