Example #1
0
        protected override void ProcessHandshakeMessage(TlsStream handMsg)
        {
            HandshakeType    handshakeType = (HandshakeType)handMsg.ReadByte();
            HandshakeMessage message       = null;

            // Read message length
            int length = handMsg.ReadInt24();

            // Read message data
            byte[] data = new byte[length];
            handMsg.Read(data, 0, length);

            // Create and process the server message
            message = this.createClientHandshakeMessage(handshakeType, data);
            message.Process();

            // Update the last handshake message
            this.Context.LastHandshakeMsg = handshakeType;

            // Update session
            if (message != null)
            {
                message.Update();
                this.Context.HandshakeMessages.WriteByte((byte)handshakeType);
                this.Context.HandshakeMessages.WriteInt24(length);
                this.Context.HandshakeMessages.Write(data, 0, data.Length);
            }
        }
Example #2
0
        protected override void ProcessHandshakeMessage(TlsStream handMsg)
        {
            HandshakeType    handshakeType    = (HandshakeType)handMsg.ReadByte();
            HandshakeMessage handshakeMessage = null;
            int num = handMsg.ReadInt24();

            byte[] array = null;
            if (num > 0)
            {
                array = new byte[num];
                handMsg.Read(array, 0, num);
            }
            handshakeMessage = createServerHandshakeMessage(handshakeType, array);
            handshakeMessage?.Process();
            base.Context.LastHandshakeMsg = handshakeType;
            if (handshakeMessage != null)
            {
                handshakeMessage.Update();
                base.Context.HandshakeMessages.WriteByte((byte)handshakeType);
                base.Context.HandshakeMessages.WriteInt24(num);
                if (num > 0)
                {
                    base.Context.HandshakeMessages.Write(array, 0, array.Length);
                }
            }
        }
        protected override void ProcessHandshakeMessage(TlsStream handMsg)
        {
            HandshakeType type  = (HandshakeType)handMsg.ReadByte();
            int           count = handMsg.ReadInt24();

            byte[] buffer = (byte[])null;
            if (count > 0)
            {
                buffer = new byte[count];
                handMsg.Read(buffer, 0, count);
            }
            HandshakeMessage handshakeMessage = this.createServerHandshakeMessage(type, buffer);

            handshakeMessage?.Process();
            this.Context.LastHandshakeMsg = type;
            if (handshakeMessage == null)
            {
                return;
            }
            handshakeMessage.Update();
            this.Context.HandshakeMessages.WriteByte((byte)type);
            this.Context.HandshakeMessages.WriteInt24(count);
            if (count <= 0)
            {
                return;
            }
            this.Context.HandshakeMessages.Write(buffer, 0, buffer.Length);
        }
Example #4
0
        public byte[] EncodeHandshakeRecord(HandshakeType handshakeType)
        {
            HandshakeMessage msg = this.GetMessage(handshakeType);

            msg.Process();

            var bytes = this.EncodeRecord(msg.ContentType, msg.EncodeMessage());

            msg.Update();

            msg.Reset();

            return(bytes);
        }
Example #5
0
        protected void WriteOperations(MemoryStream ms, params HandshakeMessage [] msgs)
        {
            List <byte []> rawbufs = new List <byte []> ();
            int            total   = 0;

            for (int i = 0; i < msgs.Length; i++)
            {
                HandshakeMessage msg = msgs [i];
                msg.Process();
                rawbufs.Add(msg.EncodeMessage());
                total += rawbufs [i].Length;
                msg.Update();
            }
            // FIXME: split packets when the size exceeded 0x10000 (or so)
            ms.WriteByte((byte)(total / 0x100));
            ms.WriteByte((byte)(total % 0x100));
            foreach (byte [] bytes in rawbufs)
            {
                ms.Write(bytes, 0, bytes.Length);
            }
        }
Example #6
0
        protected override void ProcessHandshakeMessage(TlsStream handMsg)
        {
            HandshakeType    handshakeType = (HandshakeType)handMsg.ReadByte();
            HandshakeMessage message       = null;

            DebugHelper.WriteLine(">>>> Processing Handshake record ({0})", handshakeType);

            // Read message length
            int length = handMsg.ReadInt24();

            // Read message data
            byte[] data = null;
            if (length > 0)
            {
                data = new byte[length];
                handMsg.Read(data, 0, length);
            }

            // Create and process the server message
            message = this.createServerHandshakeMessage(handshakeType, data);
            if (message != null)
            {
                message.Process();
            }

            // Update the last handshake message
            this.Context.LastHandshakeMsg = handshakeType;

            // Update session
            if (message != null)
            {
                message.Update();
                this.Context.HandshakeMessages.WriteByte((byte)handshakeType);
                this.Context.HandshakeMessages.WriteInt24(length);
                if (length > 0)
                {
                    this.Context.HandshakeMessages.Write(data, 0, data.Length);
                }
            }
        }