title: How can I connect a C# SSLStream client to an OpenSSL server?
body: <p>I am currentry writing <strong>a C# client</strong> (with Mono using SSLStream) <strong>for an already existing OpenSSL server</strong> written in C++. I know that in theory, they should be able to communicate, but I always get an Exception:</p>
  <blockquote>
  <p>Authentication or decryption has failed.</p>
  </blockquote>
  <p>Which takes place in <em>Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback</em> when I invoke <code>sslStream.AuthenticateAsClient(ServerName)</code>;</p>
  <p><strong>I do not need client authentication</strong>, so i don't use any client certificate, and i can't load my server certificate into a client's trust store, as I can't use the command line on the client side.</p>
  <p>On the server, I seem to receive some random data, which should not happen, as I never invoke <code>sslStream.Write()</code> in the client code. Maybe I don't completely understand how the handshake happens. I have an OpenSSL C++ client that works perfectly though.</p>
  <p>Does someone know How I could get this working?</p>
  <p>I am using, on the server side, a self-signed certificate generated by OpenSSL, which i converted to DER format.</p>
  <h2>How I proceed:</h2>
  <h3>Server side</h3>
  <ol>
  <li>Initialize OpenSSL</li>
  <li>Load server certificate (DER) and private key (PEM)</li>
  <li>Open a non-SSL listening socket</li>
  <li>As a client connects, I open a new socket which I connect to an SSL_Bio and accept the connection</li>
  <li>Read the SSL socket for incoming data.</li>
  </ol>
  <h3>Client side</h3>
  <p>I am trying to connect using a temporary client adapted from the one in <a href="https://stackoverflow.com/questions/6451910/c-sharp-ssl-secure-sockets">this topic</a>.</p>
  <ol>
  <li>Open a new TCPClient</li>
  <li>Link a new SSLStream to it with the same validation callback as in the thread above;</li>
  <li>Calling AuthenticateAsClient(ServerName) which brings this exception.</li>
  <li>Invoke <code>sslStream.Write</code> but the execution never gets here.</li>
  </ol>
  <p>Any help would be greatly appreciated as I am not sure to understand how sslStream internally works.</p>