I'm trying to connect to a server via a SslStream / Tcp Client. Everytime I do I get an exception stating: Received an unexpected EOF or 0 bytes from the transport stream at the AuthenticateAsClient line.
I've enabled Trace logging and am getting the following two errors in the logs:
System.Net Information: 0 : [12260] SecureChannel#66702757::.ctor(hostname=xxx.xx.xx.xxx, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [12260] SecureChannel#66702757 - Left with 0 client certificates to choose from.
Would anybody be able to give me any advice on how to solve this? Not sure why but it's throwing to the outer catch if that makes any difference.
try
{
TcpClient client = new TcpClient(_host, _port);
// _stream = client.GetStream();
_stream = new SslStream(client.GetStream(), false, ValidateServerCertificate, null);
_sslReader = new StreamReader(client.GetStream());
try
{
_stream.AuthenticateAsClient(_host);
}
catch (AuthenticationException e)
{
client.Close();
return;
}
HandleConnect();
}
catch (Exception e)
{
_logger.Error(e.BuildExceptionInfo());
}
public bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None || sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch)
return true;
return false;
}
My guess is the server is requiring a client certificate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With