Esempio n. 1
1
 public LazyAsyncResult(SslState sslState, object asyncState, AsyncCallback asyncCallback)
 {
     AsyncState = asyncState;
     asyncCallback?.Invoke(this);
 }
Esempio n. 2
0
        //
        // This version of an Ssl Stream is for internal HttpWebrequest use.
        // This Ssl client owns the underlined socket
        // The TlsStream will own secured read/write and disposal of the passed "networkStream" stream.
        //
        public TlsStream(string destinationHost, NetworkStream networkStream, X509CertificateCollection clientCertificates, ServicePoint servicePoint, object initiatingRequest, ExecutionContext executionContext)
               :base(networkStream, true) {

        // WebRequest manages the execution context manually so we have to ensure we get one for SSL client certificate demand
        _ExecutionContext = executionContext;
        if (_ExecutionContext == null)
        {
            _ExecutionContext = ExecutionContext.Capture();
        }

        // 


         GlobalLog.Enter("TlsStream::TlsStream", "host="+destinationHost+", #certs="+((clientCertificates == null) ? "none" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
         if (Logging.On) Logging.PrintInfo(Logging.Web, this, ".ctor", "host="+destinationHost+", #certs="+((clientCertificates == null) ? "null" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));

         m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
         m_Worker = new SslState(networkStream, initiatingRequest is HttpWebRequest, SettingsSectionInternal.Section.EncryptionPolicy);

         m_DestinationHost = destinationHost;
         m_ClientCertificates = clientCertificates;

         RemoteCertValidationCallback certValidationCallback = servicePoint.SetupHandshakeDoneProcedure(this, initiatingRequest);
         m_Worker.SetCertValidationDelegate(certValidationCallback);

         // The Handshake is NOT done at this point
         GlobalLog.Leave("TlsStream::TlsStream (Handshake is not done)");
        }
        internal SslStreamInternal(SslState sslState)
        {
            _sslState = sslState;

            _decryptedBytesOffset = 0;
            _decryptedBytesCount  = 0;
        }
Esempio n. 4
0
 private static void WriteCallback(IAsyncResult transportResult)
 {
     if (!transportResult.CompletedSynchronously)
     {
         AsyncProtocolRequest asyncState  = (AsyncProtocolRequest)transportResult.AsyncState;
         SslState             asyncObject = (SslState)asyncState.AsyncObject;
         try
         {
             asyncObject.InnerStream.EndWrite(transportResult);
             object    obj2      = asyncState.AsyncState;
             Exception exception = obj2 as Exception;
             if (exception != null)
             {
                 throw exception;
             }
             asyncObject.CheckCompletionBeforeNextReceive((ProtocolToken)obj2, asyncState);
         }
         catch (Exception exception2)
         {
             if (asyncState.IsUserCompleted)
             {
                 throw;
             }
             asyncObject.FinishHandshake(exception2, asyncState);
         }
     }
 }
Esempio n. 5
0
        internal SslStreamInternal(SslState sslState)
        {
            if (PinnableBufferCacheEventSource.Log.IsEnabled())
            {
                PinnableBufferCacheEventSource.Log.DebugMessage1("CTOR: In System.Net._SslStream.SslStream", this.GetHashCode());
            }

            _sslState = sslState;
        }
Esempio n. 6
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);
 }
Esempio n. 7
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);
 }
 public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy) : base(innerStream, leaveInnerStreamOpen)
 {
     if (((encryptionPolicy != EncryptionPolicy.RequireEncryption) && (encryptionPolicy != EncryptionPolicy.AllowNoEncryption)) && (encryptionPolicy != EncryptionPolicy.NoEncryption))
     {
         throw new ArgumentException(SR.GetString("net_invalid_enum", new object[] { "EncryptionPolicy" }), "encryptionPolicy");
     }
     this._userCertificateValidationCallback = userCertificateValidationCallback;
     this._userCertificateSelectionCallback = userCertificateSelectionCallback;
     RemoteCertValidationCallback certValidationCallback = new RemoteCertValidationCallback(this.userCertValidationCallbackWrapper);
     LocalCertSelectionCallback certSelectionCallback = (userCertificateSelectionCallback == null) ? null : new LocalCertSelectionCallback(this.userCertSelectionCallbackWrapper);
     this._SslState = new SslState(innerStream, certValidationCallback, certSelectionCallback, encryptionPolicy);
 }
Esempio n. 9
0
        static void HandshakeWriteCallback(IAsyncResult transportResult)
        {
            if (transportResult.CompletedSynchronously)
            {
                return;
            }

            HandshakeProtocolRequest asyncRequest = (HandshakeProtocolRequest)transportResult.AsyncState;

            SslState sslState = (SslState)asyncRequest.AsyncObject;

            sslState.SecureStream.HandshakeWriteCallback(asyncRequest, transportResult);
        }
        public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy) : base(innerStream, leaveInnerStreamOpen)
        {
            if (((encryptionPolicy != EncryptionPolicy.RequireEncryption) && (encryptionPolicy != EncryptionPolicy.AllowNoEncryption)) && (encryptionPolicy != EncryptionPolicy.NoEncryption))
            {
                throw new ArgumentException(SR.GetString("net_invalid_enum", new object[] { "EncryptionPolicy" }), "encryptionPolicy");
            }
            this._userCertificateValidationCallback = userCertificateValidationCallback;
            this._userCertificateSelectionCallback  = userCertificateSelectionCallback;
            RemoteCertValidationCallback certValidationCallback = new RemoteCertValidationCallback(this.userCertValidationCallbackWrapper);
            LocalCertSelectionCallback   certSelectionCallback  = (userCertificateSelectionCallback == null) ? null : new LocalCertSelectionCallback(this.userCertSelectionCallbackWrapper);

            this._SslState = new SslState(innerStream, certValidationCallback, certSelectionCallback, encryptionPolicy);
        }
