예제 #1
0
파일: MainForm.cs 프로젝트: tyranid/canape
 private void makeNewRootCertToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (CreateCertForm frm = new CreateCertForm(true))
     {
         if (frm.ShowDialog(this) == DialogResult.OK)
         {
             try
             {
                 if (MessageBox.Show(this, Properties.Resources.MainForm_ReplaceRootCA, Properties.Resources.MessageBiox_WarningString,
                                     MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                 {
                     CertManager.SetRootCert(frm.Certificate);
                 }
             }
             catch (IOException ex)
             {
                 MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (CryptographicException ex)
             {
                 MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (ArgumentException ex)
             {
                 MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
예제 #2
0
파일: MainForm.cs 프로젝트: tyranid/canape
        private void createNewCertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (CreateCertForm frm = new CreateCertForm())
            {
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        using (SaveFileDialog dlg = new SaveFileDialog())
                        {
                            dlg.Filter = Properties.Resources.CreateCert_SaveFilter;

                            if (dlg.ShowDialog(this) == DialogResult.OK)
                            {
                                GetPasswordForm getPass  = new GetPasswordForm();
                                SecureString    password = null;

                                if (getPass.ShowDialog(this) == DialogResult.OK)
                                {
                                    password = getPass.Password;
                                    if (password.Length == 0)
                                    {
                                        password = null;
                                    }
                                }

                                string ext = Path.GetExtension(dlg.FileName);

                                if (ext.Equals(".pfx") || ext.Equals(".p12"))
                                {
                                    File.WriteAllBytes(dlg.FileName, frm.Certificate.Export(X509ContentType.Pfx, password));
                                }
                                else
                                {
                                    File.WriteAllText(dlg.FileName, CertificateUtils.ExportToPEM(frm.Certificate) +
                                                      CertificateUtils.ExportToPEM((RSA)frm.Certificate.PrivateKey, password));
                                }
                            }
                        }
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (CryptographicException ex)
                    {
                        MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (ArgumentException ex)
                    {
                        MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
예제 #3
0
        private X509Certificate2 CreateCert()
        {
            X509Certificate2 ret = null;
            using (CreateCertForm frm = new CreateCertForm())
            {
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    ret = frm.Certificate;
                }
            }

            return ret;
        }
예제 #4
0
파일: MainForm.cs 프로젝트: michyer/canape
 private void makeNewRootCertToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (CreateCertForm frm = new CreateCertForm(true))
     {
         if (frm.ShowDialog(this) == DialogResult.OK)
         {
             try
             {
                 if (MessageBox.Show(this, Properties.Resources.MainForm_ReplaceRootCA, Properties.Resources.MessageBiox_WarningString,
                     MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                 {
                     CertManager.SetRootCert(frm.Certificate);
                 }
             }
             catch (IOException ex)
             {
                 MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (CryptographicException ex)
             {
                 MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (ArgumentException ex)
             {
                 MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
예제 #5
0
파일: MainForm.cs 프로젝트: michyer/canape
        private void createNewCertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (CreateCertForm frm = new CreateCertForm())
            {
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        using (SaveFileDialog dlg = new SaveFileDialog())
                        {
                            dlg.Filter = Properties.Resources.CreateCert_SaveFilter;

                            if (dlg.ShowDialog(this) == DialogResult.OK)
                            {
                                GetPasswordForm getPass = new GetPasswordForm();
                                SecureString password = null;

                                if (getPass.ShowDialog(this) == DialogResult.OK)
                                {
                                    password = getPass.Password;
                                    if (password.Length == 0)
                                    {
                                        password = null;
                                    }
                                }

                                string ext = Path.GetExtension(dlg.FileName);

                                if (ext.Equals(".pfx") || ext.Equals(".p12"))
                                {
                                    File.WriteAllBytes(dlg.FileName, frm.Certificate.Export(X509ContentType.Pfx, password));
                                }
                                else
                                {
                                    File.WriteAllText(dlg.FileName, CertificateUtils.ExportToPEM(frm.Certificate) +
                                                CertificateUtils.ExportToPEM((RSA)frm.Certificate.PrivateKey, password));
                                }
                            }
                        }
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (CryptographicException ex)
                    {
                        MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (ArgumentException ex)
                    {
                        MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }