示例#1
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);
                }
            }
        }
示例#2
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);
            }
        }
        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);
        }
        public IAsyncResult BeginSendRecord(HandshakeType handshakeType, AsyncCallback callback, object state)
        {
            HandshakeMessage message = this.GetMessage(handshakeType);

            message.Process();
            RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = new RecordProtocol.SendRecordAsyncResult(callback, state, message);
            this.BeginSendRecord(message.ContentType, message.EncodeMessage(), new AsyncCallback(this.InternalSendRecordCallback), sendRecordAsyncResult);
            return(sendRecordAsyncResult);
        }
示例#5
0
        public IAsyncResult BeginSendRecord(HandshakeType handshakeType, AsyncCallback callback, object state)
        {
            HandshakeMessage message = GetMessage(handshakeType);

            message.Process();
            SendRecordAsyncResult sendRecordAsyncResult = new SendRecordAsyncResult(callback, state, message);

            BeginSendRecord(message.ContentType, message.EncodeMessage(), InternalSendRecordCallback, sendRecordAsyncResult);
            return(sendRecordAsyncResult);
        }
示例#6
0
        public IAsyncResult BeginSendRecord(HandshakeType handshakeType, AsyncCallback callback, object state)
        {
            HandshakeMessage msg = this.GetMessage(handshakeType);

            msg.Process();

            DebugHelper.WriteLine(">>>> Write handshake record ({0}|{1})", context.Protocol, msg.ContentType);

            SendRecordAsyncResult internalResult = new SendRecordAsyncResult(callback, state, msg);

            this.BeginSendRecord(msg.ContentType, msg.EncodeMessage(), new AsyncCallback(InternalSendRecordCallback), internalResult);

            return(internalResult);
        }
示例#7
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);
        }
示例#8
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);
            }
        }
示例#9
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);
                }
            }
        }