6

我试图通过传递服务器IP,SslProtocols.TlsX509Certificate2Collection使用SslStream.AuthenticateAsClient方法从C#发送APN。但我收到错误消息:APN由于“验证失败,因为远程方已关闭传输流”

Authentication failed because remote party has closed the transport stream 

我试图在这里讨论,但没有工作的每一个解决方案。请在下面帮忙是

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; 
+0

Apple是否颁发了客户端证书? – jww

+1

你有这个工作吗?我试图在这里做完全相同的事情,具有完全相同的错误;) –

回答

1

我面临同样的情况禁用SSL3后的代码。生成新的证书后,它得到了工作。

相关问题