Socket and Authentication failed because the remote party has closed the transport stream exception in WPF
Got it working.
The server who is hosting the socket server MUST have installed on its Certification Storage the certificate WITH the Private Key. If you install it without it (just the certificate or just the public key) you will get those errors of authentication failure.
I hope it help.
Comments
-
Zozo about 2 years
I am trying to connect with Java netty based server, which auto generates certificates for itself (and server guys told me, that is accepting any certificate from client side for now).
My task was to migrate TcpSocket connection into Tls encrypted connection.
First of all, I converted TcpSocket into NetworkStream:
using (var client = new NetworkStream(connection.TcpSocket)) { if (client.CanRead) { client.BeginRead(recvState.DataBuffer, 0, recvState.DataBuffer.Length, ReceiveCallback, recvState); } }
and that is working perfectly. So then, I decided to build SslAuthentication - like here:
using (var client = new NetworkStream(connection.TcpSocket)) using (var sslStream = new SslStream(client, false, App_CertificateValidation)) { var clientCertificate = new X509Certificate2("client.pfx"); var clientCertificateCollection = new X509Certificate2Collection(new[] { clientCertificate }); sslStream.AuthenticateAsClient("MyServer", clientCertificateCollection, SslProtocols.Tls, false); if (sslStream.CanRead) { sslStream.BeginRead(recvState.DataBuffer, 0, recvState.DataBuffer.Length, ReceiveCallback, recvState); } }
Where
client.pfx
is random certificate with no password, as a file in project and also imported intoCurrent User Certificates > Personal > Certificates
incertmgr.msc
.The problem is AuthenticateAsClient throws an
System.IO.IOException: Authentication failed because the remote party has closed the transport stream exception.
Also, if the hostname in AuthenticateAsCtlient method means anything, if server accepts every certificate? Should I put there something significant?
I still can contact with the server guys, so I can ask them about everything - do we need any additional information?
-
Zozo over 9 yearsI am going to pass this answer to our server team. Thank you!
-
Rajdeep Paliwal almost 9 yearsmy application sends mail for 8 to 10 hours then it throws exception like this "Authentication failed because the remote party has closed the transport stream." how to deal with this case? please help.
-
Brandon over 7 yearsDude, you just saved my ass with this post. Thank you so much! I would totally give you ALL of my reputation points right now if I could! lol!