Exemple #1
0
        /// <summary>
        /// Encrypts the message before sending.
        /// </summary>
        /// <param name="client">Client object.</param>
        /// <param name="message">Message to be processed.</param>
        /// <returns>True if no other handler should process this message.</returns>
        bool IHandler.HandleSendMessage(Server server, ClientData client, ref Message message)
        {
            var additionalData = client.Resources.GetResource <AdditionalData>();

            if (additionalData.ClientState == ClientState.Encrypted)
            {
                message = CommunicationPrimitives.BuildMessage(this.EncryptBytes(additionalData.Key, message.MessageBytes));
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Performs operations on the message buffer, modifying it.
        /// </summary>
        /// <param name="client">Client connection.</param>
        /// <param name="message">Message to be processed.</param>
        /// <returns>True if no other handler should process it further.</returns>
        bool IHandler.PreHandleReceivedMessage(Client client, ref Message message)
        {
            if (this.connectionState == ConnectionState.Encrypted)
            {
                var encryptedBytes = message.MessageBytes;
                var decryptedBytes = this.DecryptBytes(encryptedBytes);
                message = CommunicationPrimitives.BuildMessage(decryptedBytes);
                return(false);
            }

            return(false);
        }