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); }