Exemplo n.º 1
0
        public static ClientHello CreateFromSSL2CompatibleData(ProtocolVersion ver, byte[] buffer, int offset, uint length)
        {
            ClientHello msg = new ClientHello(ver);

            int    cipherLen    = BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref offset) / 3;
            ushort sessionIdLen = BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref offset);

            if (sessionIdLen != 0 && sessionIdLen != 16)
            {
                throw new Exception();
            }
            ushort challengeLen = BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref offset);

            if (challengeLen < 16)
            {
                throw new Exception();
            }
            if (challengeLen > RandomData.Size)
            {
                challengeLen = RandomData.Size;
            }
            msg._cipherSuites = new CipherSuite[cipherLen];
            for (int i = 0; i < cipherLen; i++)
            {
                msg._cipherSuites[i] = (CipherSuite)BitConverterBE.ReadUInt24AndMoveOffset(buffer, ref offset);
            }
            msg._sessionId = new byte[sessionIdLen];
            Buffer.BlockCopy(buffer, offset, msg._sessionId, 0, sessionIdLen);
            offset     += sessionIdLen;
            msg._random = new byte[RandomData.Size];
            Buffer.BlockCopy(buffer, offset, msg._random, 0, challengeLen);
            return(msg);
        }
Exemplo n.º 2
0
        public void ComputeServerMasterSecret(SecurityParameters sparams, byte[] raw, int offset, int length)
        {
            ushort len = BitConverterBE.ReadUInt16AndMoveOffset(raw, ref offset);

            byte[] premaster = _dh.PerformKeyAgreement(raw, offset, len);
            sparams.SetupMasterSecret(premaster);
        }
Exemplo n.º 3
0
        public ClientHello(byte[] buffer, int offset, uint length) : base(HandshakeType.ClientHello)
        {
            int idx = offset, end = (int)(offset + length);

            _version = (ProtocolVersion)BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref idx);
            _random  = RandomData.ReadRandomData(buffer, idx);
            idx     += RandomData.Size;

            if (buffer[idx] > 32)
            {
                throw new FormatException();
            }
            _sessionId = new byte[buffer[idx]];
            Buffer.BlockCopy(buffer, idx + 1, _sessionId, 0, _sessionId.Length);
            idx += 1 + _sessionId.Length;

            _cipherSuites = new CipherSuite[BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref idx) >> 1];
            for (int i = 0; i < _cipherSuites.Length; i++)
            {
                _cipherSuites[i] = (CipherSuite)BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref idx);
            }

            _compressions = new CompressionMethod[buffer[idx]];
            for (int i = 0; i < _compressions.Length; i++)
            {
                _compressions[i] = (CompressionMethod)buffer[idx + 1 + i];
            }
            idx += 1 + _compressions.Length;

            if (idx < end)
            {
                int extBytes          = BitConverterBE.ReadUInt16AndMoveOffset(buffer, ref idx);
                List <Extension> list = new List <Extension> ();
                while (idx < end)
                {
                    ExtensionType etype = (ExtensionType)BitConverterBE.ReadUInt16(buffer, idx);
                    int           esize = BitConverterBE.ReadUInt16(buffer, idx + 2);
                    byte[]        edata = new byte[esize];
                    Buffer.BlockCopy(buffer, idx + 4, edata, 0, esize);
                    list.Add(new Extension(etype, edata));
                    idx += 4 + esize;
                }
                _extensions = list.ToArray();
            }
            else
            {
                _extensions = Utility.EmptyExtensionArray;
            }
        }