title: Using SSL and SslStream for peer to peer authentication?
body: <p>I need to provide secure communication between various processes that are using TCP/IP sockets for communication.  I want both authentication and encryption.  Rather than re-invent the wheel I would really like to use SSL and the SslStream class and self-signed certificates.  What I want to do is validate the remote process's certificate against a known copy in my local application.  (There doesn't need to be a certificate authority because I intend for the certificates to be copied around manually).</p>
  
  <p>To do this, I want the application to be able to automatically generate a new certifiate the first time it is run.  In addition to makecert.exe, it looks like <a href="http://blogs.msdn.com/dcook/archive/2008/11/25/creating-a-self-signed-certificate-in-c.aspx" rel="noreferrer">this link</a> shows a way to automatically generate self-signed certificates, so that's a start.</p>
  
  <p>I've looked at the AuthenticateAsServer and AuthenticateAsClient methods of SslStream.  You can provide call-backs for verification, so it looks like it's possible.  But now that I'm into the details of it, I really don't think it's possible to do this.</p>
  
  <p>Am I going in the right direction?  Is there a better alternative?  Has anyone done anything like this before (basically peer-to-peer SSL rather than client-server)?</p>