private void ImportCertificateListToTrustBTN_Click(object sender, EventArgs e)
{
try
{
const string caption = "Import Certificate List";
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;
}
CertificateStoreIdentifier store = new CertificateStoreDlg().ShowDialog(m_currentStore);
if (store == null)
{
return;
}
m_currentStore = store;
int count = 0;
ICertificateStore store1 = application.TrustList.OpenStore();
ICertificateStore store2 = store.OpenStore();
try
{
foreach (X509Certificate2 certificate in store2.Enumerate())
{
if (store1.FindByThumbprint(certificate.Thumbprint) == null)
{
store1.Add(certificate);
count++;
}
}
}
finally
{
store1.Close();
store2.Close();
}
MessageBox.Show(
this,
count.ToString() + " certificates added.",
caption,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception exception)
{
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}