public static new bool TryParse(Frame parentFrame, int packetStartIndex, int packetEndIndex, out AbstractPacket result)
        {
            result = null;
            if (!Enum.IsDefined(typeof(ContentTypes), parentFrame.Data[packetStartIndex]))
            {
                return(false);
            }

            //verify that the complete TLS record has been received
            ushort length = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex + 3);

            if (length + 5 > packetEndIndex - packetStartIndex + 1)
            {
                return(false);
            }

            try {
                result = new TlsRecordPacket(parentFrame, packetStartIndex, packetEndIndex);
            }
            catch {
                result = null;
            }

            if (result == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#2
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }
            int tlsRecordBytes = 0;

            while (PacketStartIndex + tlsRecordBytes < PacketEndIndex)
            {
                AbstractPacket packet;
                try {
                    packet = new TlsRecordPacket(ParentFrame, PacketStartIndex + tlsRecordBytes, PacketEndIndex);
                }
                catch {
                    packet = new RawPacket(ParentFrame, PacketStartIndex + tlsRecordBytes, PacketEndIndex);
                }
                //tht TLS packets automatically shrinks if needed
                tlsRecordBytes += packet.PacketByteCount;
                yield return(packet);

                foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
                {
                    yield return(subPacket);
                }
            }
        }
示例#3
0
        public static new bool TryParse(Frame parentFrame, int packetStartIndex, int packetEndIndex, out AbstractPacket result)
        {
            bool validTls = TlsRecordPacket.TryParse(parentFrame, packetStartIndex, packetEndIndex, out result);

            if (validTls)
            {
                try {
                    result = new SslPacket(parentFrame, packetStartIndex, packetEndIndex);
                }
                catch {
                    result = null;
                }
            }
            return(validTls && result != null);
        }