public void CreateSigningRequest() { var dto = new CertRequestDTO(); CreateCertificateWindowController cwc = new CreateCertificateWindowController(dto); NSApplication.SharedApplication.BeginSheet(cwc.Window, VMCAAppEnvironment.Instance.MainWindow, () => { }); try { nint result = NSApplication.SharedApplication.RunModalForWindow(cwc.Window); if (result == (nint)Constants.DIALOGOK) { using (var request = new VMCARequest(this.ServerDTO.VMCAClient)) { dto.FillRequest(request); string csr = request.GetCSR(dto.PrivateKey.ToString()); this.ServerDTO.SigningRequests.Add(new SigningRequestDTO { CreatedDateTime = DateTime.UtcNow, CSR = csr }); GenericTextViewWindowController gwc = new GenericTextViewWindowController(csr); gwc.Window.Title = "CSR Data"; NSApplication.SharedApplication.RunModalForWindow(gwc.Window); NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this); } } } catch (Exception e) { UIErrorHelper.ShowAlert(e.Message, "Operation could not complete successfully."); } finally { VMCAAppEnvironment.Instance.MainWindow.EndSheet(cwc.Window); cwc.Dispose(); } }
public void CreateCASignedCertificate(object sender, EventArgs args) { var dto = new CertRequestDTO(); CreateCertificateWindowController cwc = new CreateCertificateWindowController(dto); NSApplication.SharedApplication.BeginSheet(cwc.Window, VMCAAppEnvironment.Instance.MainWindow, () => { }); try { nint result = NSApplication.SharedApplication.RunModalForWindow(cwc.Window); if (result == (nint)Constants.DIALOGOK) { using (var request = new VMCARequest(this.ServerDTO.VMCAClient)) { dto.FillRequest(request); var vmcaCert = ServerDTO.VMCAClient.GetVMCASignedCertificate(request.GetRequestData(), dto.PrivateKey.ToString(), dto.NotBefore, dto.NotAfter); var localCertDTO = new PrivateCertificateDTO { Certificate = Convert.ToBase64String(vmcaCert.RawData) }; UIErrorHelper.ShowAlert("", "Successfully Created A CA Signed Certificate"); this.ServerDTO.PrivateCertificates.Add(localCertDTO); NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this); CertificateService.DisplayX509Certificate2(this, vmcaCert); } } } catch (Exception e) { UIErrorHelper.ShowAlert(e.Message, "Operation could not complete successfully."); } finally { VMCAAppEnvironment.Instance.MainWindow.EndSheet(cwc.Window); cwc.Dispose(); } }
public static void CreateSigningRequest(VMCAServerDTO serverDTO) { MMCActionHelper.CheckedExec(delegate() { TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new EditorAttribute (typeof(PrivateKeyEditor), typeof(UITypeEditor))); TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new CategoryAttribute("Security")); var dto = new CertRequestDTO(); var frm = new GenericInputForm("Fill Signing Request", "Create", dto); frm.Icon = VMCASnapInEnvironment.Instance.GetIconResource(VMCAIconIndex.cert); frm.ApplyDelegate = MiscUtilsService.ApproveCertRequestHandler; if (MMCDlgHelper.ShowForm(frm)) { using (var request = new VMCARequest(serverDTO.VMCAClient)) { dto.FillRequest(request); string csr = request.GetCSR(dto.PrivateKey.ToString()); serverDTO.SigningRequests.Add(new SigningRequestDTO { CSR = csr, CreatedDateTime = DateTime.Now }); MMCDlgHelper.ShowMessage(csr); } } }); }
private bool CertRequest(Func <VMCARequest, CertRequestDTO, X509Certificate2> func, VMCAServerDTO serverDTO) { bool bResult = false; MMCActionHelper.CheckedExec(delegate() { TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new EditorAttribute (typeof(PrivateKeyEditor), typeof(UITypeEditor))); TypeDescriptor.AddAttributes(typeof(PrivateKeyDTO), new CategoryAttribute("Security")); var dto = new CertRequestDTO(); var frm = new GenericInputForm("Fill Certificate Request", "Create", dto); frm.Icon = VMCASnapInEnvironment.Instance.GetIconResource(VMCAIconIndex.cert); frm.ApplyDelegate = MiscUtilsService.ApproveCertRequestHandler; if (!MMCDlgHelper.ShowForm(frm)) { return; } var request = new VMCARequest(serverDTO.VMCAClient); dto.FillRequest(request); var cert = func(request, dto); X509Certificate2UI.DisplayCertificate(cert); var localCertDTO = new PrivateCertificateDTO { Certificate = Convert.ToBase64String(cert.RawData) }; serverDTO.PrivateCertificates.Add(localCertDTO); bResult = true; VMCASnapInEnvironment.Instance.SaveLocalData(); }); return(bResult); }
public void FillRequest(VMCARequest request) { request.Country = Country; request.DNSName = DNSName; request.Email = Email; request.IPAddress = IPAddress; request.KeyUsageConstraints = KeyUsageConstraints; request.Locality = Locality; request.Name = Name; request.Organization = Organization; request.OU = OU; request.State = State; request.URIName = URIName; }