IgorShare Thoughts and Ideas

Consulting and Training

Part 1- Securing Client Stream with SSL

Posted by Igor Moochnick on 11/11/2007

Most of the communications outside of your home network are secured and encrypted. The most popular kind of a secured communication today is the SSL. In most cases it is not even required to do any configuration for the end user.

Let’s assume: we have a server that requires that all the incoming connections be secured with SSL. The following post shows an example of how this can be accomplished.

I’ll show you the implementation by securing the POP3 communication while retrieving e-mails from the Gmail POP3 servers by the POP3 tunneling client. This client was introduced by Bart De Smet in this series of posts:
Pop3 Tunneling

Note that authentication of the client is optional. This allows us to use the SSL only for the channel encryption without any client authentication and authorization. This is why the HTTPS (HTTP over SSL) is widely popular – the end users are not required to issue and configure their own certificates and the server-side issued certificates are used to encrypt the traffic.

// The following method is invoked by the RemoteCertificateValidationDelegate.
private bool ValidateServerCertificate(
   object sender,
   X509Certificate certificate,
   X509Chain chain,
   SslPolicyErrors sslPolicyErrors)
{
   if (sslPolicyErrors == SslPolicyErrors.None)
       return true;  

     Console.WriteLine("Certificate error: {0}", sslPolicyErrors);  

     // Do not allow this client to communicate with unauthenticated servers.
     return false;
}

SslStream sslStream = new SslStream(client.GetStream(), false,
        new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
        sslStream.AuthenticateAsClient(server);
        stream = sslStream;

The modified Pop3Client (Pop3ClientSecured) code can be downloaded here. The package includes a test application as well, so you’re welcome to try it against your Gmail account (if you have it or any other POP3 account).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: