Ejemplo n.º 1
0
 public HandshakeServerHello(ProtocolVersion version) : base(HandshakeMessageType.ServerHello, version)
 {
     ServerVersion     = version;
     Random            = new HandshakeRandom();
     SessionID         = new byte[0];
     CipherSuite       = 0x0000;
     CompressionMethod = 0x00;
     Extensions        = new List <HelloExtension>();
 }
Ejemplo n.º 2
0
 public HandshakeClientHello(ProtocolVersion version) : base(HandshakeMessageType.ClientHello, version)
 {
     ClientVersion      = version;
     Random             = new HandshakeRandom();
     SessionID          = new byte[0];
     Cookie             = new byte[0];
     CipherSuites       = new List <UInt16>();
     CompressionMethods = new List <Byte>();
     Extensions         = new List <HelloExtension>();
 }
Ejemplo n.º 3
0
 public HandshakeClientHello(ProtocolVersion version)
     : base(HandshakeMessageType.ClientHello, version)
 {
     ClientVersion       = version;
     Random              = new HandshakeRandom();
     SessionID           = new byte[0];
     Cookie              = new byte[0];
     CipherSuites        = new List<UInt16>();
     CompressionMethods  = new List<Byte>();
     Extensions          = new List<HelloExtension>();
 }
Ejemplo n.º 4
0
        protected override void DecodeDataBytes(ProtocolVersion ver, byte[] data)
        {
            MemoryStream    memStream = new MemoryStream(data);
            HandshakeStream stream    = new HandshakeStream(memStream);

            byte major = stream.ReadUInt8();
            byte minor = stream.ReadUInt8();

            ServerVersion = new ProtocolVersion(major, minor);

            byte[] randomBytes = stream.ReadBytes(32);
            Random = new HandshakeRandom(randomBytes);

            int idLength = (int)stream.ReadUInt8();

            SessionID = stream.ReadBytes(idLength);

            CipherSuite       = stream.ReadUInt16();
            CompressionMethod = stream.ReadUInt8();

            byte[] extensionList = new byte[0];
            if (!stream.EndOfStream && ServerVersion.HasExtensions)
            {
                UInt16 extensionListLength = stream.ReadUInt16();
                extensionList = stream.ReadBytes(extensionListLength);
            }
            stream.ConfirmEndOfStream();

            int pos = 0;

            while (pos + 4 <= extensionList.Length)
            {
                UInt16 extensionType       = (UInt16)((extensionList[pos] << 8) | extensionList[pos + 1]);
                UInt16 extensionDataLength = (UInt16)((extensionList[pos + 2] << 8) | extensionList[pos + 3]);
                pos += 4;

                if (pos + extensionDataLength > extensionList.Length)
                {
                    throw new AlertException(AlertDescription.IllegalParameter,
                                             "ServerHello extension data length too large: " + extensionDataLength);
                }

                byte[] extensionData = new byte[extensionDataLength];
                Buffer.BlockCopy(extensionList, pos, extensionData, 0, extensionData.Length);
                pos += extensionData.Length;

                Extensions.Add(new HelloExtension(extensionType, extensionData));
            }
        }
Ejemplo n.º 5
0
        protected override void DecodeDataBytes(ProtocolVersion ver, byte[] data)
        {
            CipherSuites.Clear();
            CompressionMethods.Clear();

            MemoryStream memStream = new MemoryStream(data);
            HandshakeStream stream = new HandshakeStream(memStream);

            byte major = stream.ReadUInt8();
            byte minor = stream.ReadUInt8();
            ClientVersion = new ProtocolVersion(major, minor);

            byte[] randomBytes = stream.ReadBytes(32);
            Random = new HandshakeRandom(randomBytes);

            int idLength = (int) stream.ReadUInt8();
            SessionID = stream.ReadBytes(idLength);

            if (ClientVersion.IsUsingDatagrams) {
                int cookieLength = (int) stream.ReadUInt8();
                Cookie = stream.ReadBytes(cookieLength);
            }

            int cipherLength = (int) stream.ReadUInt16();
            for (int i=0; i<cipherLength; i+=2) {
                CipherSuites.Add(stream.ReadUInt16());
            }

            int compressionLength = (int) stream.ReadUInt8();
            for (int i=0; i<compressionLength; i++) {
                CompressionMethods.Add(stream.ReadUInt8());
            }

            byte[] extensionList = new byte[0];
            if (!stream.EndOfStream && ClientVersion.HasExtensions) {
                UInt16 extensionListLength = stream.ReadUInt16();
                extensionList = stream.ReadBytes(extensionListLength);
            }
            stream.ConfirmEndOfStream();

            int pos = 0;
            while (pos+4 <= extensionList.Length) {
                UInt16 extensionType = (UInt16) ((extensionList[pos] << 8) | extensionList[pos+1]);
                UInt16 extensionDataLength = (UInt16) ((extensionList[pos+2] << 8) | extensionList[pos+3]);
                pos += 4;

                if (pos+extensionDataLength > extensionList.Length) {
                    throw new AlertException(AlertDescription.IllegalParameter,
                                             "ClientHello extension data length too large: " + extensionDataLength);
                }

                byte[] extensionData = new byte[extensionDataLength];
                Buffer.BlockCopy(extensionList, pos, extensionData, 0, extensionData.Length);
                pos += extensionData.Length;

                Extensions.Add(new HelloExtension(extensionType, extensionData));
            }
        }