예제 #1
0
        override public void Parse()
        {
            MemoryStream      ms  = new MemoryStream(payload);
            NetworkByteReader nbr = new NetworkByteReader(ms);

            nbr.ReadByte();
            cookie                                  = nbr.ReadBytes(16);
            kex_algorithms                          = nbr.ReadNameList();
            server_host_key_algorithms              = nbr.ReadNameList();
            encryption_algorithms_client_to_server  = nbr.ReadNameList();
            encryption_algorithms_server_to_client  = nbr.ReadNameList();
            mac_algorithms_client_to_server         = nbr.ReadNameList();
            mac_algorithms_server_to_client         = nbr.ReadNameList();
            compression_algorithms_client_to_server = nbr.ReadNameList();
            compression_algorithms_server_to_client = nbr.ReadNameList();
            languages_client_to_server              = nbr.ReadNameList();
            languages_server_to_client              = nbr.ReadNameList();
            first_kex_packet_follows                = nbr.ReadBoolean();
            reserved                                = nbr.ReadUInt32();
        }
예제 #2
0
        public Packet RecvPacket(ICryptoTransform decryptor)
        {
            if (decryptor == null)
            {
                Packet packet = new Packet();
                uint packet_length = reader.ReadUInt32();
                byte padding_length = reader.ReadByte();
                byte[] payload = reader.ReadBytes(packet_length - padding_length - 1);
                byte[] padding = reader.ReadBytes(padding_length);
                packet.SetPayload(payload);
                return packet;
            }
            else
            {
                int blocksize = Math.Max(decryptor.InputBlockSize, 8);
                MemoryStream ms_packet = new MemoryStream();
                NetworkByteWriter writer_packet = new NetworkByteWriter(ms_packet);

                byte[] buffer = new byte[blocksize];

                bool first = true;
                int more = 0;
                while (true)
                {
                    // read a block
                    int ret = reader.ReadBytes(buffer, 0, blocksize);
                    // must be a real block size;
                    if (ret != blocksize) return null;
                    decryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0);
                    writer_packet.WriteBytes(buffer);

                    if (first) // it's first time, need parse packet_length and padding_length
                    {
                        NetworkByteReader reader_buffer = new NetworkByteReader(new MemoryStream(buffer));
                        uint packet_length_t = reader_buffer.ReadUInt32();
                        first = false;

                        more = (int)packet_length_t + 4 - blocksize;
                        if (more % blocksize != 0) return null;
                    }
                    else
                    {
                        more -= blocksize;
                    }
                    if (more <= 0) break;
                }

                byte[] mac = reader.ReadBytes(20);

                ms_packet.Seek(0, SeekOrigin.Begin);
                NetworkByteReader reader_packet = new NetworkByteReader(ms_packet);

                Packet packet = new Packet();
                uint packet_length = reader_packet.ReadUInt32();
                byte padding_length = reader_packet.ReadByte();
                byte[] payload = reader_packet.ReadBytes(packet_length - padding_length - 1);
                byte[] padding = reader_packet.ReadBytes(padding_length);
                packet.SetPayload(payload);

                return packet;
            }
        }
예제 #3
0
 public override void Parse()
 {
     MemoryStream ms = new MemoryStream(payload);
     NetworkByteReader nbr = new NetworkByteReader(ms);
     nbr.ReadByte();
     cookie = nbr.ReadBytes(16);
     kex_algorithms = nbr.ReadNameList();
     server_host_key_algorithms = nbr.ReadNameList();
     encryption_algorithms_client_to_server = nbr.ReadNameList();
     encryption_algorithms_server_to_client = nbr.ReadNameList();
     mac_algorithms_client_to_server = nbr.ReadNameList();
     mac_algorithms_server_to_client = nbr.ReadNameList();
     compression_algorithms_client_to_server = nbr.ReadNameList();
     compression_algorithms_server_to_client = nbr.ReadNameList();
     languages_client_to_server = nbr.ReadNameList();
     languages_server_to_client = nbr.ReadNameList();
     first_kex_packet_follows = nbr.ReadBoolean();
     reserved = nbr.ReadUInt32();
 }
예제 #4
0
        public Packet RecvPacket(ICryptoTransform decryptor)
        {
            if (decryptor == null)
            {
                Packet packet         = new Packet();
                uint   packet_length  = reader.ReadUInt32();
                byte   padding_length = reader.ReadByte();
                byte[] payload        = reader.ReadBytes(packet_length - padding_length - 1);
                byte[] padding        = reader.ReadBytes(padding_length);
                packet.SetPayload(payload);
                return(packet);
            }
            else
            {
                int               blocksize     = Math.Max(decryptor.InputBlockSize, 8);
                MemoryStream      ms_packet     = new MemoryStream();
                NetworkByteWriter writer_packet = new NetworkByteWriter(ms_packet);

                byte[] buffer = new byte[blocksize];

                bool first = true;
                int  more  = 0;
                while (true)
                {
                    // read a block
                    int ret = reader.ReadBytes(buffer, 0, blocksize);
                    // must be a real block size;
                    if (ret != blocksize)
                    {
                        return(null);
                    }
                    decryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0);
                    writer_packet.WriteBytes(buffer);

                    if (first) // it's first time, need parse packet_length and padding_length
                    {
                        NetworkByteReader reader_buffer = new NetworkByteReader(new MemoryStream(buffer));
                        uint packet_length_t            = reader_buffer.ReadUInt32();
                        first = false;

                        more = (int)packet_length_t + 4 - blocksize;
                        if (more % blocksize != 0)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        more -= blocksize;
                    }
                    if (more <= 0)
                    {
                        break;
                    }
                }

                byte[] mac = reader.ReadBytes(20);


                ms_packet.Seek(0, SeekOrigin.Begin);
                NetworkByteReader reader_packet = new NetworkByteReader(ms_packet);

                Packet packet         = new Packet();
                uint   packet_length  = reader_packet.ReadUInt32();
                byte   padding_length = reader_packet.ReadByte();
                byte[] payload        = reader_packet.ReadBytes(packet_length - padding_length - 1);
                byte[] padding        = reader_packet.ReadBytes(padding_length);
                packet.SetPayload(payload);

                return(packet);
            }
        }