Example #1
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetCertificateStorage;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  var value = client.proxy.FetchCertificateStorage();
                  this.certificateStorage.Add(value.First);
                  Certificate serverCertificate = value.Second;

                  if (serverCertificate.Validate(this.certificateStorage) == CertificateValidationResult.Valid)
                  {
                this.callBack(serverCertificate, null);
                  }
                  else
                  {
                throw new PiException(ExceptionCode.ServerCertificateInvalid, "Server certificate invalid.");
                  }
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
 protected PiVoteAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
 {
     BotMethods = botMethods;
     Client = client;
     CertificateStorage = certificateStorage;
     EventArgs = eventArgs;
 }
Example #3
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetSignatureRequests;
                  Progress = 0d;
                  SubText = LibraryResources.ClientGetSignatureRequestsGetList;
                  SubProgress = 0d;

                  var signatureRequestList = client.proxy.FetchSignatureRequestList();

                  int max = signatureRequestList.Count();
                  int done = 0;

                  if (max > 0)
                  {
                Progress = 0.5d;
                SubText = string.Format(LibraryResources.ClientGetSignatureRequestsGetRequest, done, max);
                SubProgress = (double)done / (double)max;
                HasSingleProgress = true;
                SingleProgress = SubProgress;

                foreach (Guid id in signatureRequestList)
                {
                  var signatureRequest = client.proxy.FetchSignatureRequest(id);
                  string fileName = Path.Combine(savePath, id.ToString() + ".pi-sig-req");
                  signatureRequest.Save(fileName);

                  done++;
                  SubText = string.Format(LibraryResources.ClientGetSignatureRequestsGetRequest, done, max);
                  SubProgress = (double)done / (double)max;
                  SingleProgress = SubProgress;
                }

                Progress = 1d;
                SubProgress = 1d;
                HasSingleProgress = false;
                  }
                  else
                  {
                Progress = 1d;
                SubText = LibraryResources.ClientGetSignatureRequestsNoRequest;
                SubProgress = 1d;
                  }

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
        public TallyAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
            : base(botMethods, client, certificateStorage, eventArgs)
        {
            if (eventArgs.Data.MessageArray.Length == 2)
            {
                int votingNumberTemp;

                if (int.TryParse(eventArgs.Data.MessageArray[1], out votingNumberTemp))
                {
                    if (votingNumberTemp >= 0)
                    {
                        votingNumber = votingNumberTemp;
                    }
                }
            }
        }
Example #5
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGenerateSignCheck;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  byte[] code = client.proxy.PushSignCheckCookie(this.signedCookie);

                  this.callBack(code, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetAuthorityCertificates;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  var authorityCertificates = client.proxy.FetchAuthorityCertificates();

                  this.callBack(authorityCertificates, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #7
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientSetCertificateStorage;
                  Progress = 0d;

                  client.proxy.PushCertificateStorage(this.certificateStorage);

                  Text = LibraryResources.ClientSetCertificateStorage;
                  Progress = 1d;

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
Example #8
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientDeleteVoting;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  client.proxy.DeleteVoting(this.command);

                  Progress = 1d;

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
Example #9
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetSignatureResponse;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  Signed<SignatureResponse> signatureResponse;
                  SignatureResponseStatus status = client.proxy.FetchSignatureResponse(this.certificateId, out signatureResponse);

                  Progress = 1d;

                  this.callBack(status, signatureResponse, null);
                }
                catch (Exception exception)
                {
                  this.callBack(SignatureResponseStatus.Unknown, null, exception);
                }
            }
