Click here to Skip to main content
15,891,704 members
Articles / Programming Languages / C#

Creating a secure channel

Rate me:
Please Sign up or sign in to vote.
4.90/5 (33 votes)
24 May 2008CDDL13 min read 118.1K   2.9K   86  
The purpose of this article is to explain how a secure channel is built. The article will explain the structure of a Very Simple Secured Protocol (VSSP) that sits above the TCP/IP layer.
using System;
using VSSProtocol.DataLayer;
using VSSProtocol.Session;
using VSSProtocol.Suits;
using VSSProtocol.Users;
using VSSProtocol.Utils;

namespace VSSProtocol.States
{
	internal class ServerKeyExchangeState : IState
	{
		/// <summary>
		/// Assets collected during the hello state.
		/// </summary>
		private readonly Assets assets;
		/// <summary>
		/// Chosen suit by the server.
		/// </summary>
		private readonly Suit chosenSuit;


		public ServerKeyExchangeState(Assets assets, Suit chosenSuit)
		{
			if (assets == null) throw new ArgumentNullException("assets");

			this.assets = assets;
			this.chosenSuit = chosenSuit;
		}

		#region IState Members

		/// <summary>
		/// Process connection and decide what to do according to data read from the connection.
		/// </summary>
		/// <param name="context">States are part of a VSS Protocol user class.</param>
		public void Process(VsspManager context)
		{
			if (context == null) throw new ArgumentNullException("context");
			DataLayerService dataLayerService = context.DataLayer;

			// Recieve from client encrypted premaster key.
			byte[] receivedMessage;
			DataPacket p = dataLayerService.ReceiveMessage(out receivedMessage);
			byte[] encryptedPreMaster = p.Data;
			// Decrypt it.
			IAsymmetricAlgorithm asym = 
				SessionFactory.CreateAsymetricAlgorithmFromSuit(chosenSuit, assets.ServerCertificate);
			byte[] decryptedPreMaster = asym.Decrypt(encryptedPreMaster); //TODO change
			// Now build the suit.
			ISession session = SessionFactory.CreateSessionFromSuit(chosenSuit, assets, ref decryptedPreMaster);
			context.Session = session;

			// Update messages that were sent and retreived.
			context.MessagesReceived.Add(receivedMessage);

			// Now move to the next state.
			MacState macState = new MacState();
			context.CurrentState = macState;
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer
Israel Israel
A computer science master student at Bar Ilan University under the supervision of Dr. Gal Kaminka.
Dealing mainly with trajectory mining.

Comments and Discussions