Пример #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);
            }
        }
		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);
			}
		}
Пример #3
0
        private void ProcessCipherSpecV2Buffer(SecurityProtocolType protocol, byte[] buffer)
        {
            TlsStream tlsStream = new TlsStream(buffer);
            string    prefix    = (protocol != SecurityProtocolType.Ssl3) ? "TLS_" : "SSL_";

            while (tlsStream.Position < tlsStream.Length)
            {
                byte b = tlsStream.ReadByte();
                if (b == 0)
                {
                    short code = tlsStream.ReadInt16();
                    int   num  = Context.SupportedCiphers.IndexOf(code);
                    if (num != -1)
                    {
                        Context.Negotiating.Cipher = Context.SupportedCiphers[num];
                        break;
                    }
                    continue;
                }
                byte[] array = new byte[2];
                tlsStream.Read(array, 0, array.Length);
                int         code2       = ((b & 0xFF) << 16) | ((array[0] & 0xFF) << 8) | (array[1] & 0xFF);
                CipherSuite cipherSuite = MapV2CipherCode(prefix, code2);
                if (cipherSuite == null)
                {
                    continue;
                }
                Context.Negotiating.Cipher = cipherSuite;
                break;
            }
            if (Context.Negotiating == null)
            {
                throw new TlsException(AlertDescription.InsuficientSecurity, "Insuficient Security");
            }
        }
Пример #4
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		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 = new byte[length];
			handMsg.Read(data, 0, length);

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

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

			// Update session
			if (message != null)
			{
				message.Update();
			}
		}
Пример #6
0
        private void ProcessCipherSpecV2Buffer(SecurityProtocolType protocol, byte[] buffer)
        {
            TlsStream tlsStream = new TlsStream(buffer);
            string    prefix    = protocol != SecurityProtocolType.Ssl3 ? "TLS_" : "SSL_";

            while (tlsStream.Position < tlsStream.Length)
            {
                byte num = tlsStream.ReadByte();
                if (num == (byte)0)
                {
                    int index = this.Context.SupportedCiphers.IndexOf(tlsStream.ReadInt16());
                    if (index != -1)
                    {
                        this.Context.Negotiating.Cipher = this.Context.SupportedCiphers[index];
                        break;
                    }
                }
                else
                {
                    byte[] buffer1 = new byte[2];
                    tlsStream.Read(buffer1, 0, buffer1.Length);
                    int         code        = ((int)num & (int)byte.MaxValue) << 16 | ((int)buffer1[0] & (int)byte.MaxValue) << 8 | (int)buffer1[1] & (int)byte.MaxValue;
                    CipherSuite cipherSuite = this.MapV2CipherCode(prefix, code);
                    if (cipherSuite != null)
                    {
                        this.Context.Negotiating.Cipher = cipherSuite;
                        break;
                    }
                }
            }
            if (this.Context.Negotiating == null)
            {
                throw new TlsException(AlertDescription.InsuficientSecurity, "Insuficient Security");
            }
        }
        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);
        }
Пример #8
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");
            }
        }
Пример #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);
                }
            }
        }
		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");
			}
		}