Пример #1
0
 public HttpConfigSslEntry(IPEndPoint endPoint, string sslHash, Guid appId, string sslCertStoreName, HTTP_SERVICE_CONFIG_SSL_CLIENT_CERT_CHECK defaultCertCheckMode, TimeSpan defaultRevocationFreshnessTime, TimeSpan defaultRevocationUrlRetrievalTimeout, string defaultSslCtlIdentifier, string defaultSslCtlStoreName, HTTP_SERVICE_CONFIG_SSL_FLAG defaultFlags)
 {
     this.appId = appId;
     this.defaultCertCheckMode                 = defaultCertCheckMode;
     this.defaultFlags                         = defaultFlags;
     this.defaultRevocationFreshnessTime       = defaultRevocationFreshnessTime;
     this.defaultRevocationUrlRetrievalTimeout = defaultRevocationUrlRetrievalTimeout;
     this.defaultSslCtlIdentifier              = defaultSslCtlIdentifier;
     this.defaultSslCtlStoreName               = defaultSslCtlStoreName;
     this.endPoint         = endPoint;
     this.sslCertStoreName = sslCertStoreName;
     this.sslHash          = HttpConfigSslEntry.CertHashFromString(sslHash);
 }
Пример #2
0
        public unsafe HttpConfigSslEntry(HttpApi.HTTP_SERVICE_CONFIG_SSL_KEY key, HttpApi.HTTP_SERVICE_CONFIG_SSL_PARAM param)
        {
            byte *        p  = (byte *)key.pIpPort;
            SocketAddress sa = new SocketAddress(0, 48);

            for (int i = 0; i < sa.Size; i++)
            {
                sa[i] = *(p++);
            }
            IPEndPoint ep;

            if (sa.Family == AddressFamily.InterNetwork)
            {
                ep = (IPEndPoint) new IPEndPoint(IPAddress.Any, 0).Create(sa);
            }
            else
            {
                ep = (IPEndPoint) new IPEndPoint(IPAddress.IPv6Any, 0).Create(sa);
            }
            this.endPoint = ep;
            if (param.SslHashLength > 0 && param.pSslHash != IntPtr.Zero)
            {
                this.sslHash = new byte[param.SslHashLength];
                Marshal.Copy(param.pSslHash, this.sslHash, 0, (int)param.SslHashLength);
            }
            this.appId = param.AppId;
            if (!string.IsNullOrEmpty(param.pSslCertStoreName))
            {
                this.sslCertStoreName = param.pSslCertStoreName;
            }
            else
            {
                this.sslCertStoreName = StoreName.My.ToString();
            }
            this.defaultCertCheckMode                 = param.DefaultCertCheckMode;
            this.defaultRevocationFreshnessTime       = TimeSpan.FromSeconds(param.DefaultRevocationFreshnessTime);
            this.defaultRevocationUrlRetrievalTimeout = TimeSpan.FromMilliseconds(param.DefaultRevocationUrlRetrievalTimeout);
            this.defaultSslCtlIdentifier              = param.pDefaultSslCtlIdentifier;
            this.defaultSslCtlStoreName               = param.pDefaultSslCtlStoreName;
            this.defaultFlags = param.DefaultFlags;
        }
Пример #3
0
        private void sslApply_Click(object sender, EventArgs e)
        {
            bool deleted = false;

            if (sslEditedEntry != null)
            {
                try
                {
                    sslEditedEntry.Delete();
                    deleted = true;
                }
                catch (Win32Exception exception)
                {
                    DialogResult result = MessageBox.Show("An error occurred while attempting to perform the requested change. The error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                    if (result == DialogResult.Abort)
                    {
                        Reload();
                    }
                    if (result != DialogResult.Ignore)
                    {
                        return;
                    }
                }
            }
            IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(this.sslAddress.Text), int.Parse(this.sslPort.Text));
            Guid       guid     = new Guid();

            try
            {
                guid = new Guid(this.sslAppId.Text);
            }
            catch (FormatException)
            {
            }
            HTTP_SERVICE_CONFIG_SSL_CLIENT_CERT_CHECK defaultCertCheckMode = 0;

            if (!this.sslCheckRevocation.Checked)
            {
                defaultCertCheckMode |= HTTP_SERVICE_CONFIG_SSL_CLIENT_CERT_CHECK.NoCheck;
            }
            if (this.sslCheckOnlyCached.Checked)
            {
                defaultCertCheckMode |= HTTP_SERVICE_CONFIG_SSL_CLIENT_CERT_CHECK.CachedOnly;
            }
            if (this.sslCheckFresh.Checked)
            {
                defaultCertCheckMode |= HTTP_SERVICE_CONFIG_SSL_CLIENT_CERT_CHECK.UseDefaultRevocationFreshnessTime;
            }
            if (this.sslCeckUsage.Checked)
            {
                defaultCertCheckMode |= HTTP_SERVICE_CONFIG_SSL_CLIENT_CERT_CHECK.NoUsage;
            }
            HTTP_SERVICE_CONFIG_SSL_FLAG defaultFlags = 0;

            if (this.sslNegotiateClientCert.Checked)
            {
                defaultFlags |= HTTP_SERVICE_CONFIG_SSL_FLAG.NegotiateClientCert;
            }
            if (this.sslRawFilter.Checked)
            {
                defaultFlags |= HTTP_SERVICE_CONFIG_SSL_FLAG.NoRawFilter;
            }
            if (this.sslUseDSMapper.Checked)
            {
                defaultFlags |= HTTP_SERVICE_CONFIG_SSL_FLAG.UseDsMapper;
            }
            double   time;
            TimeSpan sslFreshness = TimeSpan.Zero;

            if (double.TryParse(this.sslFreshness.Text, out time))
            {
                sslFreshness = TimeSpan.FromSeconds(time);
            }
            TimeSpan sslDownload = TimeSpan.Zero;

            if (double.TryParse(this.sslDownload.Text, out time))
            {
                sslDownload = TimeSpan.FromMilliseconds(time);
            }
            HttpConfigSslEntry entry = new HttpConfigSslEntry(endpoint, this.sslCertHash.Text, guid, this.sslCertStore.Text, defaultCertCheckMode, sslFreshness, sslDownload, null, null, defaultFlags);

            try
            {
                entry.Create();
            }
            catch (Win32Exception exception)
            {
                DialogResult result = MessageBox.Show("An error occurred while attempting to perform the requested change. The error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                if (result == DialogResult.Abort)
                {
                    Reload();
                }
                if (result != DialogResult.Ignore)
                {
                    return;
                }
                if (deleted && sslEditedEntry != null)
                {
                    try
                    {
                        sslEditedEntry.Create();
                    }
                    catch (Win32Exception)
                    {
                    }
                }
            }
            sslEditedEntry = null;
            Reload();
        }