Beispiel #1
0
        private int StartFrameHeader(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            int readBytes = 0;

            //
            // Always pass InternalBuffer for SSPI "in place" decryption.
            // A user buffer can be shared by many threads in that case decryption/integrity check may fail cause of data corruption.
            //

            // Reset internal buffer for a new frame.
            EnsureInternalBufferSize(0, SecureChannel.ReadHeaderSize);

            if (asyncRequest != null)
            {
                asyncRequest.SetNextRequest(InternalBuffer, 0, SecureChannel.ReadHeaderSize, s_readHeaderCallback);
                FixedSizeReader.ReadPacketAsync(_sslState.InnerStream, asyncRequest);

                if (!asyncRequest.MustCompleteSynchronously)
                {
                    return(0);
                }

                readBytes = asyncRequest.Result;
            }
            else
            {
                readBytes = FixedSizeReader.ReadPacket(_sslState.InnerStream, InternalBuffer, 0, SecureChannel.ReadHeaderSize);
            }

            return(StartFrameBody(readBytes, buffer, offset, count, asyncRequest));
        }
Beispiel #2
0
 //
 //  The public Client and Server classes enforce the parameters rules before
 //  calling into this .ctor.
 //
 internal SslState(Stream innerStream, RemoteCertValidationCallback certValidationCallback, LocalCertSelectionCallback certSelectionCallback, EncryptionPolicy encryptionPolicy)
 {
     _innerStream = innerStream;
     _reader = new FixedSizeReader(innerStream);
     _certValidationDelegate = certValidationCallback;
     _certSelectionDelegate = certSelectionCallback;
     _encryptionPolicy = encryptionPolicy;
 }
Beispiel #3
0
 internal SslState(Stream innerStream, RemoteCertValidationCallback certValidationCallback, LocalCertSelectionCallback certSelectionCallback, EncryptionPolicy encryptionPolicy)
 {
     this._InnerStream            = innerStream;
     this._Reader                 = new FixedSizeReader(innerStream);
     this._CertValidationDelegate = certValidationCallback;
     this._CertSelectionDelegate  = certSelectionCallback;
     this._EncryptionPolicy       = encryptionPolicy;
 }
 internal _SslStream(SslState sslState)
 {
     if (PinnableBufferCacheEventSource.Log.IsEnabled())
     {
         PinnableBufferCacheEventSource.Log.DebugMessage1("CTOR: In System.Net._SslStream.SslStream", this.GetHashCode());
     }
     _SslState = sslState;
     _Reader = new FixedSizeReader(_SslState.InnerStream);
 }
Beispiel #5
0
 internal _SslStream(SslState sslState)
 {
     if (PinnableBufferCacheEventSource.Log.IsEnabled())
     {
         PinnableBufferCacheEventSource.Log.DebugMessage1("CTOR: In System.Net._SslStream.SslStream", this.GetHashCode());
     }
     _SslState = sslState;
     _Reader   = new FixedSizeReader(_SslState.InnerStream);
 }
        private int StartFrameBody(int readBytes, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            if (readBytes == 0)
            {
                //EOF
                asyncRequest?.CompleteUser(0);
                return(0);
            }

            if (!(readBytes == _ReadHeader.Length))
            {
                NetEventSource.Fail(this, $"Frame size must be 4 but received {readBytes} bytes.");
            }

            // Replace readBytes with the body size recovered from the header content.
            readBytes = _ReadHeader[3];
            readBytes = (readBytes << 8) | _ReadHeader[2];
            readBytes = (readBytes << 8) | _ReadHeader[1];
            readBytes = (readBytes << 8) | _ReadHeader[0];

            //
            // The body carries 4 bytes for trailer size slot plus trailer, hence <=4 frame size is always an error.
            // Additionally we'd like to restrict the read frame size to 64k.
            //
            if (readBytes <= 4 || readBytes > NegoState.MaxReadFrameSize)
            {
                throw new IOException(SR.net_frame_read_size);
            }

            //
            // Always pass InternalBuffer for SSPI "in place" decryption.
            // A user buffer can be shared by many threads in that case decryption/integrity check may fail cause of data corruption.
            //
            EnsureInternalBufferSize(readBytes);
            if (asyncRequest != null)
            {
                asyncRequest.SetNextRequest(InternalBuffer, 0, readBytes, s_readCallback);

                FixedSizeReader.ReadPacketAsync(InnerStream, asyncRequest);

                if (!asyncRequest.MustCompleteSynchronously)
                {
                    return(0);
                }

                readBytes = asyncRequest.Result;
            }
            else //Sync
            {
                readBytes = FixedSizeReader.ReadPacket(InnerStream, InternalBuffer, 0, readBytes);
            }

            return(ProcessFrameBody(readBytes, buffer, offset, count, asyncRequest));
        }
