Пример #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;
 }
Пример #2
0
 public VotingContainer(VotingMaterial material, List<Certificate> authorities, List<Guid> authoritiesDone, VotingStatus status, int envelopeCount)
 {
     Material = material;
       Authorities = authorities;
       AuthoritiesDone = authoritiesDone;
       Status = status;
       EnvelopeCount = envelopeCount;
 }
Пример #3
0
        /// <summary>
        /// Creates a new voting descriptor from offline files.
        /// </summary>
        /// <param name="offlinePath">Path to the offline files.</param>
        public VotingDescriptor2(string offlinePath)
            : base(offlinePath)
        {
            string materialFileName = Path.Combine(offlinePath, Files.VotingMaterialFileName);

              if (!File.Exists(materialFileName))
            throw new ArgumentException("Offline voting material file not found.");

              this.material = Serializable.Load<VotingMaterial>(materialFileName);
              this.authorities = new List<Certificate>();

              for (int authorityIndex = 1; authorityIndex < this.material.Parameters.Value.AuthorityCount + 1; authorityIndex++)
              {
            string partialDecipherFileName = Path.Combine(offlinePath, string.Format(Files.PartialDecipherFileString, authorityIndex));

            if (File.Exists(partialDecipherFileName))
            {
              var partialDecipher = Serializable.Load<Signed<PartialDecipherList>>(partialDecipherFileName);

              this.authorities.Add(partialDecipher.Certificate);
            }
              }
        }
Пример #4
0
        private bool SetVotingMaterial(VotingMaterial votingMaterial)
        {
            bool acceptMaterial = votingMaterial.Valid(CertificateStorage);

              if (acceptMaterial)
              {
            this.parameters = votingMaterial.Parameters.Value;
            this.publicKey = new BigInt(1);

            foreach (Signed<ShareResponse> signedShareResponse in votingMaterial.PublicKeyParts)
            {
              ShareResponse shareResponse = signedShareResponse.Value;
              this.publicKey = (this.publicKey * shareResponse.PublicKeyPart).Mod(this.parameters.P);
            }
              }

              return acceptMaterial;
        }
Пример #5
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;
              }
        }
Пример #6
0
        /// <summary>
        /// Begin summation of votes.
        /// </summary>
        public void TallyBegin(
            VotingMaterial votingMaterial,
            int checkProofCount)
        {
            if (votingMaterial == null)
            throw new ArgumentNullException("votingMaterial");

              if (!SetVotingMaterial(votingMaterial))
            throw new PiArgumentException(ExceptionCode.BadVotingMaterial, "Bad voting material");

              this.tally = new Tally(this.parameters, CertificateStorage, this.publicKey, checkProofCount);
        }
Пример #7
0
 /// <summary>
 /// Send vote to server.
 /// </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 void Vote(VotingMaterial votingMaterial, VoterCertificate voterCertificate, IEnumerable<IEnumerable<bool>> vota, VoteCallBack callBack)
 {
     lock (this.operations)
       {
     this.operations.Enqueue(new VoteOperation(votingMaterial, voterCertificate, vota, callBack));
       }
 }
Пример #8
0
 private void GetVotingMaterialComplete(VotingMaterial votingMaterial, Exception exception)
 {
     this.votingMaterial = votingMaterial;
       this.exception = exception;
       this.run = false;
 }
Пример #9
0
        /// <summary>
        /// Calculates the public key of the authorities.
        /// </summary>
        /// <param name="votingMaterial">Voting material.</param>
        /// <returns>Public key.</returns>
        private BigInt CalculatePublicKey(VotingMaterial votingMaterial)
        {
            if (votingMaterial == null)
            throw new ArgumentNullException("votingMaterial");

              BigInt publicKey = new BigInt(1);
              var baseParameters = votingMaterial.Parameters.Value;

              foreach (Signed<ShareResponse> signedShareResponse in votingMaterial.PublicKeyParts)
              {
            ShareResponse shareResponse = signedShareResponse.Value;

            if (!signedShareResponse.Verify(this.certificateStorage, baseParameters.VotingBeginDate))
              throw new PiSecurityException(ExceptionCode.ShareResponseBadSignature, "Share response has bad signature.");
            if (!signedShareResponse.Certificate.IsIdentic(this.authorities[shareResponse.AuthorityIndex]))
              throw new PiSecurityException(ExceptionCode.ShareResponseWrongAuthority, "Share response is from wrong authority.");
            if (!shareResponse.AcceptShares)
              throw new PiSecurityException(ExceptionCode.ShareResponseNotAccepted, "Share response does not accept.");
            if (!shareResponse.Verify(votingMaterial.Parameters))
              throw new PiSecurityException(ExceptionCode.ShareResponseParametersDontMatch, "Share response does not match voting parameters.");

            publicKey = (publicKey * shareResponse.PublicKeyPart).Mod(this.parameters.P);
              }

              return publicKey;
        }
Пример #10
0
        /// <summary>
        /// Resets the vote sum.
        /// </summary>
        /// <param name="votingMaterial">Voting material.</param>
        public void TallyBegin(VotingMaterial votingMaterial)
        {
            if (votingMaterial == null)
            throw new ArgumentNullException("votingMaterial");

              BigInt publicKey = CalculatePublicKey(votingMaterial);

              this.tally = new Tally(this.parameters, this.certificateStorage, publicKey, BaseParameters.StandardProofCount);
        }
Пример #11
0
 /// <summary>
 /// Create a new voting descriptor.
 /// </summary>
 /// <param name="container">Container with all information about this voting.</param>
 public VotingDescriptor2(VotingContainer container)
     : base(container.Material.Parameters.Value, container.Status, container.AuthoritiesDone, container.EnvelopeCount)
 {
     this.material = container.Material;
       this.authorities = container.Authorities;
 }