예제 #1
0
        static String getConfig(CertConfigOption option)
        {
            var certConfig = new CCertConfigClass();

            try {
                return(certConfig.GetConfig((Int32)option));
            } catch {
                return(null);
            } finally {
                Marshal.FinalReleaseComObject(certConfig);
            }
        }
        /// <summary>
        /// The send active directory certificate request.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string SendActiveDirectoryCertificateRequest(string request)
        {
            this.LastError.Clear();
            try
            {
                CCertConfig  objCertConfig  = new CCertConfigClass();                                                        // Create all the objects that will be required
                CCertRequest objCertRequest = new CCertRequestClass();
                var          strCaConfig    = objCertConfig.GetConfig(CcUipickconfig);                                       // strCAConfig = objCertConfig.GetConfig(CC_DEFAULTCONFIG); // Get CA config from UI
                var          result         = objCertRequest.Submit(CrInBase64 | CrInFormatany, request, null, strCaConfig); // Submit the request
                // Check the submission status
                if (result != CrDispIssued)
                {
                    // Not enrolled
                    var dispositionMessage = objCertRequest.GetDispositionMessage();
                    if (result == CrDispUnderSubmission)
                    {
                        // Pending
                        this.LastError.Add("The submission is pending: " + dispositionMessage);
                        return(string.Empty);
                    }
                    else
                    {
                        // Failed
                        this.LastError.Add("The submission failed: " + dispositionMessage);
                        this.LastError.Add("Last status: " + objCertRequest.GetLastStatus());
                        return(string.Empty);
                    }
                }

                var certificate = objCertRequest.GetCertificate(CrOutBase64 | CrOutChain); // Get the certificate
                return(certificate);
            }
            catch (Exception ex)
            {
                this.LastError.Add(ex.Message);
                return(string.Empty);
            }
        }
예제 #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());
                }
            }
        }