title: SslStream AuthenticateAsServer with optional ClientCertificate
body: <p>Considering the <a href="http://msdn.microsoft.com/en-us/library/ms145065%28v=vs.110%29.aspx" rel="nofollow"><em>SslStream.AuthenticateAsServer</em></a> method, the second parameter <em>clientCertificateRequired</em>:</p>
  
  <p>If it is set to true, a client certificate is required. It will throw an exception if not. The client certificate will be available in the property <em>RemoteCertificate</em>.</p>
  
  <p>When set to false, no client certificate is required, the property <em>RemoteCertificate</em> shall always be null. Even if one is provided by the client.</p>
  
  <p>What I like to accomplish is to <strong>let the client decide</strong> whether it will or will not provide a certificate. But, if they do provide one, I like to know it on the server.</p>
  
  <p>I have tried to first set the variable to true, if this fails, fallback to not require the certificat. However, this result in an "Already Authenticated Exception".</p>
  
  <pre><code>try{
          sslStream.AuthenticateAsServer(x509certificate, true, SslProtocols.Tls, true);
  }catch(Exception ex){
          sslStream.AuthenticateAsServer(x509certificate, false, SslProtocols.Tls, true);
  }
  </code></pre>