SslStream TcpClient - Received unexpected EOF or 0 bytes from transport stream

I am trying to connect to the server through the SslStream / Tcp Client. Every time I do, I get an exception message: Got an unexpected EOF or 0 bytes from the transport stream in the AuthenticateAsClient line.

I have enabled trace logging and get the following two errors in the logs:

Information about System.Net: 0: [12260] SecureChannel # 66702757 ::. ctor (hostname = xxx.xx.xx.xxx, # clientCertificates = 0, encryptionPolicy = RequireEncryption)

Information about System.Net: 0: [12260] SecureChannel # 66702757 - There are 0 client certificates left to choose from.

Can anyone give me any advice on how to solve this? Not sure why, but he throws it on the outside catch, if that matters.

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;
}
+5
1

, .

+2

All Articles