views:

103

answers:

2

I have a rich client application that is connecting to a set of backing web services where the connection is secured by SSL. I need to determine the "strength" of the encryption being used for the actual SSL stream to display this information to the end user.

My understanding is that the client and server will negotiate a symmetric encryption method between them (SSL/TLS) with different levels of encryption (40,56,128,256). Is there any way I can detect which mode is being used from a HttpWebRequest/ServicePoint/other in C# code?

+1  A: 

Since you have established an SslStream stream, you could use the following:

stream.CipherAlgorithm //to get the algorithm that is used
stream.CipherStrength //to get the strength of the cipher algorithm

You can find more information here.

Alex
A: 

This expands upon @Alex's post, obviously add your own error handling

        System.Net.Sockets.TcpClient TC = new System.Net.Sockets.TcpClient();
        TC.Connect("mail.google.com", 443);
        using (System.Net.Security.SslStream Ssl = new System.Net.Security.SslStream(TC.GetStream()))
        {
            Ssl.AuthenticateAsClient("mail.google.com");
            Console.WriteLine(Ssl.CipherAlgorithm);
            Console.WriteLine(Ssl.CipherStrength);
        }
        TC.Close();

I don't think you can access the SSL information from the web service directly, you'll have to use this helper code to talk to the host directly.

Chris Haas