private void SelectCertificateToTrustBTN_Click(object sender, EventArgs e)
{
try
{
const string caption = "Select Certificate to Trust";
ManagedApplication application = ManageApplicationSecurityCTRL.GetSelectedApplication();
if (application == null)
{
return;
}
if (application.TrustList == null)
{
MessageBox.Show(application.ToString() + " does not have a trust list defined.", caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (m_currentStore == null)
{
m_currentStore = new CertificateStoreIdentifier();
m_currentStore.StoreType = Utils.DefaultStoreType;
m_currentStore.StorePath = Utils.DefaultStorePath;
}
CertificateIdentifier id = new CertificateListDlg().ShowDialog(m_currentStore, true);
if (id == null)
{
return;
}
m_currentStore.StoreType = id.StoreType;
m_currentStore.StorePath = id.StorePath;
X509Certificate2 certificate = id.Find();
if (certificate == null)
{
return;
}
ICertificateStore store = application.TrustList.OpenStore();
try
{
if (store.FindByThumbprint(certificate.Thumbprint) == null)
{
store.Add(new X509Certificate2(certificate.RawData));
}
}
finally
{
store.Close();
}
MessageBox.Show(
this,
certificate.Subject + " now trusted.",
caption,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception exception)
{
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}