private void TrustListBTN_Click(object sender, EventArgs e) { try { // determine default store. CertificateStoreIdentifier store = new CertificateStoreIdentifier(); if (m_trustList != null) { store.StoreType = m_trustList.StoreType; store.StorePath = m_trustList.StorePath; } else { store.StoreType = Utils.DefaultStoreType; store.StorePath = Utils.DefaultStorePath; } // select store. CertificateStoreIdentifier trustList = new CertificateStoreDlg().ShowDialog(store); if (trustList != null) { m_trustList = trustList; TrustListTB.Text = m_trustList.ToString(); } } catch (Exception exception) { GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// Updates the dialog with the configuration. /// </summary> private void Update(ManagedApplication application) { if (application == null) { application = new ManagedApplication(); } m_application = application; SetIsSdkApplication(application.IsSdkCompatible); ApplicationNameTB.Text = application.DisplayName; ExecutableFileTB.Text = application.ExecutablePath; ConfigurationFileTB.Text = application.ConfigurationPath; CertificateTB.Text = null; TrustListTB.Text = null; m_certificate = application.Certificate; m_trustList = application.TrustList; if (m_certificate != null) { X509Certificate2 certificate = m_certificate.Find(); if (certificate != null) { CertificateTB.Text = certificate.Subject; } else { CertificateTB.Text = m_certificate.ToString(); } } if (m_trustList != null) { TrustListTB.Text = m_trustList.ToString(); } }
public ContainerInfo(ContainerInfoType type, CertificateStoreIdentifier store) { Type = type; DisplayName = store.ToString(); Store = store; }
/// <summary> /// Validates a certificate and adds it to the trust list. /// </summary> private void ValidateAndImport(CertificateStoreIdentifier store, X509Certificate2 certificate) { if (store == null || certificate == null) { return; } // validate the certificate using the trust lists for the certificate tool. try { CertificateValidator validator = new CertificateValidator(); validator.Update(m_configuration); validator.Validate(certificate); } catch (ServiceResultException exception) { if (!HandleValidationError(certificate, exception)) { return; } } // confirm import. StringBuilder buffer = new StringBuilder(); buffer.Append("You are adding this certificate to a trust list that may be shared with other applications."); buffer.Append("\r\n"); buffer.Append("\r\n"); buffer.Append("Would you still like to accept the certificate?\r\n"); buffer.Append("\r\n"); buffer.Append("Target Trust List = "); buffer.Append(store.ToString()); buffer.Append("\r\n"); buffer.Append("Certificate to Add = "); buffer.Append(certificate.Subject); DialogResult result = new YesNoDlg().ShowDialog(buffer.ToString(), "Import Certificate to Trust List"); if (result != DialogResult.Yes) { return; } // update store. ICertificateStore physicalStore = store.OpenStore(); if (physicalStore.FindByThumbprint(certificate.Thumbprint) == null) { physicalStore.Add(new X509Certificate2(certificate.RawData)); } }