Example #1
0
        public static void TestSignatureRequestDocument()
        {
            VoterCertificate voterCert = new VoterCertificate(Language.English, null, 0);
              voterCert.CreateSelfSignature();
              SignatureRequest request = new SignatureRequest("Hans", "Müller", "*****@*****.**");
              SignatureRequestInfo requestInfo = new SignatureRequestInfo("*****@*****.**", request.Encrypt());

              SignatureRequestDocument document = new SignatureRequestDocument(request, voterCert, GetGroupName);

              ////PrintDialog dialog = new PrintDialog();
              ////dialog.Document = document;

              ////if (dialog.ShowDialog() == DialogResult.OK)
              ////{
              ////  document.Print();
              ////}
        }
Example #2
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            SetEnable(false);
              this.run = true;
              OnUpdateWizard();

              SignatureRequest signatureRequest
            = new SignatureRequest(
              this.firstNameTextBox.Text,
              this.familyNameTextBox.Text,
              this.emailAddressTextBox.Text);

              SignatureRequestInfo signatureRequestInfo
            = new SignatureRequestInfo(
              this.emailAddressTextBox.Text,
              signatureRequest.Encrypt());

              SignatureRequestDocument document = new SignatureRequestDocument(
            signatureRequest,
            Status.Certificate,
            Status.GetGroupName);

              SaveFileDialog dialog = new SaveFileDialog();
              dialog.Title = GuiResources.SaveDocumentDialogTitle;
              dialog.Filter = Files.PdfFileFilter;

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            document.Create(dialog.FileName);

            Secure<SignatureRequest> secureSignatureRequest =
              new Secure<SignatureRequest>(signatureRequest, Status.CaCertificate, Status.Certificate);
            Secure<SignatureRequestInfo> secureSignatureRequestInfo =
              new Secure<SignatureRequestInfo>(signatureRequestInfo, Status.ServerCertificate, Status.Certificate);

            Status.VotingClient.SetSignatureRequest(secureSignatureRequest, secureSignatureRequestInfo, SetSignatureRequestComplete);

            while (this.run)
            {
              Status.UpdateProgress();
              Thread.Sleep(10);
            }

            Status.UpdateProgress();

            if (this.exception == null)
            {
              Status.SetMessage(Resources.CreateCertificateDone, MessageType.Success);
            }
            else
            {
              Status.SetMessage(this.exception.Message, MessageType.Error);
            }
              }
              else
              {
            SetEnable(true);
            this.run = false;
              }

              OnUpdateWizard();
        }
        private void createButton_Click(object sender, EventArgs e)
        {
            this.run = true;
              OnUpdateWizard();

              SetEnable(false);

              var encryptResult = EncryptPrivateKeyDialog.ShowSetPassphrase();

              if (encryptResult.First == DialogResult.OK)
              {
            string passphrase = encryptResult.Second;

            Status.Certificate = new VoterCertificate(Resources.Culture.ToLanguage(), passphrase, this.groupComboBox.Value.Id);
            Status.Certificate.CreateSelfSignature();
            Status.CertificateFileName = Path.Combine(Status.DataPath, Status.Certificate.Id.ToString() + Files.CertificateExtension);
            Status.Certificate.Save(Status.CertificateFileName);

            Certificate parentCertificate = TryFindValidParentCertificate();

            if (parentCertificate != null)
            {
              DateTime parentValidUntil = parentCertificate.ExpectedValidUntil(Status.CertificateStorage, DateTime.Now);
              DialogResult result = DialogResult.Yes;

              while (result == DialogResult.Yes)
              {
            result = MessageForm.Show(
              string.Format(Resources.AskToSignSignatureRequestWithParent, parentValidUntil),
              GuiResources.MessageBoxTitle,
              MessageBoxButtons.YesNo,
              MessageBoxIcon.Question,
              DialogResult.Yes);

            if (result == DialogResult.Yes &&
              DecryptPrivateKeyDialog.TryDecryptIfNessecary(parentCertificate, string.Empty))
            {
              this.signatureRequest = new SignatureRequest2(this.firstNameTextBox.Text, this.familyNameTextBox.Text, this.emailAddressTextBox.Text, parentCertificate);
              result = DialogResult.OK;
            }

            parentCertificate.Lock();
              }
            }

            if (this.signatureRequest == null)
            {
              this.signatureRequest = new SignatureRequest(this.firstNameTextBox.Text, this.familyNameTextBox.Text, this.emailAddressTextBox.Text);
            }

            this.signatureRequestInfo = new SignatureRequestInfo(
              this.emailNotificationCheckBox.Checked ? this.emailAddressTextBox.Text : string.Empty,
              this.signatureRequest.Encrypt());
            this.secureSignatureRequest = new Secure<SignatureRequest>(this.signatureRequest, Status.CaCertificate, Status.Certificate);
            this.secureSignatureRequestInfo = new Secure<SignatureRequestInfo>(this.signatureRequestInfo, Status.ServerCertificate, Status.Certificate);

            string signatureRequestDataFileName = Path.Combine(Status.DataPath, Status.Certificate.Id.ToString() + Files.SignatureRequestDataExtension);
            this.signatureRequest.Save(signatureRequestDataFileName);

            this.run = false;
            OnUpdateWizard();

            if (this.signatureRequest is SignatureRequest2)
            {
              this.uploadButton.Enabled = true;
            }
            else
            {
              this.printButton.Enabled = true;
            }
              }
              else
              {
            this.run = false;
            OnUpdateWizard();

            SetEnable(true);
              }
        }
Example #4
0
        private void okButton_Click(object sender, EventArgs e)
        {
            this.passphraseTextBox.Enabled = false;
              this.repeatTextBox.Enabled = false;
              this.okButton.Enabled = false;

              var signatureRequest = this.controller.UserData;
              var certificate = new VoterCertificate(Language.German, this.passphraseTextBox.Text, 0);
              certificate.CreateSelfSignature();
              var secureRequest = new Secure<SignatureRequest>(signatureRequest, this.caCertificate, certificate);
              var requestInfo = new SignatureRequestInfo(string.Empty, signatureRequest.Encrypt());
              var secureRequestInfo = new Secure<SignatureRequestInfo>(requestInfo, this.controller.ServerCertificate, certificate);
              var requestContainer = new RequestContainer(signatureRequest, secureRequest, secureRequestInfo);

              this.requestStatusTextBox.Text = "Übermitteln...";
              this.controller.RequestContainer = requestContainer;
        }
        public override void Begin()
        {
            if (Status.Certificate == null)
              {
            SetEnable(true);
            this.printButton.Enabled = false;
            this.uploadButton.Enabled = false;
            this.done = false;
              }
              else if (Status.Certificate.Validate(Status.CertificateStorage) == CertificateValidationResult.Valid)
              {
            SetEnable(false);
            this.printButton.Enabled = false;
            this.uploadButton.Enabled = false;
            this.done = true;
            Status.SetMessage(Resources.CheckCertificateReady, MessageType.Info);
              }
              else
              {
            string signatureRequestDataFileName = Path.Combine(Status.DataPath, Status.Certificate.Id.ToString() + Files.SignatureRequestDataExtension);

            if (File.Exists(signatureRequestDataFileName))
            {
              if (DecryptPrivateKeyDialog.TryDecryptIfNessecary(Status.Certificate, GuiResources.UnlockActionSignRequest))
              {
            this.signatureRequest = Serializable.Load<SignatureRequest>(signatureRequestDataFileName);
            this.signatureRequestInfo = new SignatureRequestInfo(
              this.signatureRequest.EmailAddress,
              this.signatureRequest.Encrypt());
            this.secureSignatureRequest = new Secure<SignatureRequest>(this.signatureRequest, Status.CaCertificate, Status.Certificate);
            this.secureSignatureRequestInfo = new Secure<SignatureRequestInfo>(this.signatureRequestInfo, Status.ServerCertificate, Status.Certificate);

            if (Status.Certificate is VoterCertificate)
            {
              this.typeComboBox.SelectedIndex = 0;
            }
            else if (Status.Certificate is AuthorityCertificate)
            {
              this.typeComboBox.SelectedIndex = 1;
            }
            else if (Status.Certificate is AdminCertificate)
            {
              this.typeComboBox.SelectedIndex = 2;
            }

            this.firstNameTextBox.Text = this.signatureRequest.FirstName;
            this.familyNameTextBox.Text = this.signatureRequest.FamilyName;
            this.emailAddressTextBox.Text = this.signatureRequest.EmailAddress;

            if (Status.Certificate is VoterCertificate)
            {
              this.groupComboBox.Value = Status.Groups.Where(group => group.Id == ((VoterCertificate)Status.Certificate).GroupId).Single();
            }

            SetEnable(false);
            this.printButton.Enabled = true;
            this.uploadButton.Enabled = true;
            this.done = false;
              }
              else
              {
            Status.CertificateFileName = null;
            Status.Certificate = null;

            SetEnable(true);
            this.printButton.Enabled = false;
            this.uploadButton.Enabled = false;
            this.done = false;
            Status.SetMessage(Resources.SimpleCreateCertificateSigningCanceled, MessageType.Info);
              }
            }
            else
            {
              File.Move(Status.CertificateFileName, Status.CertificateFileName + Files.BakExtension);
              Status.CertificateFileName = null;
              Status.Certificate = null;

              SetEnable(true);
              this.printButton.Enabled = false;
              this.uploadButton.Enabled = false;
              this.done = false;
              Status.SetMessage(Resources.SimpleCreateCertificateFileMissing, MessageType.Error);
            }
              }

              OnUpdateWizard();
        }