private void SelectAndIssueCertificateBTN_Click(object sender, EventArgs e)
{
try
{
const string caption = "Select Certificate to Issue";
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;
}
CertificateIdentifier newId = new CreateCertificateDlg().ShowDialog(m_currentStore, IssuerKeyFilePathTB.Text, certificate);
if (newId == null)
{
return;
}
X509Certificate2 newCertificate = id.Find();
MessageBox.Show(
this,
newCertificate.Subject + " issued.",
caption,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
// check if original certificate should be deleted.
if (new YesNoDlg().ShowDialog("Delete orginal certificate?", caption) == DialogResult.Yes)
{
ICertificateStore physicalStore = id.OpenStore();
try
{
physicalStore.Delete(certificate.Thumbprint);
}
finally
{
physicalStore.Close();
}
}
}
catch (Exception exception)
{
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}