Example #1
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);
            }
        }
Example #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 static string ToSerializedValue(this SslState value)
        {
            switch (value)
            {
            case SslState.Disabled:
                return("Disabled");

            case SslState.SniEnabled:
                return("SniEnabled");

            case SslState.IpBasedEnabled:
                return("IpBasedEnabled");
            }
            return(null);
        }
        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);
        }
 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);
         }
     }
 }
        public Site UpdateHostNameSslState(string resourceGroupName, string webAppName, string slotName, string location, string hostName, SslState sslState, string thumbPrint)
        {
            Site   updateWebSite;
            string qualifiedSiteName;

            var shouldUseDeploymentSlot = CmdletHelpers.ShouldUseDeploymentSlot(webAppName, slotName, out qualifiedSiteName);

            var webappWithNewSslBinding = new Site
            {
                HostNameSslStates = new List <HostNameSslState> {
                    new HostNameSslState
                    {
                        Name       = hostName,
                        Thumbprint = thumbPrint,
                        ToUpdate   = true,
                        SslState   = sslState
                    }
                },
                Location = location
            };

            if (shouldUseDeploymentSlot)
            {
                updateWebSite = WrappedWebsitesClient.WebApps().CreateOrUpdateSiteSlot(
                    resourceGroupName, webAppName, slot: slotName, siteEnvelope:
                    webappWithNewSslBinding);
            }
            else
            {
                updateWebSite = WrappedWebsitesClient.WebApps().CreateOrUpdateSite(
                    resourceGroupName, webAppName, siteEnvelope:
                    webappWithNewSslBinding);
            }
            return(updateWebSite);
        }
Example #7
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="SslState" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => SslState.CreateFrom(sourceValue);
 public static string ToSerialString(this SslState value) => value switch
 {
        public Site UpdateHostNameSslState(string resourceGroupName, string webAppName, string slotName, string location, string hostName, SslState sslState, string thumbPrint)
        {
            Site updateWebSite;
            string qualifiedSiteName;

            var shouldUseDeploymentSlot = CmdletHelpers.ShouldUseDeploymentSlot(webAppName, slotName, out qualifiedSiteName);

            var webappWithNewSslBinding = new Site
            {
                HostNameSslStates = new List<HostNameSslState>{new HostNameSslState
                {
                    Name = hostName,
                    Thumbprint = thumbPrint,
                    ToUpdate = true,
                    SslState = sslState
                }},
                Location = location
            };

            if (shouldUseDeploymentSlot)
            {
                updateWebSite = WrappedWebsitesClient.Sites.CreateOrUpdateSiteSlot(
                        resourceGroupName, webAppName, slot: slotName, siteEnvelope:
                        webappWithNewSslBinding);
            }
            else
            {
                updateWebSite = WrappedWebsitesClient.Sites.CreateOrUpdateSite(
                        resourceGroupName, webAppName, siteEnvelope:
                        webappWithNewSslBinding);
            }
            return updateWebSite;
        }