/// <summary>
        /// Sign into the system
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSignIn_Click(object sender, EventArgs e)
        {
            string clientMessage = string.Empty;
            SocketCommunication socketComm = new SocketCommunication();
            string[] message = {"username:"******"password:"******"START",
                AcknowledgementMsg = "ACK",
                Trailer = "END"
            };

            // receivedBytes hold TGT
            receivedBytes = new SocketCommunication().SendMessage(11000, ack);

            ClientHome clientHome = new ClientHome(username,password,receivedBytes,sessionKey);
            clientHome.Show();
            this.Hide();
        }
 /// <summary>
 /// Sign up button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonSignUp_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(textBoxUsername.Text) && !string.IsNullOrEmpty(textBoxPassword.Text) && !string.IsNullOrEmpty(textBoxConfirmPassword.Text))
     {
         if (textBoxPassword.Text.Equals(textBoxConfirmPassword.Text))
         {
             SocketCommunication socketComm = new SocketCommunication();
             SignUpCredential signUpCredential = new SignUpCredential()
             {
                 Username = textBoxUsername.Text,
                 Password = textBoxPassword.Text
             };
             new SocketCommunication().SendMessage(11000, signUpCredential);
         }
         else
         {
             MessageBox.Show("Password mismatch!");
         }
         new ProjectKerberosForm().Show();
         this.Hide();
     }
 }
        /// <summary>
        /// Get available service list from service providing server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonRefreshServiceList_Click(object sender, EventArgs e)
        {
            ServiceListRequest serviceListRequest = new ServiceListRequest() { Username = username };
            byte[] receivedMessage = new SocketCommunication().SendMessage(11001, serviceListRequest);

            // Deserialize the dataByte
            Object serverMessageObject = Formatter.Deserialize(receivedMessage);
            ServiceList serviceList = (ServiceList)serverMessageObject;
            listBoxService.DataSource = serviceList.Services;
        }
        /// <summary>
        /// Sends chat message to service providing server.
        /// </summary>
        /// <param name="serviceFunctionName"></param>
        /// <returns></returns>
        private byte[] SendChatMessage(string serviceFunctionName)
        {
            if (clientServerSessionKeyShared && !string.IsNullOrEmpty(clientServerSessionKey))
            {
                Chat chat = new Chat()
                {
                    ServiceName = selectedServiceName,
                    Message = serviceFunctionName
                };

                byte[] serializedChatMessage = Formatter.Serialize(chat);
                byte[] encryptedSerializedChatMessage = TripleDESEncryption.Encrypt(serializedChatMessage, clientServerSessionKey);
                ChatMessage chatMessage = new ChatMessage()
                {
                    Message = encryptedSerializedChatMessage
                };
                byte[] receivedChatMessage = new SocketCommunication().SendMessage(11001, chatMessage);
                return receivedChatMessage;
            }
            return null;
        }
 /// <summary>
 /// Processes chat response message from service providing server
 /// </summary>
 /// <param name="chatMsgReply"></param>
 private void ProcessChatResponseMessage(byte[] chatMsgReply)
 {
     ClearDisplay();
     byte[] decryptedNewAuthenticationDataByte = new SocketCommunication().DecryptMessage(chatMsgReply, clientServerSessionKey);
     Object serverReplyMessageObject = Formatter.Deserialize(decryptedNewAuthenticationDataByte);
     if (serverReplyMessageObject is ChatReply)
     {
         ChatReply chatReply = (ChatReply)serverReplyMessageObject;
         foreach (string msg in chatReply.Message)
         {
             DisplayMessage(msg);
         }
     }
 }
        /// <summary>
        /// Request an access for particular service
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonRequestService_Click(object sender, EventArgs e)
        {
            ServiceRequest servReqSelected = new ServiceRequest()
            {
                Auth = new Authenticator() { Username = username, TimeStamp = DateTime.Now.AddHours(12) },
                EncryptedTGT = receivedByte,
                ServiceName = listBoxService.GetItemText(listBoxService.SelectedItem)
            };

            // Serialize the session object into bytes
            byte[] serializedServReqObject = Formatter.Serialize(servReqSelected);
            // Encrypt the serialized bytes using hash generated from user password.
            byte[] encryptedServReqObject = TripleDESEncryption.Encrypt(serializedServReqObject, sessionKeyKDC);

            ClientSessionKeyEncryptedServReqMessage clientSessionServReqMessage = new ClientSessionKeyEncryptedServReqMessage()
            {
                Username = username,
                Message = encryptedServReqObject
            };

            // Send the bytes to server.
            byte[] receivedMessage = new SocketCommunication().SendMessage(11000, clientSessionServReqMessage);

            Object serverMessageObject = Formatter.Deserialize(receivedMessage);
            TGSResponseforServiceReq tgsResponseForServiceReq = (TGSResponseforServiceReq)serverMessageObject;

            byte[] decryptedDataByte = new SocketCommunication().DecryptMessage(tgsResponseForServiceReq.EncryptedSerializedTGSresponseB, sessionKeyKDC);

            // Deserialize the dataByte
            serverMessageObject = Formatter.Deserialize(decryptedDataByte);
            TGSResponseBforServiceReq tgsResponseB = (TGSResponseBforServiceReq)serverMessageObject;
            clientServerSessionKey = tgsResponseB.ClientServerSessionKey;

            // send the bytes to service server
            // a. send EncryptedSerializedTGSresponseA as it is
            ClientTGSResponseAforServiceReq clientTGSResponseAforServiceReq = new ClientTGSResponseAforServiceReq()
            { ServiceName = servReqSelected.ServiceName, EncryptedTGSResponseAforServiceReq = tgsResponseForServiceReq.EncryptedSerializedTGSresponseA };
            selectedServiceName = servReqSelected.ServiceName;
            byte[] receivedMessageServiceServer = new SocketCommunication().SendMessage(11001, clientTGSResponseAforServiceReq);

            // Deserialize the acknowledgment
            serverMessageObject = Formatter.Deserialize(receivedMessageServiceServer);
            Acknowledgement aCKtgsResponseB = (Acknowledgement)serverMessageObject;

            // b. send New Authenticator object
            newAuthenticator = new NewAuthenticator()
            {
                Username = username,
                TimeStamp = DateTime.Now
            };

            // Serialize the session object into bytes
            byte[] serializedNewAuthenticator = Formatter.Serialize(newAuthenticator);
            // Encrypt the serialized bytes using hash generated from user password.
            byte[] encryptedSerializedNewAuthenticator = TripleDESEncryption.Encrypt(serializedNewAuthenticator, tgsResponseB.ClientServerSessionKey);

            ClientNewAuthenticator clientNewAuthenticator = new ClientNewAuthenticator()
            {
                EncryptedSerializedNewAuthenticator = encryptedSerializedNewAuthenticator
            };

            byte[] receivedMessageClientNewAuthentication = new SocketCommunication().SendMessage(11001, clientNewAuthenticator);
            serverMessageObject = Formatter.Deserialize(receivedMessageClientNewAuthentication);
            ClientNewAuthenticator clientNewAuthenticationServerResponse = (ClientNewAuthenticator)serverMessageObject;
            byte[] decryptedNewAuthenticationDataByte = new SocketCommunication().DecryptMessage(clientNewAuthenticationServerResponse.EncryptedSerializedNewAuthenticator, tgsResponseB.ClientServerSessionKey);
            serverMessageObject = Formatter.Deserialize(decryptedNewAuthenticationDataByte);
            incrementedTimeStamp = (IncrementedTimeStamp)serverMessageObject;
            if (Math.Abs(incrementedTimeStamp.NewTimeStamp.Minute - newAuthenticator.TimeStamp.Minute) == 1)
            {
                if (!string.IsNullOrEmpty(selectedServiceName))
                {
                    if (selectedServiceName.ToUpper().Equals("WEATHER"))
                    {
                        groupBoxWeather.Visible = true;
                    }
                    else if (selectedServiceName.ToUpper().Equals("CURRENCY"))
                    {
                        groupBoxCurrency.Visible = true;
                    }
                }
                clientServerSessionKeyShared = true;
            }
            else
            {
                MessageBox.Show("Opps Timeout");
            }
        }