Esempio n. 11
0
        public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback,
            LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
            : base(innerStream, leaveInnerStreamOpen)
        {
            if (encryptionPolicy != EncryptionPolicy.RequireEncryption && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
            {
                throw new ArgumentException(SR.Format(SR.net_invalid_enum, "EncryptionPolicy"), nameof(encryptionPolicy));
            }

            _userCertificateValidationCallback = userCertificateValidationCallback;
            _userCertificateSelectionCallback = userCertificateSelectionCallback;
            RemoteCertValidationCallback _userCertValidationCallbackWrapper = new RemoteCertValidationCallback(UserCertValidationCallbackWrapper);
            LocalCertSelectionCallback _userCertSelectionCallbackWrapper = userCertificateSelectionCallback == null ? null : new LocalCertSelectionCallback(UserCertSelectionCallbackWrapper);
            _sslState = new SslState(innerStream, _userCertValidationCallbackWrapper, _userCertSelectionCallbackWrapper, encryptionPolicy);
        }
Esempio n. 12
0
        public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback,
                         LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
            : base(innerStream, leaveInnerStreamOpen)
        {
            if (encryptionPolicy != EncryptionPolicy.RequireEncryption && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
            {
                throw new ArgumentException(SR.Format(SR.net_invalid_enum, "EncryptionPolicy"), nameof(encryptionPolicy));
            }

            _userCertificateValidationCallback = userCertificateValidationCallback;
            _userCertificateSelectionCallback  = userCertificateSelectionCallback;
            _encryptionPolicy       = encryptionPolicy;
            _certValidationDelegate = new RemoteCertValidationCallback(UserCertValidationCallbackWrapper);
            _certSelectionDelegate  = userCertificateSelectionCallback == null ? null : new LocalCertSelectionCallback(UserCertSelectionCallbackWrapper);
            _sslState = new SslState(innerStream);
        }
Esempio n. 13
0
		internal SslStream (Stream innerStream, bool leaveInnerStreamOpen, EncryptionPolicy encryptionPolicy, MonoTlsProvider provider, MonoTlsSettings settings)
			: base (innerStream, leaveInnerStreamOpen)
		{
			if (encryptionPolicy != EncryptionPolicy.RequireEncryption && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
				throw new ArgumentException (SR.GetString (SR.net_invalid_enum, "EncryptionPolicy"), "encryptionPolicy");

			var validationHelper = MNS.ChainValidationHelper.CloneWithCallbackWrapper (provider, ref settings, myUserCertValidationCallbackWrapper);

			LocalCertSelectionCallback selectionCallback = null;
			if (validationHelper.HasCertificateSelectionCallback)
				selectionCallback = validationHelper.SelectClientCertificate;

			var internalProvider = new MNS.Private.MonoTlsProviderWrapper (provider);
			_Configuration = new MyConfiguration (internalProvider, settings, this);
			_SslState = new SslState (innerStream, null, selectionCallback, encryptionPolicy, _Configuration);
		}
Esempio n. 14
0
        public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback,
                         LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
            : base(innerStream, leaveInnerStreamOpen)
        {
            if (encryptionPolicy != EncryptionPolicy.RequireEncryption && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
            {
                throw new ArgumentException(SR.GetString(SR.net_invalid_enum, "EncryptionPolicy"), "encryptionPolicy");
            }

            _userCertificateValidationCallback = userCertificateValidationCallback;
            _userCertificateSelectionCallback  = userCertificateSelectionCallback;
            RemoteCertValidationCallback _userCertValidationCallbackWrapper = new RemoteCertValidationCallback(userCertValidationCallbackWrapper);
            LocalCertSelectionCallback   _userCertSelectionCallbackWrapper  = userCertificateSelectionCallback == null  ? null : new LocalCertSelectionCallback(userCertSelectionCallbackWrapper);

            _SslState = new SslState(innerStream, _userCertValidationCallbackWrapper, _userCertSelectionCallbackWrapper, encryptionPolicy);
        }
Esempio n. 15
0
        private static void PartialFrameCallback(AsyncProtocolRequest asyncRequest)
        {
            SslState asyncObject = (SslState)asyncRequest.AsyncObject;

            try
            {
                asyncObject.StartReadFrame(asyncRequest.Buffer, asyncRequest.Result, asyncRequest);
            }
            catch (Exception exception)
            {
                if (asyncRequest.IsUserCompleted)
                {
                    throw;
                }
                asyncObject.FinishHandshake(exception, asyncRequest);
            }
        }
Esempio n. 16
0
		internal SslStream (Stream innerStream, bool leaveInnerStreamOpen, EncryptionPolicy encryptionPolicy, MonoTlsSettings settings)
			: base (innerStream, leaveInnerStreamOpen)
		{
#if MARTIN_FIXME
			if (encryptionPolicy != EncryptionPolicy.RequireEncryption && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
				throw new ArgumentException (SR.GetString (SR.net_invalid_enum, "EncryptionPolicy"), "encryptionPolicy");

			var validationHelper = ChainValidationHelper.CloneWithCallbackWrapper (ref settings, myUserCertValidationCallbackWrapper);

			LocalCertSelectionCallback selectionCallback = null;
			if (validationHelper.HasCertificateSelectionCallback)
				selectionCallback = validationHelper.SelectClientCertificate;

			_Configuration = new MyConfiguration (settings, this);
			_SslState = new SslState (innerStream, null, selectionCallback, encryptionPolicy, _Configuration);
#else
			throw new NotImplementedException ();
#endif
		}
 public TlsStream(string destinationHost, NetworkStream networkStream, X509CertificateCollection clientCertificates, ServicePoint servicePoint, object initiatingRequest, ExecutionContext executionContext) : base(networkStream, true)
 {
     this.m_PendingIO = new ArrayList();
     this._ExecutionContext = executionContext;
     if (this._ExecutionContext == null)
     {
         this._ExecutionContext = ExecutionContext.Capture();
     }
     if (Logging.On)
     {
         Logging.PrintInfo(Logging.Web, this, ".ctor", "host=" + destinationHost + ", #certs=" + ((clientCertificates == null) ? "null" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
     }
     this.m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
     this.m_Worker = new SslState(networkStream, initiatingRequest is HttpWebRequest, SettingsSectionInternal.Section.EncryptionPolicy);
     this.m_DestinationHost = destinationHost;
     this.m_ClientCertificates = clientCertificates;
     RemoteCertValidationCallback certValidationCallback = servicePoint.SetupHandshakeDoneProcedure(this, initiatingRequest);
     this.m_Worker.SetCertValidationDelegate(certValidationCallback);
 }
Esempio n. 18
0
        internal SslStream(Stream innerStream, bool leaveInnerStreamOpen, EncryptionPolicy encryptionPolicy, MonoTlsSettings settings)
            : base(innerStream, leaveInnerStreamOpen)
        {
            if (encryptionPolicy != EncryptionPolicy.RequireEncryption && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
            {
                throw new ArgumentException(SR.GetString(SR.net_invalid_enum, "EncryptionPolicy"), "encryptionPolicy");
            }

            var validationHelper = ChainValidationHelper.CloneWithCallbackWrapper(ref settings, myUserCertValidationCallbackWrapper);

            LocalCertSelectionCallback selectionCallback = null;

            if (validationHelper.HasCertificateSelectionCallback)
            {
                selectionCallback = validationHelper.SelectClientCertificate;
            }

            _Configuration = new MyConfiguration(settings, this);
            _SslState      = new SslState(innerStream, null, selectionCallback, encryptionPolicy, _Configuration);
        }
Esempio n. 19
0
        private static void ReadFrameCallback(AsyncProtocolRequest asyncRequest)
        {
            SslState asyncObject = (SslState)asyncRequest.AsyncObject;

            try
            {
                if (asyncRequest.Result == 0)
                {
                    asyncRequest.Offset = 0;
                }
                asyncObject.ProcessReceivedBlob(asyncRequest.Buffer, asyncRequest.Offset + asyncRequest.Result, asyncRequest);
            }
            catch (Exception exception)
            {
                if (asyncRequest.IsUserCompleted)
                {
                    throw;
                }
                asyncObject.FinishHandshake(exception, asyncRequest);
            }
        }
 internal _SslStream(SslState sslState)
 {
     this._SslState = sslState;
     this._Reader = new FixedSizeReader(this._SslState.InnerStream);
 }
Esempio n. 21
0
 public LazyAsyncResult(SslState sslState, object asyncState, AsyncCallback asyncCallback)
 {
 }
Esempio n. 22
0
 public LazyAsyncResult(SslState sslState, object asyncState, AsyncCallback asyncCallback)
 {
 }
Esempio n. 23
0
 internal ShutdownAsyncResult(SslState instance, object userState, AsyncCallback callback)
     : base(instance, userState, callback)
 {
 }
 internal _SslStream(SslState sslState)
 {
     _SslState = sslState;
     _Reader   = new FixedSizeReader(_SslState.InnerStream);
 }
 public SslReadAsync(SslState sslState, CancellationToken cancellationToken)
 {
     _cancellationToken = cancellationToken;
     _sslState          = sslState;
 }
 public SslReadSync(SslState sslState) => _sslState = sslState;
 protected override void Dispose(bool disposing)
 {
     if (Interlocked.Exchange(ref this.m_ShutDown, 1) != 1)
     {
         try
         {
             if (disposing)
             {
                 this.m_CachedChannelBinding = this.GetChannelBinding(ChannelBindingKind.Endpoint);
                 this.m_Worker.Close();
             }
             else
             {
                 this.m_Worker = null;
             }
         }
         finally
         {
             base.Dispose(disposing);
         }
     }
 }
Esempio n. 28
0
        protected override void Dispose(bool disposing) {
            GlobalLog.Print("TlsStream::Dispose()");
            if ( Interlocked.Exchange( ref m_ShutDown,  1) == 1 ) {
                return;
            }
            try {
                if (disposing) {
                    // When KeepAlive is turned off, the TlsStream will be closed before the auth headers for the next request
                    // are computed.  We cannot retrieve the ChannelBinding from the TlsStream after closing it, so we need to
                    // cache it now.
                    m_CachedChannelBinding = GetChannelBinding(ChannelBindingKind.Endpoint);

                    // Note this will not close the underlined socket, only security context
                    m_Worker.Close();
                }
                else {
                    m_Worker = null;
                }
            }
            finally {
                //This will close the underlined socket
                base.Dispose(disposing);
            }
        }
Esempio n. 29
0
			internal ShutdownAsyncResult (SslState instance, object userState, AsyncCallback callback)
				: base (instance, userState, callback)
			{
			}
Esempio n. 30
0
 public LazyAsyncResult(SslState sslState, object asyncState, AsyncCallback asyncCallback)
 {
     AsyncState = asyncState;
     asyncCallback?.Invoke(this);
 }
 public SslWriteAsync(SslState sslState, CancellationToken cancellationToken)
 {
     _sslState = sslState;
     _cancellationToken = cancellationToken;
 }
Esempio n. 32
0
 internal _SslStream(SslState sslState)
 {
     _SslState = sslState;
     _Reader = new FixedSizeReader(_SslState.InnerStream);
 }
 public SslWriteSync(SslState sslState) => _sslState = sslState;
Esempio n. 34
0
 internal _SslStream(SslState sslState)
 {
     this._SslState = sslState;
     this._Reader   = new FixedSizeReader(this._SslState.InnerStream);
 }