Exemplo n.º 1
0
 static byte[] ForgeBallot(BallotContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Ballot),
                ForgeTzAddress(operation.Source),
                ForgeInt32(operation.Period),
                Base58.Parse(operation.Proposal, 2),
                new[] { (byte)operation.Ballot }));
 }
Exemplo n.º 2
0
        static byte[] ForgeBallot(BallotContent operation)
        {
            var res = ForgeNat(OperationTags[operation.Kind]);

            res = res.Concat(ForgeSource(operation.Source));
            res = res.Concat(ForgeInt32(operation.Period));
            res = res.Concat(Base58.Parse(operation.Proposal, ProposalPrefix));
            res = res.Concat(new[] { (byte)operation.Ballot });

            return(res);
        }
Exemplo n.º 3
0
        private void CastVote(VoteTicket ticket, string voteContent)
        {
            var protector  = dataprotection.CreateProtector("SecureBallot");
            var secureVote = protector.Protect(voteContent);
            var voteId     = Guid.NewGuid().ToString();

            lock (ticketsDb)
            {
                ticketsDb.Put(ticket.HashId, ticket.ToJson());
            }

            lock (secureBallot)
            {
                var ballot = new BallotContent()
                {
                    ElectionId = ticket.ElectionId, SecureVote = secureVote
                };
                secureBallot.Put(voteId, ballot.ToJson());
            }
        }
Exemplo n.º 4
0
        public IActionResult Tally(List <IFormFile> files)
        {
            if (!HttpContext.Session.Keys.Contains(IsAuthenticated))
            {
                return(RedirectToAction("Signin"));
            }

            if (files.Count != 5)
            {
                return(RedirectToAction("Tally", new { msg = "Missing keys" }));
            }

            var kk = new List <string>();

            foreach (var f in files)
            {
                kk.Add((new StreamReader(f.OpenReadStream())).ReadToEnd());
            }

            if (!JoinKeys(kk))
            {
                return(RedirectToAction("Tally", new { msg = "Fail to obtain master key" }));
            }

            ElectionGuard.ElectionDescription eldesc;
            lock (_conf)
            {
                if (_conf.Get(ESElectionConfigurationKey) == null)
                {
                    throw new Exception("ESConfiguration missing");
                }
                eldesc = JsonSerializer.Deserialize <ElectionGuard.ElectionDescription>(_conf.Get(ESElectionConfigurationKey));
            }

            var protector = dataProtector.CreateProtector("SecureBallot");
            var ballots   = new List <BallotContent>();

            lock (secureBallot)
            {
                if (secureBallot.Get(VotingForTallyClosedKey) == null)
                {
                    secureBallot.Put(VotingForTallyClosedKey, DateTime.Now.ToString());
                }
                using (var it = secureBallot.NewIterator())
                {
                    it.SeekToFirst();
                    while (it.Valid())
                    {
                        // This is the only exception and it is the seal of the Ballot
                        if (it.StringKey() != HomeController.VotingForTallyClosedKey)
                        {
                            ballots.Add(BallotContent.FromJson(it.StringValue()));
                        }
                        it.Next();
                    }
                }
            }

            var clearBallots = ballots.ConvertAll(b => (b.ElectionId, protector.Unprotect(b.SecureVote)));

            var result = new Dictionary <string, Dictionary <string, int> >();

            foreach (var ballot in clearBallots.GroupBy(b => b.ElectionId))
            {
                var count = ballot.GroupBy(b => b.Item2);
                foreach (var c in count)
                {
                    if (!result.ContainsKey(ballot.Key))
                    {
                        result.Add(ballot.Key, new Dictionary <string, int>());
                    }

                    result[ballot.Key].Add(c.Key, c.Count());
                }
            }
            var elections = eldesc.contests.ToDictionary(g => g.object_id);

            return(View((result, elections)));
        }