p divya

p divya

  • NA
  • 1
  • 4.8k

System.IO.IOException: Authentication failed because the rem

Apr 3 2013 8:14 AM

I'm creating a webservice ( in .NET 3.5) to obtain SSL certificate information of a remote server based on the domain name and i have a client which is a console application to call the service. presently for me there are 11 domain names. i am able to obtain the SSL information for all server except one.

my code is:

 using (TcpClient client = new TcpClient())
    {            
        client.Connect(strDNSEntry, 443);

        SslStream ssl = new SslStream(client.GetStream(), false);
        try
        {
            ssl.AuthenticateAsClient(strDNSEntry);    //Error thrown here
        }
        catch (AuthenticationException e)
        {
            log.Debug(e.Message);
            ssl.Close();
            client.Close();
            return cert;
        }
        catch (Exception e)
        {
            log.Debug(e.Message);
            ssl.Close();
            client.Close();
            return cert;
        }
        cert = new X509Certificate2(ssl.RemoteCertificate);
        ssl.Close();
        client.Close();
        return cert;
    }    

the error is

"[System.IO.IOException] = {"Authentication failed because the remote party has closed the transport stream."}".

When I examined during debugging at SSLStream I found the error as "

This operation is only allowed using a successfully authenticated context".

Is that because I don't have enough credentials is it throwing the error or any issues with the service? Also I tried to do Remote desktop conncetion to that server, I'm unable to coonect.