void DoWork() { try { //var certificateGenerator = new X509V3CertificateGenerator(); // Step 1 if (nameFrm1.GetNames()) { X509Name subject = new X509Name(); // TODO FIX NAME FRM int progress = 0; int cur = 0; foreach (KeyValuePair <string, string> keyp in nameFrm1.bind.Vals) { progress = (int)((double)((cur / nameFrm1.bind.Vals.Count) * 100)); backgroundWorker1.ReportProgress(progress, 1); subject.AddEntryByName(keyp.Key.ToUpper(), keyp.Value); cur++; } backgroundWorker1.ReportProgress(100, 1); // Step 2 progress = 0; cur = 0; if (keyGenerationFrm1.GenerateKey()) { Al.Security.CA.KeyGenerationBind keyb = keyGenerationFrm1.bind; CryptoKey KeyPair = keyb.KeyPair; CSReq = new X509Request(2, subject, KeyPair); // CUSTOM SERIAL NUMBER SimpleSerialNumber serial = null; if (keyGenerationFrm1.serialnumber.Value != null && keyGenerationFrm1.serialnumber.Value != 0) { serial = new SimpleSerialNumber(keyGenerationFrm1.serialnumber.Value); } backgroundWorker1.ReportProgress(100, 2); // STEP 3 if (!configbox.Checked) { ExtensionsWork(); } Configuration config = new Configuration(Application.StartupPath + @"\ext.cfg"); backgroundWorker1.ReportProgress(100, 3); DateTime notbe = nameFrm1.notbefore.Value; DateTime vali = nameFrm1.notafter.Value; // STEP 4 SAVE //generate SimpleSerialNumber caserial = new SimpleSerialNumber(PFX.Certificate.SerialNumber); X509CertificateAuthority ca = new X509CertificateAuthority(PFX.Certificate, PFX.PrivateKey, caserial, config); X509Certificate signedCert = null; if (serial != null) { signedCert = ca.ProcessRequest(serial, config, CSReq, DateTime.UtcNow, vali, keyb.SignatureAlgorithm); } else { signedCert = ca.ProcessRequest(config, CSReq, DateTime.UtcNow, vali, keyb.SignatureAlgorithm); } // CertExportFrm cfrm = new CertExportFrm(); cfrm.certificate = signedCert; cfrm.Key = KeyPair; // cfrm.ShowDialog(); backgroundWorker1.ReportProgress(100, 4); } else { SelectTab(superTabItem5); } } else { SelectTab(superTabItem4); } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
void DoWork() { try { // Step 1 if (nameFrm1.GetNames()) { X509Name subject = new X509Name(); // TODO FIX NAME FRM int progress = 0; int cur = 0; foreach (KeyValuePair <string, string> keyp in nameFrm1.bind.Vals) { progress = (int)((double)((cur / nameFrm1.bind.Vals.Count) * 100)); backgroundWorker1.ReportProgress(progress, 1); subject.AddEntryByName(keyp.Key.ToUpper(), keyp.Value); cur++; } backgroundWorker1.ReportProgress(100, 1); // Step 2 progress = 0; cur = 0; if (keyGenerationFrm1.GenerateKey()) { Al.Security.CA.KeyGenerationBind keyb = keyGenerationFrm1.bind; CryptoKey KeyPair = keyb.KeyPair; // var serialNumber = //BigIntegers.CreateRandomInRange( // BigInteger.One, BigInteger.ValueOf(Int64.MaxValue), keyb.SRandom); // CUTOM SERIAL SimpleSerialNumber serial = null; int serialn = 0; if (keyGenerationFrm1.serialnumber.Value != null && keyGenerationFrm1.serialnumber.Value != 0) { serial = new SimpleSerialNumber(keyGenerationFrm1.serialnumber.Value); } backgroundWorker1.ReportProgress(100, 2); // STEP 3 if (!configbox.Checked) { ExtensionsWork(); } Configuration config = new Configuration(Application.StartupPath + @"\ext.cfg"); backgroundWorker1.ReportProgress(100, 3); DateTime notbe = nameFrm1.notbefore.Value; TimeSpan vali = nameFrm1.notafter.Value.Subtract(notbe); // STEP 4 SAVE X509CertificateAuthority ca = null; if (serial != null) { ca = X509CertificateAuthority.SelfSigned(config, serial, KeyPair, keyb.SignatureAlgorithm, subject, notbe, vali); } else { ca = X509CertificateAuthority.SelfSigned(config, new SimpleSerialNumber(), KeyPair, keyb.SignatureAlgorithm, subject, notbe, vali); } // cfrm = new CertExportFrm(); cfrm.certificate = ca.Certificate; cfrm.Key = KeyPair; backgroundWorker1.ReportProgress(100, 4); } else { SelectTab(superTabItem5); } } else { SelectTab(superTabItem4); } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }