private void m_pCreate_Click(object sender, EventArgs e) { this.m_pCertificate = CreateCertificateForm.CreateCertificate(this.m_pName.Text, ""); base.DialogResult = DialogResult.OK; }
private void m_pSslToolbar_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Name == null) { return; } if (e.ClickedItem.Name == "create") { CreateCertificateForm createCertificateForm = new CreateCertificateForm(this.m_pHostName.Text); if (createCertificateForm.ShowDialog(this) != DialogResult.OK) { return; } try { X509Certificate2 x509Certificate = new X509Certificate2(createCertificateForm.Certificate, "", X509KeyStorageFlags.Exportable); if (!x509Certificate.HasPrivateKey) { MessageBox.Show(this, "Certificate is not server certificate, private key is missing !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } this.m_pCert = x509Certificate; this.UpdateCertStatus(); return; } catch { MessageBox.Show(this, "Invalid or not supported certificate file !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } } if (e.ClickedItem.Name == "add") { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog(this) != DialogResult.OK) { return; } try { X509Certificate2 x509Certificate2 = new X509Certificate2(openFileDialog.FileName, "", X509KeyStorageFlags.Exportable); if (!x509Certificate2.HasPrivateKey) { MessageBox.Show(this, "Certificate is not server certificate, private key is missing !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } this.m_pCert = x509Certificate2; this.UpdateCertStatus(); return; } catch { MessageBox.Show(this, "Invalid or not supported certificate file !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } } if (e.ClickedItem.Name == "delete") { if (MessageBox.Show(this, "Are you sure you want to delete active SSL certificate ?", "Confirm delete:", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { this.m_pCert = null; this.UpdateCertStatus(); return; } } else if (e.ClickedItem.Name == "save") { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "*.pfx | *.p12"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { File.WriteAllBytes(saveFileDialog.FileName, this.m_pCert.Export(X509ContentType.Pfx)); } } }