Example #10
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetStats;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  List<VotingDescriptor> votingList = new List<VotingDescriptor>();

                  var data = client.proxy.FetchStats(this.type);

                  Progress = 1d;
                  SubProgress = 0d;

                  this.callBack(data, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #11
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  int max = fileNames.Count();
                  int done = 0;

                  if (max > 0)
                  {
                Text = string.Format(LibraryResources.ClientSetSignatureResponses, done, max);
                Progress = (double)done / (double)max;
                SubText = string.Empty;
                SubProgress = 0d;

                foreach (string fileName in this.fileNames)
                {
                  var signatureResponse = Serializable.Load<Signed<SignatureResponse>>(fileName);
                  client.proxy.PushSignatureResponse(signatureResponse);
                  done++;
                  Text = string.Format(LibraryResources.ClientSetSignatureResponses, done, max);
                  Progress = (double)done / (double)max;
                }
                  }
                  else
                  {
                Text = LibraryResources.ClientSetSignatureResponsesNoFiles;
                Progress = 1d;
                  }

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
Example #12
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  this.client = client;

                  Text = LibraryResources.ClientVoteFetchMaterial;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  var material = client.proxy.FetchVotingMaterial(this.votingId);

                  Progress = 1d;
                  SubProgress = 1d;

                  this.callBack(material, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #13
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientCreateVoting;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  client.proxy.CreateVoting(this.votingParameters, this.authorities);

                  Progress = 1d;

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
        public override void Activate()
        {
            actionQueue = new Queue<PiVoteAction>();
            certificateStorage = new CertificateStorage();

            if (!certificateStorage.TryLoadRoot("./root.pi-cert"))
            {
                throw new Exception("Cannot find root certificate file.");
            }

            client = new VotingClient(certificateStorage);

            var serverIpAddress = Dns.GetHostEntry(PiVoteServerAddress).AddressList.First();
            var serverIpEndPoint = new IPEndPoint(serverIpAddress, PiVoteServerPort);
            client.Connect(serverIpEndPoint);

            BotMethods.AddCommand(new Commandlet(CommandListVotings, CommandListVotingsDescription, ListVotingsHandler, this));
            BotMethods.AddCommand(new Commandlet(CommandTally, CommandTallyDescription, TallyHandler, this));
            BotMethods.AddCommand(new Commandlet(CommandStatus, CommandStatusDescription, StatusHandler, this));

            base.Activate();
        }
Example #15
0
 /// <summary>
 /// Execute the operation.
 /// </summary>
 /// <remarks>
 /// Don't forget to callback when implementing.
 /// </remarks>
 /// <param name="client">Voter client to execute against.</param>
 public abstract void Execute(VotingClient client);
Example #16
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetCertificateStorage;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  var config = client.proxy.FetchConfig(this.clientName, this.clientVersion);

                  this.callBack(config.First, config.Second, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, null, exception);
                }
            }
Example #17
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientCheckSharesLoadAuthority;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  client.LoadAuthority(this.authorityFileName, this.authorityCertificate);

                  Text = LibraryResources.ClientCheckSharesFetchShares;
                  Progress = 0.2d;

                  var allShareParts = client.proxy.FetchAllShares(this.votingId);

                  Text = LibraryResources.ClientCheckSharesVerifyShares;
                  Progress = 0.4d;

                  var signedShareResponse = client.authorityEntity.VerifyShares(allShareParts);

                  Text = LibraryResources.ClientCheckSharesSaveAuthority;
                  Progress = 0.5d;

                  Signed<BadShareProof> signedBadShareProof = client.authorityEntity.CreateBadShareProof(allShareParts);
                  signedBadShareProof.Save(Path.Combine(Path.GetDirectoryName(this.authorityFileName), signedBadShareProof.Value.FileName(signedBadShareProof.Certificate.Id)));

                  client.SaveAuthority(this.authorityFileName);

                  Text = LibraryResources.ClientCheckSharesPushShareResponse;
                  Progress = 0.6d;

                  client.proxy.PushShareResponse(this.votingId, signedShareResponse);

                  Text = LibraryResources.ClientCheckSharesGetVotingStatus;
                  Progress = 0.8d;

                  var material = client.proxy.FetchVotingMaterial(this.votingId);
                  List<Guid> authoritiesDone;
                  VotingStatus status = client.proxy.FetchVotingStatus(this.votingId, out authoritiesDone);
                  var votingDescriptor = new VotingDescriptor(material.Parameters.Value, status, authoritiesDone, material.CastEnvelopeCount);

                  Progress = 1d;

                  this.callBack(votingDescriptor, signedShareResponse.Value.AcceptShares, signedBadShareProof, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, false, null, exception);
                }
            }
Example #18
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetResultFetchMaterial;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  if (!Directory.Exists(this.offlinePath))
                Directory.CreateDirectory(this.offlinePath);

                  var material = client.proxy.FetchVotingMaterial(votingId);
                  string materialFileName = Path.Combine(this.offlinePath, Files.VotingMaterialFileName);
                  material.Save(materialFileName);

                  var parameters = material.Parameters.Value;

                  Progress = 0.1d;
                  Text = LibraryResources.ClientGetResultFetchEnvelopeCount;

                  this.envelopeCount = client.proxy.FetchEnvelopeCount(votingId);

                  Progress = 0.2d;
                  Text = LibraryResources.ClientGetResultFetchEnvelopes;
                  SubText = string.Format(LibraryResources.ClientGetResultFetchEnvelopesOf, 0, this.envelopeCount);
                  SubProgress = 0d;

                  this.client = client;
                  Thread fetcher = new Thread(FetchWorker);
                  fetcher.Priority = ThreadPriority.Lowest;
                  fetcher.Start();

                  HasSingleProgress = true;

                  while (this.fetchedEnvelopes < this.envelopeCount)
                  {
                SubText = string.Format(LibraryResources.ClientDownloadVotingFetchEnvelopesOf, this.fetchedEnvelopes, this.envelopeCount);
                SubProgress = 1d / (double)this.envelopeCount * (double)this.fetchedEnvelopes;
                SingleProgress = SubProgress;

                Thread.Sleep(100);
                  }

                  fetcher.Join();

                  HasSingleProgress = false;
                  Progress = 0.8d;
                  Text = LibraryResources.ClientGetResultFetchPartialDeciphers;
                  SubText = string.Format(LibraryResources.ClientGetResultFetchPartialDeciphersOf, 0, parameters.AuthorityCount);
                  SubProgress = 0d;

                  for (int authorityIndex = 1; authorityIndex < parameters.AuthorityCount + 1; authorityIndex++)
                  {
                var partialDecipher = client.proxy.FetchPartialDecipher(votingId, authorityIndex);

                if (partialDecipher != null)
                {
                  string partialDecipherFileName = Path.Combine(this.offlinePath, string.Format(Files.PartialDecipherFileString, authorityIndex));
                  partialDecipher.Save(partialDecipherFileName);
                }

                SubText = string.Format(LibraryResources.ClientGetResultFetchPartialDeciphersOf, authorityIndex, parameters.AuthorityCount);
                SubProgress = 1d / (double)parameters.AuthorityCount * (double)(authorityIndex);
                  }

                  Progress = 1d;
                  SubProgress = 1d;

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
 public ListVotingsAction(IrcBot botMethods, VotingClient client, CertificateStorage certificateStorage, IrcEventArgs eventArgs)
     : base(botMethods, client, certificateStorage, eventArgs)
 {
 }
Example #20
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetResultFetchMaterial;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  VotingMaterial material = null;

                  if (this.offlinePath.IsNullOrEmpty())
                  {
                material = client.proxy.FetchVotingMaterial(votingId);
                  }
                  else
                  {
                material = Serializable.Load<VotingMaterial>(Path.Combine(this.offlinePath, Files.VotingMaterialFileName));
                  }

                  if (!material.Valid(client.voterEntity.CertificateStorage))
                throw new InvalidOperationException(LibraryResources.ClientGetResultMaterialInvalid);
                  var parameters = material.Parameters.Value;

                  Progress = 0.1d;
                  Text = LibraryResources.ClientGetResultFetchEnvelopeCount;

                  if (this.offlinePath.IsNullOrEmpty())
                  {
                this.envelopeCount = client.proxy.FetchEnvelopeCount(votingId);
                  }
                  else
                  {
                var directory = new DirectoryInfo(this.offlinePath);
                this.envelopeCount = directory.GetFiles(Files.EnvelopeFilePattern).Count();
                  }

                  while (true)
                  {
                try
                {
                  Progress = 0.2d;
                  Text = LibraryResources.ClientGetResultFetchEnvelopes;
                  SubText = string.Format(LibraryResources.ClientGetResultFetchEnvelopesOf, 0, this.envelopeCount);
                  SubProgress = 0d;

                  client.voterEntity.TallyBegin(material, this.checkProofCount);

                  HasSingleProgress = true;
                  this.client = client;
                  this.envelopeQueue = new Queue<Tuple<int, Signed<Envelope>>>();
                  this.workerRun = true;
                  Thread fetcher = new Thread(FetchWorker);
                  fetcher.Priority = ThreadPriority.Lowest;
                  fetcher.Start();
                  List<Thread> workers = new List<Thread>();
                  Environment.ProcessorCount.Times(() => workers.Add(new Thread(TallyAddWorker)));
                  this.threadProgress = new Dictionary<int, double>();
                  workers.ForEach(worker => worker.Priority = ThreadPriority.Lowest);
                  workers.ForEach(worker => this.threadProgress.Add(worker.ManagedThreadId, 0d));
                  workers.ForEach(worker => worker.Start());

                  while (this.verifiedEnvelopes < this.envelopeCount)
                  {
                lock (this.threadProgress)
                {
                  SubText = string.Format(LibraryResources.ClientGetResultFetchEnvelopesOf, this.verifiedEnvelopes, this.envelopeCount);
                  SubProgress = 0.2d / (double)this.envelopeCount * (double)this.fetchedEnvelopes +
                                0.8d / (double)this.envelopeCount * ((double)this.verifiedEnvelopes + this.threadProgress.Values.Sum());
                  SingleProgress = SubProgress;
                }

                Thread.Sleep(100);
                  }

                  fetcher.Join();
                  this.workerRun = false;
                  workers.ForEach(worker => worker.Join());

                  Progress = 0.8d;
                  Text = LibraryResources.ClientGetResultFetchPartialDeciphers;
                  SubText = string.Format(LibraryResources.ClientGetResultFetchPartialDeciphersOf, 0, parameters.AuthorityCount);
                  SubProgress = 0d;

                  fetcher.Join();
                  this.workerRun = false;
                  workers.ForEach(worker => worker.Join());

                  for (int authorityIndex = 1; authorityIndex < parameters.AuthorityCount + 1; authorityIndex++)
                  {
                Signed<PartialDecipherList> partialDecipher = null;

                if (this.offlinePath.IsNullOrEmpty())
                {
                  partialDecipher = client.proxy.FetchPartialDecipher(votingId, authorityIndex);
                }
                else
                {
                  string partialDecipherFileName = Path.Combine(this.offlinePath, string.Format(Files.PartialDecipherFileString, authorityIndex));

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

                if (partialDecipher != null)
                {
                  client.voterEntity.TallyAddPartialDecipher(partialDecipher);
                }

                SubText = string.Format(LibraryResources.ClientGetResultFetchPartialDeciphersOf, authorityIndex, parameters.AuthorityCount);
                SubProgress = 1d / (double)parameters.AuthorityCount * (double)(authorityIndex);
                SingleProgress = SubProgress;
                  }

                  Progress = 0.9d;
                  Text = LibraryResources.ClientGetResultDecipherResult;
                  SubProgress = 0d;
                  HasSingleProgress = false;

                  var result = client.voterEntity.TallyResult;

                  SubProgress = 1d;
                  Progress = 1d;

                  this.callBack(result, this.voteReceiptsStatus, null);
                  return;
                }
                catch (PiSecurityException exception)
                {
                  if (exception.Code == ExceptionCode.PartialDecipherBadEnvelopeHash &&
                 this.checkProofCount < parameters.ProofCount)
                  {
                this.checkProofCount = Math.Min(parameters.ProofCount, this.checkProofCount + 1);
                  }
                  else
                  {
                throw;
                  }
                }
                  }
                }
                catch (Exception exception)
                {
                  this.callBack(null, null, exception);
                }
            }
Example #21
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientSetSignatureRequest;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  client.proxy.PushSignatureRequest(this.signatureRequest, this.signatureRequestInfo);

                  Progress = 1d;

                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }
Example #22
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientCreateSharePartPrepareAuthority;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  var parameters = client.proxy.FetchParameters(this.votingId, this.authorityCertificate);

                  client.CreateAuthority(this.authorityCertificate);
                  client.authorityEntity.Prepare(parameters.Key, parameters.Value);

                  Text = LibraryResources.ClientCreateSharePartFetchAuthorityList;
                  Progress = 0.15d;

                  var authorityList = client.proxy.FetchAuthorityList(this.votingId);

                  client.authorityEntity.SetAuthorities(authorityList);

                  Text = LibraryResources.ClientCreateSharePartSaveAuthority;
                  Progress = 0.3d;

                  client.SaveAuthority(this.authorityFileName);

                  Text = LibraryResources.ClientCreateSharePartCreateShareParts;
                  Progress = 0.55d;

                  var sharePart = client.authorityEntity.GetShares();

                  Text = LibraryResources.ClientCreateSharePartPushShareParts;
                  Progress = 0.75d;

                  client.proxy.PushShares(this.votingId, sharePart);

                  Text = LibraryResources.ClientCreateSharePartGetVotingStatus;
                  Progress = 0.9d;

                  var material = client.proxy.FetchVotingMaterial(this.votingId);
                  List<Guid> authoritieDone;
                  VotingStatus status = client.proxy.FetchVotingStatus(this.votingId, out authoritieDone);
                  var votingDescriptor = new VotingDescriptor(material.Parameters.Value, status, authoritieDone, material.CastEnvelopeCount);

                  Progress = 1d;

                  this.callBack(votingDescriptor, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #23
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voting client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientCreateDeciphersLoadAuthority;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  client.LoadAuthority(this.authorityFileName, this.authorityCertificate);

                  Text = LibraryResources.ClientCreateDeciphersFetchMaterial;
                  Progress = 0.1d;

                  var material = client.proxy.FetchVotingMaterial(this.votingId);
                  client.authorityEntity.TallyBegin(material);

                  Text = LibraryResources.ClientCreateDeciphersFetchEnvelopeCount;
                  Progress = 0.2d;
                  this.envelopeCount = client.proxy.FetchEnvelopeCount(votingId);

                  Text = LibraryResources.ClientCreateDeciphersFetchEnvelope;
                  Progress = 0.2d;

                  this.client = client;
                  this.envelopeQueue = new Queue<Tuple<int, Signed<Envelope>>>();
                  this.workerRun = true;
                  Thread fetcher = new Thread(FetchWorker);
                  fetcher.Priority = ThreadPriority.Lowest;
                  fetcher.Start();
                  List<Thread> workers = new List<Thread>();
                  Environment.ProcessorCount.Times(() => workers.Add(new Thread(TallyAddWorker)));
                  this.threadProgress = new Dictionary<int, double>();
                  workers.ForEach(worker => worker.Priority = ThreadPriority.Lowest);
                  workers.ForEach(worker => this.threadProgress.Add(worker.ManagedThreadId, 0d));
                  workers.ForEach(worker => worker.Start());
                  HasSingleProgress = true;

                  while (this.verifiedEnvelopes < this.envelopeCount)
                  {
                lock (this.threadProgress)
                {
                  SubText = string.Format(LibraryResources.ClientGetResultFetchEnvelopesOf, this.verifiedEnvelopes, this.envelopeCount);
                  SubProgress = 0.2d / (double)this.envelopeCount * (double)this.fetchedEnvelopes +
                            0.8d / (double)this.envelopeCount * ((double)this.verifiedEnvelopes + this.threadProgress.Values.Sum());
                  SingleProgress = SubProgress;
                }

                Thread.Sleep(100);
                  }

                  this.workerRun = false;
                  workers.ForEach(worker => worker.Join());
                  HasSingleProgress = false;
                  SubText = string.Empty;

                  Text = LibraryResources.ClientCreateDeciphersCreatePartialDecipher;
                  Progress = 0.7d;

                  if (this.askCallBack == null || this.askCallBack(client.authorityEntity.TallyValidEnvelopeCount))
                  {
                var decipherList = client.authorityEntity.PartiallyDecipher();

                Text = LibraryResources.ClientCreateDeciphersPushPartialDecipher;
                Progress = 0.8d;

                client.proxy.PushPartailDecipher(this.votingId, decipherList);

                Text = LibraryResources.ClientCreateDeciphersFetchVotingStatus;
                Progress = 0.9d;

                material = client.proxy.FetchVotingMaterial(this.votingId);
                List<Guid> authoritiesDone;
                VotingStatus status = client.proxy.FetchVotingStatus(this.votingId, out authoritiesDone);
                var votingDescriptor = new VotingDescriptor(material.Parameters.Value, status, authoritiesDone, material.CastEnvelopeCount);

                Progress = 1d;

                this.callBack(votingDescriptor, null);
                  }
                  else
                  {
                this.callBack(null, new PiException(ExceptionCode.CanceledByUser, LibraryResources.ExceptionCanceledByUser));
                  }
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #24
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientGetVotingList;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  List<VotingDescriptor> votingList = new List<VotingDescriptor>();

                  var votingMaterials = client.proxy.FetchVotingMaterial(null);
                  var votingDescriptors = votingMaterials
                .Where(votingMaterial => votingMaterial.First.Valid(this.certificateStorage))
                .Select(votingMaterial => new VotingDescriptor(votingMaterial.First.Parameters.Value, votingMaterial.Second, votingMaterial.Third, votingMaterial.First.CastEnvelopeCount));
                  votingList.AddRange(votingDescriptors);

                  DirectoryInfo appDataDirectory = new DirectoryInfo(this.dataPath);

                  foreach (DirectoryInfo offlineDirectory in appDataDirectory.GetDirectories())
                  {
                if (File.Exists(Path.Combine(offlineDirectory.FullName, Files.VotingMaterialFileName)))
                {
                  votingList.Add(new VotingDescriptor(offlineDirectory.FullName));
                }
                  }

                  Progress = 1d;
                  SubProgress = 0d;

                  this.callBack(votingList, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #25
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  this.client = client;

                  Text = LibraryResources.ClientVote;
                  Progress = 0d;
                  SubText = LibraryResources.ClientVoteFetchMaterial;
                  SubProgress = 0d;

                  if (!votingMaterial.Valid(client.voterEntity.CertificateStorage))
                throw new InvalidOperationException(LibraryResources.ClientVoteMaterialInvalid);
                  var parameters = votingMaterial.Parameters.Value;

                  if (!parameters.Valid)
                throw new InvalidOperationException(LibraryResources.ClientVoteMaterialInvalid);

                  IEnumerable<IEnumerable<int>> vota = this.vota.Select(questionVota => questionVota.Select(votum => votum ? 1 : 0));

                  Progress = 0.3d;
                  SubText = LibraryResources.ClientVoteCalcVote;
                  SubProgress = 0d;
                  HasSingleProgress = true;

                  var envelope = client.voterEntity.Vote(this.votingMaterial, this.voterCertificate, vota, VoteProgressHandler);

                  HasSingleProgress = false;
                  Progress = 0.7d;
                  SubText = LibraryResources.ClientVotePushVote;
                  SubProgress = 0d;

                  var voteReceipt = client.proxy.PushEnvelope(parameters.VotingId, envelope);

                  if (voteReceipt == null ||
                  !voteReceipt.Verify(client.voterEntity.CertificateStorage) ||
                  !(voteReceipt.Certificate is ServerCertificate) ||
                  voteReceipt.Value.VoterId != envelope.Certificate.Id ||
                  voteReceipt.Value.VotingId != parameters.VotingId ||
                  !voteReceipt.Value.Verify(envelope))
                  {
                throw new PiSecurityException(ExceptionCode.InvalidVoteReceipt, "Invalid vote receipt");
                  }

                  Progress = 1d;

                  this.callBack(voteReceipt, null);
                }
                catch (Exception exception)
                {
                  this.callBack(null, exception);
                }
            }
Example #26
0
            /// <summary>
            /// Execute the operation.
            /// </summary>
            /// <param name="client">Voter client to execute against.</param>
            public override void Execute(VotingClient client)
            {
                try
                {
                  Text = LibraryResources.ClientConnect;
                  Progress = 0d;
                  SubText = string.Empty;
                  SubProgress = 0d;

                  if (!client.client.Connected)
                  {
                if (proxyEndPoint == null)
                {
                  client.Connect(this.serverEndPoint);
                }
                else
                {
                  client.Connect(this.serverEndPoint, this.proxyEndPoint);
                }
                  }

                  Progress = 1d;
                  this.callBack(null);
                }
                catch (Exception exception)
                {
                  this.callBack(exception);
                }
            }