Beispiel #7
0
        public void Compress(string input, string output, int chunkSize)
        {
            var chunksPool = new DataChunksPool();

            using (var readStream = new FileStream(input, FileMode.Open))
                using (var writeStream = new FileStream(output, FileMode.Create))
                {
                    var reader = new FixedSizeReader(readStream, chunkSize, chunksPool.Get);
                    var writer = new OrderedWriter(writeStream, new CompressedFormatter(), 10, chunksPool.Return);

                    var worker = new Worker(reader, writer, new DataChunkCompressProcessor(chunksPool.Get), chunksPool.Return);
                    worker.Process();
                }
        }
Beispiel #8
0
        private int StartFrameBody(int readBytes, byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            if (readBytes == 0)
            {
                //EOF : Reset the buffer as we did not read anything into it.
                SkipBytes(InternalBufferCount);
                asyncRequest?.CompleteUser(0);

                return(0);
            }

            // Now readBytes is a payload size.
            readBytes = _sslState.GetRemainingFrameSize(InternalBuffer, readBytes);

            if (readBytes < 0)
            {
                throw new IOException(SR.net_frame_read_size);
            }

            EnsureInternalBufferSize(SecureChannel.ReadHeaderSize, readBytes);

            if (asyncRequest != null)
            {
                asyncRequest.SetNextRequest(InternalBuffer, SecureChannel.ReadHeaderSize, readBytes, s_readFrameCallback);

                FixedSizeReader.ReadPacketAsync(_sslState.InnerStream, asyncRequest);

                if (!asyncRequest.MustCompleteSynchronously)
                {
                    return(0);
                }

                readBytes = asyncRequest.Result;
            }
            else
            {
                readBytes = FixedSizeReader.ReadPacket(_sslState.InnerStream, InternalBuffer, SecureChannel.ReadHeaderSize, readBytes);
            }

            return(ProcessFrameBody(readBytes, buffer, offset, count, asyncRequest));
        }
        private int StartFrameHeader(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            int readBytes = 0;

            if (asyncRequest != null)
            {
                asyncRequest.SetNextRequest(_ReadHeader, 0, _ReadHeader.Length, s_readCallback);
                FixedSizeReader.ReadPacketAsync(InnerStream, asyncRequest);
                if (!asyncRequest.MustCompleteSynchronously)
                {
                    return(0);
                }

                readBytes = asyncRequest.Result;
            }
            else
            {
                readBytes = FixedSizeReader.ReadPacket(InnerStream, _ReadHeader, 0, _ReadHeader.Length);
            }

            return(StartFrameBody(readBytes, buffer, offset, count, asyncRequest));
        }
        //
        // Server side starts here, but client also loops through this method.
        //
        private void ReceiveBlob(byte[] buffer)
        {
            //This is first server read.
            buffer = EnsureBufferSize(buffer, 0, SecureChannel.ReadHeaderSize);

            int readBytes = FixedSizeReader.ReadPacket(_innerStream, buffer, 0, SecureChannel.ReadHeaderSize);

            if (readBytes == 0)
            {
                // EOF received
                throw new IOException(SR.net_auth_eof);
            }

            if (_framing == Framing.Unknown)
            {
                _framing = DetectFraming(buffer, readBytes);
            }

            int restBytes = GetRemainingFrameSize(buffer, 0, readBytes);

            if (restBytes < 0)
            {
                throw new IOException(SR.net_ssl_io_frame);
            }

            if (restBytes == 0)
            {
                // EOF received
                throw new AuthenticationException(SR.net_auth_eof, null);
            }

            buffer = EnsureBufferSize(buffer, readBytes, readBytes + restBytes);

            restBytes = FixedSizeReader.ReadPacket(_innerStream, buffer, readBytes, restBytes);

            SendBlob(buffer, readBytes + restBytes);
        }
Beispiel #11
0
 internal _SslStream(SslState sslState)
 {
     this._SslState = sslState;
     this._Reader   = new FixedSizeReader(this._SslState.InnerStream);
 }
Beispiel #12
0
        //
        // Private implemenation
        //

        private void InitializeStreamPart()
        {
            _ReadHeader  = new byte[4];
            _FrameReader = new FixedSizeReader(InnerStream);
        }
 internal _SslStream(SslState sslState)
 {
     _SslState = sslState;
     _Reader   = new FixedSizeReader(_SslState.InnerStream);
 }
Beispiel #14
0
 internal _SslStream(SslState sslState)
 {
     _SslState = sslState;
     _Reader = new FixedSizeReader(_SslState.InnerStream);
 }
 private void InitializeStreamPart()
 {
     _ReadHeader = new byte[4];
     _FrameReader = new FixedSizeReader(InnerStream);
 }
 private void InitializeStreamPart()
 {
     _ReadHeader     = new byte[4];
     _FrameReader    = new FixedSizeReader(InnerStream);
     _innerStreamAPM = new StreamAsyncHelper(InnerStream);
 }
 private void InitializeStreamPart()
 {
     _ReadHeader = new byte[4];
     _FrameReader = new FixedSizeReader(InnerStream);
     _innerStreamAPM = new StreamAsyncHelper(InnerStream);
 }
 private void InitializeStreamPart()
 {
     this._ReadHeader  = new byte[4];
     this._FrameReader = new FixedSizeReader(base.InnerStream);
 }