title: AuthenticateAsClient: System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream
body: <p>Due to <a href="http://en.wikipedia.org/wiki/Heartbleed" rel="nofollow noreferrer">Heartbleed</a>, our Gateway Server was updated and this problem presented itself.</p>
  
  <p>Due to <a href="http://en.wikipedia.org/wiki/POODLE" rel="nofollow noreferrer">POODLE</a>, SSLv3 is no longer supported.</p>
  
  <ul>
  <li>Note, the problem is only present on Win7+ boxes; WinXP boxes work without issue (same code, different OS = problem); granted WinXP is no longer a valid OS, just wanted to make note of functionality.</li>
  </ul>
  
  <p>Client application (.NET 2.0) sits on a Windows 7 (or 8) box.  Server runs within a DMZ behind a Gateway Server.  Just to note, I found that this problem is no longer present on .NET 4.0+ - however due to legacy code, I do not have the luxury of updating.</p>
  
  <p>Gateway Server is a pass through box on which Apache HTTP Server with SSL run.  Its location is outside the DMZ, and it is used to access the Server which is inside the DMZ.  Versions of software running on the Gateway server are Apache/2.2.25 (Win32), mod_jk/1.2.39, mod_ssl/2.2.25, OpenSSL/1.0.1g</p>
  
  <p>Here is the code used on the Client application (with an exorbitant amount of logging added) ... note, 'serverName' typically contains a value such as "<a href="https://some.url.com" rel="nofollow noreferrer">https://some.url.com</a>"</p>
  
  <pre><code>private bool ConnectAndAuthenicate(string serverName, out TcpClient client, out SslStream sslStream)
  {
      client = null;
      sslStream = null;
      try
      {
          client = new TcpClient(serverName, 443); // Create a TCP/IP client; ctor attempts connection
          Log("ConnectAndAuthenicate: Client CONNECTED"));
  
          sslStream = new SslStream(client.GetStream(), false, ValidateServerCertificate, null);
          Log("ConnectAndAuthenicate: SSL Stream CREATED"));
      }
      catch (Exception x)
      {
          Log("ConnectAndAuthenicate: EXCEPTION &gt;&gt; CONNECTING to server: {0}", x.ToString()));
  
          if (x is SocketException)
          {
              SocketException s = x as SocketException;
              Log("ConnectAndAuthenicate: EXCEPTION &gt;&gt; CONNECTING to server: Socket.ErrorCode: {0}", s.ErrorCode));
          }
          if (client != null) { client.Close(); client = null; }
          if (sslStream != null) { sslStream.Close(); sslStream = null; }
      }
  
      if (sslStream == null) return false;
  
      try
      {
          sslStream.ReadTimeout = 10000; // wait 10 seconds for a response ...
          Log("ConnectAndAuthenicate: AuthenticateAsClient CALLED ({0})", serverName));
          sslStream.AuthenticateAsClient(serverName);
          Log("ConnectAndAuthenicate: AuthenticateAsClient COMPLETED SUCCESSFULLY"));
          return true;
      }
      catch (Exception x)
      {
          Log("ConnectAndAuthenicate: EXCEPTION &gt;&gt; AuthenticateAsClient: {0}", x.ToString()));
          client.Close(); client = null;
          sslStream.Close(); sslStream = null;
      }
      return false;
  }
  </code></pre>
  
  <p>Note - <a href="https://stackoverflow.com/a/12244894/3259125">answers posted</a> pertaining to ServicePointManager have absolutely no effect on the outcome of this application.</p>
  
  <p>Every time that AuthenicateAsClient() is called when application is run on Win 7+ box, the exception occurs - if application is run on WinXP box, code works properly without exceptions.</p>
  
  <p>Any ideas for solutions are very welcome.</p>