SslStream and AuthenticateAsServer

I'm trying to create authenticated SslStreams, with a certificate created with OpenSSL (which is read from file). I can read the certificate without a problem from within C#. The problem is my code hangs whenever I call AuthenticateAsStream(). My question is, I'm creating (and signing) the x509 certificates myself. Will this cause problems with AuthenticateAsStream What exactly does AuthenticateAsServer do

Thanks,
Josh


Answer this question

SslStream and AuthenticateAsServer

  • RameshKandukuri

    I realised that I wasn't matching the AuthenticateAsServer() on the server side with an AuthenticateAsClient() on the client side. The problem I get now is the following exception:
    System.NotSupportedException was caught
    Message="The server mode SSL must use a certificate with the associated private key."
    Source="System"
    StackTrace:
    at System.Net.Security.SecureChannel.AcquireServerCredentials(Byte[]& thumbPrint)
    at System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output)

    I can't find any documentation on this. Can anyone help I can post my certificate if needed.

    Thanks,
    Josh


  • Jamie Thomson

    To associate the private key with the certificate you need to creat a pkcs12 cert.

    openssl pkcs12 -export -in newcert.pem -out IceTestCert.p12 -name "CertName" -inkey newkey.pem

    The information is extracted from

    http://www.towersoft.com/sdk/doku.php id=ice:setting_up_an_ice_server_to_use_ssl


  • gmaenrile

    I've found the problem: the certificates created using OpenSSL (at least the way I was creating them) are not in the format reuqired/expected by C# (x509Certificate(string filename)) (specifically, they don't include the private key). I used http://blogs.technet.com/jhoward/archive/2005/02/02/365323.aspx which worked perfectly. I hope this prevents others from wasting their time as well...

  • redshock

    This could be usefull:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=767044&SiteID=1

  • Prabagarane

    I have the same problem, I used makecert.exe still not solving it. what is the parameters for makecert.exe
  • SslStream and AuthenticateAsServer