Beispiel #1
0
    protected internal void ProcessRecord(byte protocol, byte[] buf, int offset, int len)
    {
        switch (protocol)
        {
        case 21:
            mAlertQueue.AddData(buf, offset, len);
            ProcessAlert();
            break;

        case 23:
            if (!mAppDataReady)
            {
                throw new TlsFatalAlert(10);
            }
            mApplicationDataQueue.AddData(buf, offset, len);
            ProcessApplicationData();
            break;

        case 20:
            ProcessChangeCipherSpec(buf, offset, len);
            break;

        case 22:
            mHandshakeQueue.AddData(buf, offset, len);
            ProcessHandshake();
            break;

        case 24:
            if (!mAppDataReady)
            {
                throw new TlsFatalAlert(10);
            }
            break;
        }
    }
Beispiel #2
0
        internal void ProcessData(
            ContentType protocol,
            byte[]          buf,
            int offset,
            int len)
        {
            /*
             * Have a look at the protocol type, and add it to the correct queue.
             */
            switch (protocol)
            {
            case ContentType.change_cipher_spec:
                changeCipherSpecQueue.AddData(buf, offset, len);
                ProcessChangeCipherSpec();
                break;

            case ContentType.alert:
                alertQueue.AddData(buf, offset, len);
                ProcessAlert();
                break;

            case ContentType.handshake:
                handshakeQueue.AddData(buf, offset, len);
                ProcessHandshake();
                break;

            case ContentType.application_data:
                if (!appDataReady)
                {
                    this.FailWithError(AlertLevel.fatal, AlertDescription.unexpected_message);
                }
                applicationDataQueue.AddData(buf, offset, len);
                ProcessApplicationData();
                break;

            default:
                /*
                 * Uh, we don't know this protocol.
                 *
                 * RFC2246 defines on page 13, that we should ignore this.
                 */
                break;
            }
        }
Beispiel #3
0
        public int Receive(byte[] buf, int off, int len, int waitMillis)
        {
            var endtime = DateTime.Now.AddMilliseconds(waitMillis);

            while (mRecordQueue.Available < len && endtime > DateTime.Now)
            {
                if (_udpclient.Available > 0)
                {
                    IPEndPoint ep   = null;
                    var        data = _udpclient.Receive(ref ep);

                    mRecordQueue.AddData(data, 0, data.Length);

                    break;
                }

                Thread.Yield();
            }

            len = Math.Min(mRecordQueue.Available, len);
            mRecordQueue.Read(buf, off, len, 0);
            mRecordQueue.RemoveData(len);
            return(len);
        }
Beispiel #4
0
 public virtual void Write(byte[] buf)
 {
     buffer.AddData(buf, 0, buf.Length);
 }