Esempio n. 1
0
 /// <summary>
 /// Create a new vote cast opeation.
 /// </summary>
 /// <param name="votingMaterial">Material to vote.</param>
 /// <param name="voterCertificate">Certificate of the voter.</param>
 /// <param name="vota">Selected options.</param>
 /// <param name="callBack">Callback upon completion.</param>
 public VoteOperation(VotingMaterial votingMaterial, Certificate voterCertificate, IEnumerable<IEnumerable<bool>> vota, VoteCallBack callBack)
 {
     this.votingMaterial = votingMaterial;
     this.voterCertificate = voterCertificate;
     this.vota = vota;
     this.callBack = callBack;
 }
Esempio n. 2
0
 /// <summary>
 /// Create a new signature.
 /// </summary>
 /// <param name="signer">Certificate of the signer.</param>
 /// <param name="objectData">Object data to be signed.</param>
 /// <param name="validFrom">This signature is not valid before then.</param>
 /// <param name="validUntil">This signature is valid until then.</param>
 public Signature(Certificate signer, byte[] objectData, DateTime validFrom, DateTime validUntil)
 {
     SignerId = signer.Id;
       ValidFrom = validFrom;
       ValidUntil = validUntil;
       Data = signer.Sign(AssmblySigningData(objectData));
 }
Esempio n. 3
0
        public void Display(CertificateAuthorityEntry entry, CertificateStorage storage, Certificate caCertificate)
        {
            Certificate certificate = entry.Certificate;
              SignatureRequest request = entry.RequestValue(caCertificate);

              this.idTextBox.Text = certificate.Id.ToString();
              this.typeTextBox.Text = certificate.TypeText;
              this.nameTextBox.Text = certificate.FullName;
              this.emailAddressTextBox.Text = request.EmailAddress;
              this.cantonTextBox.Text = certificate is VoterCertificate ? GroupList.GetGroupName(((VoterCertificate)certificate).GroupId) : "N/A";
              this.fingerprintTextBox.Text = certificate.Fingerprint;
              this.language = certificate.Language;
              this.certificate = entry.Certificate;

              LibraryResources.Culture = Language.English.ToCulture();
              this.reasonComboBox.Items.Add(LibraryResources.RevokedMoved);
              this.reasonComboBox.Items.Add(LibraryResources.RevokedStolen);
              this.reasonComboBox.Items.Add(LibraryResources.RevokedLost);
              this.reasonComboBox.Items.Add(LibraryResources.RevokedForgotten);
              this.reasonComboBox.Items.Add(LibraryResources.RevokedError);

              if (entry.Certificate is VoterCertificate)
              {
            this.reasonComboBox.Items.Add(LibraryResources.RevokedNoLonger);
              }
              else
              {
            this.reasonComboBox.Items.Add(LibraryResources.RevokedNoMoreFx);
              }
        }
Esempio n. 4
0
 public KioskServer(CertificateStorage certificateStorage, Certificate serverCertificate)
 {
     Requests = new Queue<RequestContainer>();
       this.certificateStorageBinary = certificateStorage.ToBinary();
       this.serverCertificateBinary = serverCertificate.ToBinary();
       this.tcpServer = new TcpServer(this);
 }
Esempio n. 5
0
 public SignatureRequestSignCheck(
     Certificate certificate,
     Signed<SignCheckCookie> cookie)
 {
     Cookie = cookie;
       Certificate = certificate;
       SignDateTime = DateTime.Now;
 }
Esempio n. 6
0
 public static void ShowCertificate(Certificate certificate, CertificateStorage certificateStorage, DateTime validationDate)
 {
     CertificateForm form = new CertificateForm();
       form.SetLanguage();
       form.certificateControl.ValidationDate = validationDate;
       form.certificateControl.CertificateStorage = certificateStorage;
       form.certificateControl.Certificate = certificate;
       form.ShowDialog();
 }
 private void GetCertificateStorageComplete(Certificate serverCertificate, Exception exception)
 {
     if (exception == null)
     {
         Client.GetVotingList(CertificateStorage, Environment.CurrentDirectory, GetVotingListCompleted);
     }
     else
     {
         BotMethods.SendMessage(SendType.Message, Channel, "Pi-Vote: " + exception.Message);
     }
 }
