Exemple #1
0
        internal /*virtual*/ void CheckRecordHeader(byte[] recordHeader)
        {
            byte type = TlsUtilities.ReadUint8(recordHeader, TLS_HEADER_TYPE_OFFSET);

            /*
             * RFC 5246 6. If a TLS implementation receives an unexpected record type, it MUST send an
             * unexpected_message alert.
             */
            CheckType(type, AlertDescription.unexpected_message);

            if (!mRestrictReadVersion)
            {
                int version = TlsUtilities.ReadVersionRaw(recordHeader, TLS_HEADER_VERSION_OFFSET);
                if ((version & 0xffffff00) != 0x0300)
                {
                    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
                }
            }
            else
            {
                ProtocolVersion version = TlsUtilities.ReadVersion(recordHeader, TLS_HEADER_VERSION_OFFSET);
                if (mReadVersion == null)
                {
                    // Will be set later in 'readRecord'
                }
                else if (!version.Equals(mReadVersion))
                {
                    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
                }
            }

            int length = TlsUtilities.ReadUint16(recordHeader, TLS_HEADER_LENGTH_OFFSET);

            CheckLength(length, mCiphertextLimit, AlertDescription.record_overflow);
        }
Exemple #2
0
        internal /*virtual*/ bool ReadRecord()
        {
            BufferSegment recordHeader = TlsUtilities.ReadAllOrNothing(TLS_HEADER_SIZE, mInput);

            if (recordHeader == BufferSegment.Empty)
            {
                return(false);
            }

            byte type = TlsUtilities.ReadUint8(recordHeader.Data, TLS_HEADER_TYPE_OFFSET);

            /*
             * RFC 5246 6. If a TLS implementation receives an unexpected record type, it MUST send an
             * unexpected_message alert.
             */
            CheckType(type, AlertDescription.unexpected_message);

            if (!mRestrictReadVersion)
            {
                int version = TlsUtilities.ReadVersionRaw(recordHeader.Data, TLS_HEADER_VERSION_OFFSET);
                if ((version & 0xffffff00) != 0x0300)
                {
                    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
                }
            }
            else
            {
                ProtocolVersion version = TlsUtilities.ReadVersion(recordHeader.Data, TLS_HEADER_VERSION_OFFSET);
                if (mReadVersion == null)
                {
                    mReadVersion = version;
                }
                else if (!version.Equals(mReadVersion))
                {
                    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
                }
            }

            int length = TlsUtilities.ReadUint16(recordHeader.Data, TLS_HEADER_LENGTH_OFFSET);

            BufferPool.Release(recordHeader.Data);

            CheckLength(length, mCiphertextLimit, AlertDescription.record_overflow);

            BufferSegment plaintext = DecodeAndVerify(type, mInput, length);

            mHandler.ProcessRecord(type, plaintext.Data, plaintext.Offset, plaintext.Count);
            BufferPool.Release(plaintext);

            return(true);
        }
Exemple #3
0
        internal virtual bool ReadRecord()
        {
            byte[] recordHeader = TlsUtilities.ReadAllOrNothing(TLS_HEADER_SIZE, mInput);
            if (recordHeader == null)
            {
                return(false);
            }

            byte type = TlsUtilities.ReadUint8(recordHeader, TLS_HEADER_TYPE_OFFSET);

            /*
             * RFC 5246 6. If a TLS implementation receives an unexpected record type, it MUST send an
             * unexpected_message alert.
             */
            CheckType(type, AlertDescription.unexpected_message);

            if (!mRestrictReadVersion)
            {
                int version = TlsUtilities.ReadVersionRaw(recordHeader, TLS_HEADER_VERSION_OFFSET);
                if ((version & 0xffffff00) != 0x0300)
                {
                    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
                }
            }
            else
            {
                ProtocolVersion version = TlsUtilities.ReadVersion(recordHeader, TLS_HEADER_VERSION_OFFSET);
                if (mReadVersion == null)
                {
                    mReadVersion = version;
                }
                else if (!version.Equals(mReadVersion))
                {
                    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
                }
            }

            int length = TlsUtilities.ReadUint16(recordHeader, TLS_HEADER_LENGTH_OFFSET);

            byte[] plaintext = DecodeAndVerify(type, mInput, length);
            mHandler.ProcessRecord(type, plaintext, 0, plaintext.Length);
            return(true);
        }
Exemple #4
0
    internal virtual bool ReadRecord()
    {
        byte[] array = TlsUtilities.ReadAllOrNothing(5, mInput);
        if (array == null)
        {
            return(false);
        }
        byte b = TlsUtilities.ReadUint8(array, 0);

        CheckType(b, 10);
        if (!mRestrictReadVersion)
        {
            int num = TlsUtilities.ReadVersionRaw(array, 1);
            if ((num & 4294967040u) != 768)
            {
                throw new TlsFatalAlert(47);
            }
        }
        else
        {
            ProtocolVersion protocolVersion = TlsUtilities.ReadVersion(array, 1);
            if (mReadVersion == null)
            {
                mReadVersion = protocolVersion;
            }
            else if (!protocolVersion.Equals(mReadVersion))
            {
                throw new TlsFatalAlert(47);
            }
        }
        int len = TlsUtilities.ReadUint16(array, 3);

        byte[] array2 = DecodeAndVerify(b, mInput, len);
        mHandler.ProcessRecord(b, array2, 0, array2.Length);
        return(true);
    }