Exemplo n.º 1
0
        private void createServerCertifiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateServerDialog dialog = new CreateServerDialog();

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Title = "Save Server Certificate";
            saveDialog.CheckPathExists = true;
            saveDialog.Filter = Files.CertificateFileFilter;

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
              ServerCertificate certificate = new ServerCertificate(dialog.FullName);
              certificate.CreateSelfSignature();

              SignatureRequest request = new SignatureRequest(dialog.FullName, string.Empty, string.Empty);
              Secure<SignatureRequest> signedRequest = new Secure<SignatureRequest>(request, CaCertificate, certificate);

              CertificateAuthorityEntry entry = new CertificateAuthorityEntry(signedRequest);
              entry.Sign(CaCertificate, DateTime.Now, dialog.ValidUntil);
              certificate.AddSignature(entry.Response.Value.Signature);

              string entryFileName = DataPath(entry.Certificate.Id.ToString() + ".pi-ca-entry");
              entry.Save(DataPath(entryFileName));

              ListEntry listEntry = new ListEntry(entryFileName, entry, CaCertificate);
              Entries.Add(listEntry);
              this.entryListView.Items.Add(listEntry.CreateItem(CaCertificate));

              certificate.Save(saveDialog.FileName);
            }
              }
        }
Exemplo n.º 2
0
        private void importRequestsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
              dialog.Title = "Open Signature Requests";
              dialog.CheckPathExists = true;
              dialog.CheckFileExists = true;
              dialog.Multiselect = true;
              dialog.Filter = Files.SignatureRequestFileFilter;

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            List<string> alreadyAddedList = new List<string>();
            List<string> invalidList = new List<string>();

            foreach (string fileName in dialog.FileNames)
            {
              Secure<SignatureRequest> secureSignatureRequest = Serializable.Load<Secure<SignatureRequest>>(fileName);

              if (secureSignatureRequest.VerifySimple())
              {
            if (Entries.Any(listEntry => listEntry.Certificate.Id == secureSignatureRequest.Certificate.Id))
            {
              alreadyAddedList.Add(fileName);
            }
            else
            {
              CertificateAuthorityEntry entry = new CertificateAuthorityEntry(secureSignatureRequest);
              string entryFileName = DataPath(entry.Certificate.Id.ToString() + ".pi-ca-entry");
              entry.Save(DataPath(entryFileName));

              ListEntry listEntry = new ListEntry(entryFileName, entry, CaCertificate);
              Entries.Add(listEntry);
              this.entryListView.Items.Add(listEntry.CreateItem(CaCertificate));
            }
              }
              else
              {
            invalidList.Add(fileName);
              }
            }

            if (invalidList.Count > 0)
            {
              StringBuilder message = new StringBuilder();
              message.AppendLine("The following request are not valid:");
              invalidList.ForEach(invalidRequest => message.AppendLine(invalidRequest));
              MessageForm.Show(message.ToString(), "Pi-Vote CA GUI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (alreadyAddedList.Count > 0)
            {
              StringBuilder message = new StringBuilder();
              message.AppendLine("The following request are already in your list:");
              alreadyAddedList.ForEach(invalidRequest => message.AppendLine(invalidRequest));
              MessageForm.Show(message.ToString(), "Pi-Vote CA GUI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
              }
        }
Exemplo n.º 3
0
        private void createAdminCertificateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateAdminDialog dialog = new CreateAdminDialog();

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Title = "Save Admin Certificate";
            saveDialog.CheckPathExists = true;
            saveDialog.Filter = Files.CertificateFileFilter;

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
              string fullName = string.Format("{0} {1}, {2}", dialog.FirstName, dialog.FamilyName, dialog.Function);
              AdminCertificate certificate = new AdminCertificate(Language.English, dialog.Passphrase, fullName);
              certificate.CreateSelfSignature();

              SignatureRequest request = new SignatureRequest(dialog.FirstName, dialog.FamilyName, dialog.EmailAddress);
              Secure<SignatureRequest> signedRequest = new Secure<SignatureRequest>(request, CaCertificate, certificate);

              CertificateAuthorityEntry entry = new CertificateAuthorityEntry(signedRequest);
              entry.Sign(CaCertificate, DateTime.Now, dialog.ValidUntil);
              certificate.AddSignature(entry.Response.Value.Signature);

              string entryFileName = DataPath(entry.Certificate.Id.ToString() + ".pi-ca-entry");
              entry.Save(DataPath(entryFileName));

              ListEntry listEntry = new ListEntry(entryFileName, entry, CaCertificate);
              Entries.Add(listEntry);
              this.entryListView.Items.Add(listEntry.CreateItem(CaCertificate));

              certificate.Save(saveDialog.FileName);
            }
              }
        }