Esempio n. 8
0
        public ListEntry(string fileName, CACertificate caCertificate)
        {
            FileName = fileName;
              this.entry = Serializable.Load<CertificateAuthorityEntry>(FileName);

              this.certificate = this.entry.Request.Certificate;
              this.request = this.entry.RequestValue(caCertificate);

              if (this.entry.Response != null)
              {
            this.response = this.entry.Response.Value;
              }
        }
Esempio n. 9
0
 public static void TryFixVoterCertificate(CircleController controller, Certificate certificate)
 {
     CreateCertificateDialog dialog = new CreateCertificateDialog();
       if (dialog.TryResumeCertificateCreation(controller, certificate))
       {
     dialog.ShowDialog();
       }
       else
       {
     dialog.CreateNewVoterCertificate(controller);
     dialog.ShowDialog();
       }
 }
Esempio n. 10
0
        public ListEntry(string fileName, CertificateAuthorityEntry entry, CACertificate caCertificate)
        {
            FileName = fileName;
              this.entry = entry;

              this.certificate = this.entry.Request.Certificate;
              this.request = this.entry.RequestValue(caCertificate);

              if (this.entry.Response != null)
              {
            this.response = this.entry.Response.Value;
              }
        }
Esempio n. 11
0
        public SignatureRequestDocument(SignatureRequest signatureRequest, Certificate certificate, GetGroupNameHandler getGroupName)
        {
            if (signatureRequest == null)
            throw new ArgumentNullException("signatureRequest");
              if (certificate == null)
            throw new ArgumentNullException("certificate");

              this.signatureRequest = signatureRequest;
              this.certificate = certificate;
              this.getGroupName = getGroupName;

              var fontPath = Path.Combine(System.Windows.Forms.Application.StartupPath, FontFilename);
              var fontData = File.ReadAllBytes(fontPath);
              XPrivateFontCollection.Global.AddFont(fontData, "Dejavu Sans");
        }
Esempio n. 12
0
        private void createLoadCertificateButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
              dialog.Filter = Files.CertificateFileFilter;
              dialog.Title = "Load Certificate";
              dialog.CheckFileExists = true;
              dialog.Multiselect = false;

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            this.certificate = Serializable.Load<Certificate>(dialog.FileName);
            this.createCertificateIdTextBox.Text = this.certificate.Id.ToString();
            this.createSaveProofButon.Enabled =
              this.certificate != null &&
              !this.createProofTextTextBox.Text.IsNullOrEmpty();
              }
        }
Esempio n. 13
0
        public static Tuple<DialogResult, string, string> ShowChangePassphrase(Certificate certificate, string message, int minLength)
        {
            ChangePassphraseDialog dialog = new ChangePassphraseDialog();

              if (minLength > 0)
              {
            dialog.encryptCheckBox.Checked = true;
            dialog.encryptCheckBox.Enabled = false;
            dialog.minLength = minLength;
              }
              else
              {
            dialog.minLength = 1;
              }

              dialog.certificateIdTextBox.Text = certificate.Id.ToString();
              dialog.certificateTypeTextBox.Text = certificate.TypeText;

              if (message.IsNullOrEmpty())
              {
            dialog.messageLabel.Text = GuiResources.ChangePassphraseMessageChange;
              }
              else
              {
            dialog.messageLabel.ForeColor = Color.Red;
            dialog.messageLabel.Text = message;
              }

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            if (dialog.encryptCheckBox.Checked)
            {
              return new Tuple<DialogResult, string, string>(DialogResult.OK, dialog.oldPassphraseTextBox.Text, dialog.passphraseTextBox.Text);
            }
            else
            {
              return new Tuple<DialogResult, string, string>(DialogResult.OK, dialog.oldPassphraseTextBox.Text, null);
            }
              }
              else
              {
            return new Tuple<DialogResult, string, string>(DialogResult.Cancel, null, null);
              }
        }
Esempio n. 14
0
        public static bool TryUnlock(Certificate certificate)
        {
            if (certificate.PrivateKeyStatus == PrivateKeyStatus.Encrypted)
              {
            bool unlocked = false;

            while (!unlocked)
            {
              DecryptCaKeyDialog dialog = new DecryptCaKeyDialog();
              dialog.caIdTextBox.Text = certificate.Id.ToString();
              dialog.caNameTextBox.Text = certificate.FullName;

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            try
            {
              certificate.Unlock(dialog.passphraseTextBox.Text);
              unlocked = true;
            }
            catch
            { }
              }
              else
              {
            break;
              }
            }

            return unlocked;
              }
              else if (certificate.PrivateKeyStatus == PrivateKeyStatus.Unavailable)
              {
            return false;
              }
              else
              {
            return true;
              }
        }
Esempio n. 15
0
 public static bool IsOfType(this CertificateType type, Certificate certificate)
 {
     switch (type)
       {
     case CertificateType.None:
       return false;
     case CertificateType.All:
       return true;
     case CertificateType.CA:
       return certificate is CACertificate;
     case CertificateType.Admin:
       return certificate is AdminCertificate;
     case  CertificateType.Authority:
       return certificate is AuthorityCertificate;
     case CertificateType.Voter:
       return certificate is VoterCertificate;
     case CertificateType.Server:
       return certificate is ServerCertificate;
     default:
       return false;
       }
 }
Esempio n. 16
0
        public static bool TryDecryptIfNessecary(Certificate certificate, string actionName)
        {
            if (certificate.PrivateKeyStatus == PrivateKeyStatus.Encrypted)
              {
            bool unlocked = false;
            string message = null;

            while (!unlocked)
            {
              string passphrase = ShowSetPassphrase(certificate.Id.ToString(), certificate.TypeText, actionName, message);

              if (passphrase.IsNullOrEmpty())
            break;

              try
              {
            certificate.Unlock(passphrase);
            unlocked = true;
              }
              catch
              {
            message = GuiResources.EncryptPrivateKeyWrongPassphrase;
              }
            }

            return unlocked;
              }
              else if (certificate.PrivateKeyStatus == PrivateKeyStatus.Unavailable)
              {
            return false;
              }
              else
              {
            return true;
              }
        }
Esempio n. 17
0
        public byte[] GenerateNotaryCertificate(Certificate notaryCertificate)
        {
            SignCheckCookie cookie = new SignCheckCookie();
              Signed<SignCheckCookie> signedCookie = new Signed<SignCheckCookie>(cookie, notaryCertificate);

              Begin();
              Status.VotingClient.GenerateSignCheck(signedCookie, GenerateSignCheckComplete);

              if (!WaitForCompletion())
              {
            throw this.exception;
              }

              byte[] code = notaryCertificate.Decrypt(this.encryptedCode);

              return code;
        }
Esempio n. 18
0
 public static Tuple<DialogResult, string, string> ShowChangePassphrase(Certificate certificate, string message)
 {
     return ShowChangePassphrase(certificate, message, 0);
 }
Esempio n. 19
0
        /// <summary>
        /// Cast a vote and pack it in an envelope.
        /// </summary>
        /// <param name="votingMaterial">Voting material.</param>
        /// <param name="voterCertificate">Private certificate of this voter.</param>
        /// <param name="vota">List of vota.</param>
        /// <returns>Signed envelope containing the ballot.</returns>
        public Signed<Envelope> Vote(VotingMaterial votingMaterial, Certificate voterCertificate, IEnumerable<IEnumerable<int>> vota, ProgressHandler progressHandler)
        {
            if (votingMaterial == null)
            throw new ArgumentNullException("votingMaterial");

              bool acceptMaterial = SetVotingMaterial(votingMaterial);

              if (vota == null)
            throw new ArgumentNullException("vota");
              if (vota.Count() != this.parameters.Questions.Count())
            throw new ArgumentException("Bad vota count.");

              if (acceptMaterial)
              {
            List<Tuple<IEnumerable<int>, VotingParameters, Question, BigInt>> inputs = new List<Tuple<IEnumerable<int>, VotingParameters, Question, BigInt>>();

            for (int questionIndex = 0; questionIndex < this.parameters.Questions.Count(); questionIndex++)
            {
              IEnumerable<int> questionVota = vota.ElementAt(questionIndex);
              Question question = this.parameters.Questions.ElementAt(questionIndex);

              if (questionVota == null)
            throw new ArgumentNullException("questionVota");
              if (questionVota.Count() != question.Options.Count())
            throw new ArgumentException("Bad vota count.");
              if (!questionVota.All(votum => votum.InRange(0, 1)))
            throw new ArgumentException("Votum out of range.");

              inputs.Add(new Tuple<IEnumerable<int>, VotingParameters, Question, BigInt>(questionVota, this.parameters, question, this.publicKey));
            }

            List<Ballot> ballots = Parallel
              .Work<Tuple<IEnumerable<int>, VotingParameters, Question, BigInt>, Ballot>(CreateBallot, inputs, progressHandler);

            Envelope ballotContainer = new Envelope(this.parameters.VotingId, voterCertificate.Id, ballots);

            return new Signed<Envelope>(ballotContainer, voterCertificate);
              }
              else
              {
            return null;
              }
        }
Esempio n. 20
0
        private void UpdateItem(Certificate certificate)
        {
            ListViewItem item = this.certificates[certificate];

              item.SubItems[3].Text = certificate.Validate(controller.Status.CertificateStorage).Text();

              DateTime validFrom = certificate.ExpectedValidFrom(controller.Status.CertificateStorage);

              if (validFrom == DateTime.MinValue)
              {
            item.SubItems[4].Text = Resources.CertificateManagerValidIndefinite;
              }
              else if (validFrom == DateTime.MaxValue)
              {
            item.SubItems[4].Text = string.Empty;
              }
              else
              {
            item.SubItems[4].Text = validFrom.ToShortDateString();
              }

              DateTime validUntil = certificate.ExpectedValidUntil(controller.Status.CertificateStorage, DateTime.Now);

              if (validUntil == DateTime.MinValue)
              {
            item.SubItems[5].Text = string.Empty;
              }
              else if (validUntil == DateTime.MaxValue)
              {
            item.SubItems[5].Text = Resources.CertificateManagerValidIndefinite;
              }
              else
              {
            item.SubItems[5].Text = validUntil.ToShortDateString();
              }
        }
Esempio n. 21
0
        /// <summary>
        /// Add an authority.
        /// </summary>
        /// <param name="certificate">Authority to be added.</param>
        /// <returns>Index of the authority.</returns>
        public int AddAuthority(
            IRpcConnection connection,
            Certificate certificate)
        {
            if (certificate == null)
            throw new ArgumentNullException("certificate");
              if (certificate.Validate(this.certificateStorage) != CertificateValidationResult.Valid)
            throw new PiSecurityException(ExceptionCode.InvalidCertificate, "Authority certificate not valid.");
              if (!(certificate is AuthorityCertificate))
            throw new PiSecurityException(ExceptionCode.NoAuthorizedAuthority, "No an authority certificate.");

              MySqlTransaction transaction = DbConnection.BeginTransaction();

              MySqlCommand countCommand = new MySqlCommand("SELECT count(*) FROM authority WHERE VotingId = @VotingId", DbConnection, transaction);
              countCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
              if ((long)countCommand.ExecuteScalar() >= this.parameters.AuthorityCount)
            throw new PiArgumentException(ExceptionCode.AlreadyEnoughAuthorities, "Already enough authorities.");

              MySqlCommand addedCommand = new MySqlCommand("SELECT count(*) FROM authority WHERE VotingId = @VotingId AND AuthorityId = @AuthorityId", DbConnection, transaction);
              addedCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
              addedCommand.Add("@AuthorityId", certificate.Id.ToByteArray());
              if (addedCommand.ExecuteHasRows())
            throw new PiArgumentException(ExceptionCode.AuthorityAlreadyInVoting, "Already an authority of the voting.");

              MySqlCommand indexCommand = new MySqlCommand("SELECT max(AuthorityIndex) + 1 FROM authority WHERE VotingId = @VotingId", DbConnection, transaction);
              indexCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
              object authorityIndexNull = indexCommand.ExecuteScalar();
              int authorityIndex = authorityIndexNull == DBNull.Value ? 1 : Convert.ToInt32((long)authorityIndexNull);

              MySqlCommand insertCommand = new MySqlCommand("INSERT INTO authority (VotingId, AuthorityIndex, AuthorityId, Certificate) VALUES (@VotingId, @AuthorityIndex, @AuthorityId, @Certificate)", DbConnection, transaction);
              insertCommand.Parameters.AddWithValue("@VotingId", this.parameters.VotingId.ToByteArray());
              insertCommand.Parameters.AddWithValue("@AuthorityIndex", authorityIndex);
              insertCommand.Parameters.AddWithValue("@AuthorityId", certificate.Id.ToByteArray());
              insertCommand.Parameters.AddWithValue("@Certificate", certificate.ToBinary());
              insertCommand.ExecuteNonQuery();

              Logger.Log(LogLevel.Info, "Connection {0}: Authority id {1} added to voting id {2}", connection.Id, certificate.Id.ToString(), Id.ToString());

              transaction.Commit();

              return authorityIndex;
        }
Esempio n. 22
0
 /// <summary>
 /// Notify the admin about an authority that has done her job.
 /// </summary>
 /// <param name="authority">Authority in question.</param>
 /// <param name="activity">Activity string.</param>
 private void SendAdminAuthorityActivityMail(Certificate authority, string activity)
 {
     Server.SendMail(
     ServerConfig.MailAdminAddress,
     MailType.AdminAuthorityActivity,
     this,
     authority,
     activity);
 }
Esempio n. 23
0
 private void GetCertificateStorageComplete(Certificate serverCertificate, Exception exception)
 {
     Status.ServerCertificate = serverCertificate;
       this.exception = exception;
       this.run = false;
 }
Esempio n. 24
0
        private void DeleteContinueSignatureRequestFiles(Certificate certificate)
        {
            string signatureRequestFileName = Path.Combine(Status.DataPath, certificate.Id.ToString() + Files.SignatureRequestDataExtension);
              string signatureRequestInfoFileName = Path.Combine(Status.DataPath, certificate.Id.ToString() + Files.SignatureRequestInfoExtension);

              if (File.Exists(signatureRequestFileName) &&
              File.Exists(signatureRequestInfoFileName))
              {
            File.Delete(signatureRequestFileName);
            File.Delete(signatureRequestInfoFileName);
              }
        }
Esempio n. 25
0
        private bool TryResumeCertificateCreation(CircleController controller, Certificate certificate)
        {
            CreateDialogStatus status = new CreateDialogStatus(controller);
              status.Certificate = certificate;

              if (status.TryLoadSignatureRequest())
              {
            SetControl(
              new PrintAndUploadCertificateControl(),
              status);

            return true;
              }
              else
              {
            return false;
              }
        }
Esempio n. 26
0
 public string GetFileName(Certificate certificate)
 {
     return this.certificates[certificate];
 }
Esempio n. 27
0
 /// <summary>
 /// Get certificate type text in the selected language.
 /// </summary>
 /// <param name="certificate">Certificate in question.</param>
 /// <param name="language">Desired language.</param>
 /// <returns>Type text.</returns>
 private string CertificateTypeText(Certificate certificate, Language language)
 {
     if (certificate is VoterCertificate)
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeVoter", language.ToCulture());
       }
       else if (certificate is AdminCertificate)
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeAdmin", language.ToCulture());
       }
       else if (certificate is AuthorityCertificate)
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeAuthority", language.ToCulture());
       }
       else if (certificate is NotaryCertificate)
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeNotary", language.ToCulture());
       }
       else if (certificate is ServerCertificate)
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeServer", language.ToCulture());
       }
       else if (certificate is CACertificate)
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeCA", language.ToCulture());
       }
       else
       {
     return LibraryResources.ResourceManager.GetString("CertificateTypeUnknown", language.ToCulture());
       }
 }
Esempio n. 28
0
        public Tuple<SignatureResponseStatus, string> GetSignatureResponse(Certificate certificate)
        {
            Begin();
              Status.VotingClient.GetSignatureResponse(certificate.Id, GetSignatureResponseComplete);

              if (WaitForCompletion())
              {
            switch (this.responseStatus)
            {
              case SignatureResponseStatus.Accepted:
              case SignatureResponseStatus.Declined:
            var response = this.signatureResponse.Value;

            if (response.SubjectId.Equals(certificate.Id) &&
              this.signatureResponse.Verify(Status.CertificateStorage))
            {
              if (this.responseStatus == SignatureResponseStatus.Accepted)
              {
                certificate.AddSignature(response.Signature);
                certificate.Save(this.certificates[certificate]);
              }

              return new Tuple<SignatureResponseStatus, string>(this.responseStatus, response.Reason);
            }
            else
            {
              return new Tuple<SignatureResponseStatus, string>(SignatureResponseStatus.Unknown, string.Empty);
            }
              default:
            return new Tuple<SignatureResponseStatus, string>(this.responseStatus, string.Empty);
            }
              }
              else
              {
            return new Tuple<SignatureResponseStatus, string>(SignatureResponseStatus.Unknown, string.Empty);
              }
        }
Esempio n. 29
0
        private void AddItem(Certificate certificate)
        {
            ListViewItem item = new ListViewItem(certificate.Id.ToString());
              item.SubItems.Add(certificate.TypeText);

              if (certificate is VoterCertificate)
              {
            item.SubItems.Add(controller.Status.GetGroupName(((VoterCertificate)certificate).GroupId));
              }
              else if (certificate is AuthorityCertificate)
              {
            item.SubItems.Add(((AuthorityCertificate)certificate).FullName);
              }
              else if (certificate is AdminCertificate)
              {
            item.SubItems.Add(((AdminCertificate)certificate).FullName);
              }
              else if (certificate is NotaryCertificate)
              {
            item.SubItems.Add(((NotaryCertificate)certificate).FullName);
              }
              else
              {
            item.SubItems.Add(string.Empty);
              }

              item.SubItems.Add(certificate.Validate(controller.Status.CertificateStorage).Text());

              DateTime validFrom = certificate.ExpectedValidFrom(controller.Status.CertificateStorage);

              if (validFrom == DateTime.MinValue)
              {
            item.SubItems.Add(Resources.CertificateManagerValidIndefinite);
              }
              else if (validFrom == DateTime.MaxValue)
              {
            item.SubItems.Add(string.Empty);
              }
              else
              {
            item.SubItems.Add(validFrom.ToShortDateString());
              }

              DateTime validUntil = certificate.ExpectedValidUntil(controller.Status.CertificateStorage, DateTime.Now);

              if (validUntil == DateTime.MinValue)
              {
            item.SubItems.Add(string.Empty);
              }
              else if (validUntil == DateTime.MaxValue)
              {
            item.SubItems.Add(Resources.CertificateManagerValidIndefinite);
              }
              else
              {
            item.SubItems.Add(validUntil.ToShortDateString());
              }

              item.Tag = certificate;
              this.certificateList.Items.Add(item);

              this.certificates.Add(certificate, item);
        }
Esempio n. 30
0
 public void SaveCertificate(Certificate certificate)
 {
     if (this.certificates.ContainsKey(certificate))
       {
     certificate.Save(this.certificates[certificate]);
       }
       else
       {
     AddAndSaveCertificate(certificate);
       }
 }