Ejemplo n.º 1
0
        /// <inheritdoc cref="ICertConfigD.FindConfigEntryByCertificateName"/>
        public static ICertConfigEntryD FindConfigEntryByCertificateName(String caName)
        {
            var certConfig = new CCertConfigClass();

            while (certConfig.Next() >= 0)
            {
                try {
                    if (certConfig.GetField("CommonName").Equals(caName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        var entry = new CertConfigEntryD(certConfig);
                        Marshal.FinalReleaseComObject(certConfig);
                        return(entry);
                    }
                } catch { }
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <inheritdoc cref="ICertConfigD.FindConfigEntryByServerName"/>
        public static ICertConfigEntryD FindConfigEntryByServerName(String computerName)
        {
            var certConfig = new CCertConfigClass();

            while (certConfig.Next() >= 0)
            {
                try {
                    if (certConfig.GetField("Server").Equals(computerName, StringComparison.OrdinalIgnoreCase))
                    {
                        var entry = new CertConfigEntryD(certConfig);
                        Marshal.FinalReleaseComObject(certConfig);
                        return(entry);
                    }
                } catch { }
            }
            return(null);
        }
Ejemplo n.º 3
0
        private void btn_SelectCA_Click(object sender, RoutedEventArgs e)
        {
            CCertConfig objCertConfig = new CCertConfigClass();
            CCertRequest objCertRequest = new CCertRequestClass();

            try
            {
                // Get CA config from UI
                string strCAConfig = objCertConfig.GetConfig(CC_UIPICKCONFIG);

                if(String.IsNullOrWhiteSpace(strCAConfig))
                {
                    return;
                }

            // Get CA Connection string
            string CACon = objCertConfig.GetField("Config");
            txt_CAServer.Text = CACon;

            // Get CA Type
            string caType = objCertRequest.GetCAProperty(strCAConfig, 10, 0, 1, 0).ToString();
            string caTypeTXT = "";
            switch (caType)
            {
                case "0":
                    caTypeTXT = "ENTERPRISE ROOT CA";
                    break;
                case "1":
                    caTypeTXT = "ENTERPRISE SUB CA";
                    break;
                case "3":
                    caTypeTXT = "STANDALONE ROOT CA";
                    break;
                case "4":
                    caTypeTXT = "STANDALONE SUB CA";
                    break;
            }
            txt_CaType.Text = caTypeTXT;

            if (caType == "3" || caType == "4" || caType == "5")
            {
                cmb_Templates.Visibility = System.Windows.Visibility.Hidden;
                btn_LoadTempls.Visibility = System.Windows.Visibility.Hidden;
                oids.Visibility = System.Windows.Visibility.Visible;
                txt_oid.Visibility = System.Windows.Visibility.Visible;
                oids.ItemsSource = Certificat.ListOids();

                strength.Visibility = System.Windows.Visibility.Visible;
            }
            else if (caType == "0" || caType == "1")
            {
                cmb_Templates.Visibility = System.Windows.Visibility.Visible;
                oids.Visibility = System.Windows.Visibility.Hidden;
                txt_oid.Visibility = System.Windows.Visibility.Hidden;
                btn_LoadTempls.Visibility = System.Windows.Visibility.Visible;
                cmb_Templates.ItemsSource = templates.GetCaTemplates(strCAConfig);
                strength.Visibility = System.Windows.Visibility.Visible;
            }

            }
            catch(Exception ex)
            {

                //Check if the user closed the dialog. Do nothing.
                if (ex.HResult.ToString() == "-2147023673")
                {
                    //MessageBox.Show("Closed By user");
                }
                    //Check if there is no available CA Servers.
                else if (ex.HResult.ToString() == "-2147024637")
                {
                    MessageBox.Show("Can't find available Servers");
                }
                    // If unknown error occurs.
                else
                {
                    MessageBox.Show(ex.Message + " " + ex.HResult.ToString());
                }
            }
        }