예제 #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);
            }
        }
예제 #2
0
        private void ProcessCipherSpecV2Buffer(SecurityProtocolType protocol, byte[] buffer)
        {
            TlsStream codes = new TlsStream(buffer);

            string prefix = (protocol == SecurityProtocolType.Ssl3) ? "SSL_" : "TLS_";

            while (codes.Position < codes.Length)
            {
                byte check = codes.ReadByte();

                if (check == 0)
                {
                    // SSL/TLS cipher spec
                    short code  = codes.ReadInt16();
                    int   index = this.Context.SupportedCiphers.IndexOf(code);
                    if (index != -1)
                    {
                        this.Context.Negotiating.Cipher = this.Context.SupportedCiphers[index];
                        break;
                    }
                }
                else
                {
                    byte[] tmp = new byte[2];
                    codes.Read(tmp, 0, tmp.Length);

                    int         tmpCode = ((check & 0xff) << 16) | ((tmp[0] & 0xff) << 8) | (tmp[1] & 0xff);
                    CipherSuite cipher  = this.MapV2CipherCode(prefix, tmpCode);

                    if (cipher != null)
                    {
                        this.Context.Negotiating.Cipher = cipher;
                        break;
                    }
                }
            }

            if (this.Context.Negotiating == null)
            {
                throw new TlsException(AlertDescription.InsuficientSecurity, "Insuficient Security");
            }
        }
예제 #3
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);
                }
            }
        }