public string Request(string csr, string templateName = "WebServer", string additionalAttributes = "") { if (string.IsNullOrEmpty(Server)) { throw new Exceptions.CANotDefinedException(); } string attributes = string.Format("CertificateTemplate: {0}", templateName); if (!string.IsNullOrEmpty(additionalAttributes)) { attributes += "\n" + additionalAttributes; } CCertRequest objCertRequest = new CCertRequestClass(); // Submit request to CA Server; 0xff flags will accept and try any encoding type RequestDisposition requestResult = (RequestDisposition)objCertRequest.Submit(0xff, csr, attributes, Server); if (requestResult == RequestDisposition.CR_DISP_ISSUED) { // Retreive the new certificate return objCertRequest.GetCertificate(0); // Get the certificate in BASE64 with header. } throw new Exceptions.CANotIssuedException(requestResult); }
public ObservableCollection<Templates> GetCaTemplates(string caserver) { CCertRequest objCertRequest = new CCertRequestClass(); ObservableCollection<Templates> Templates = new ObservableCollection<Templates>(); Regex regex = new Regex(@"([A-Za-z]+)"); string value = objCertRequest.GetCAProperty(caserver, 29, 0, 4, 0).ToString(); string[] lines = Regex.Split(value, @"\n"); foreach (string line in lines) { Match match = regex.Match(line); if (match.Success) { Templates.Add(new Templates { Template = line }); } } return Templates; }
/// <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); } }
public string RetrieveCertStatus(int id, string caserver) { int strDisposition; string msg = ""; CCertRequest objCertRequest = new CCertRequestClass(); strDisposition = objCertRequest.RetrievePending(id, caserver); switch (strDisposition) { case (int)RequestDisposition.CR_DISP_INCOMPLETE: msg = "incomplete certificate"; break; case (int)RequestDisposition.CR_DISP_DENIED: msg = "request denied"; break; case (int)RequestDisposition.CR_DISP_ISSUED: msg = "certificate issued"; break; case (int)RequestDisposition.CR_DISP_UNDER_SUBMISSION: msg = "request pending"; break; case (int)RequestDisposition.CR_DISP_REVOKED: msg = "certificate revoked"; break; } return msg; }
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()); } } }