我收到以下错误"身份验证失败,因为远程方已关闭传输流"
之后的代码: stream.AuthenticateAsClient(this.appleSettings.Host,this.certificates,System.Security.Authentication.SslProtocols.Ssl3,false);
它注定了有效的第12页
void connect()
{
client = new TcpClient();
//Notify we are connecting
var eoc = this.OnConnecting;
if (eoc != null)
eoc(this.appleSettings.Host, this.appleSettings.Port);
try
{
client.Connect(this.appleSettings.Host, this.appleSettings.Port);
}
catch (Exception ex)
{
throw new ConnectionFailureException("Connection to Host Failed", ex);
}
if (appleSettings.SkipSsl)
{
networkStream = client.GetStream();
}
else
{
stream = new SslStream(client.GetStream(), false,
new RemoteCertificateValidationCallback((sender, cert, chain, sslPolicyErrors) => { return true; }),
new LocalCertificateSelectionCallback((sender, targetHost, localCerts, remoteCert, acceptableIssuers) =>
{
return certificate;
}));
try
{
stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);
//stream.AuthenticateAsClient(this.appleSettings.Host);
}
catch (System.Security.Authentication.AuthenticationException ex)
{
throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex);
}
if (!stream.IsMutuallyAuthenticated)
throw new ConnectionFailureException("SSL Stream Failed to Authenticate", null);
if (!stream.CanWrite)
throw new ConnectionFailureException("SSL Stream is not Writable", null);
networkStream = stream;
}
//Start reading from the stream asynchronously
Reader();
}
}
答案 0 :(得分:4)
stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);
https://developer.apple.com/news/?id=10222014a
Apple推送服务器不再支持SSL3。尝试将此更改为.Default或.TLS,它应该工作。
答案 1 :(得分:1)
我使用了Moon API for .NET,并将Protocol Ssl3更改为Tls,如上所述 并使用.p12文件而不是.pem .p12是使用以下证书生成的。
$ openssl pkcs12 -export -in chatPushCert.pem -inkey chatPushKey.pem -certfile CertificateSigningRequest.certSigningRequest -name" apn_developer_identity" -out apn_developer_identity.p12
并且每件事情都很好。