Esempio n. 1
0
        public void ChainTest()
        {
            CertificateStorage storage = new CertificateStorage();

              CACertificate root = new CACertificate(null, "Root");
              root.CreateSelfSignature();
              Assert.AreEqual(CertificateValidationResult.NoSignature, root.Validate(storage));

              storage.AddRoot(root.OnlyPublicPart);
              Assert.AreEqual(CertificateValidationResult.Valid, root.Validate(storage));

              var rootCrl = new RevocationList(root.Id, DateTime.Now, DateTime.Now.AddDays(1), new Guid[]{});
              var signedRootCrl = new Signed<RevocationList>(rootCrl, root);
              storage.AddRevocationList(signedRootCrl);

              CACertificate intermediate = new CACertificate(null, "Intermediate");
              intermediate.CreateSelfSignature();
              Assert.AreEqual(CertificateValidationResult.NoSignature, intermediate.Validate(storage));

              intermediate.AddSignature(root, DateTime.Now.AddDays(1));
              storage.Add(intermediate.OnlyPublicPart);
              Assert.AreEqual(CertificateValidationResult.Valid, intermediate.Validate(storage));

              var intermediateCrl = new RevocationList(intermediate.Id, DateTime.Now, DateTime.Now.AddDays(1), new Guid[] { });
              var signedIntermediateCrl = new Signed<RevocationList>(intermediateCrl, intermediate);
              storage.AddRevocationList(signedIntermediateCrl);

              AdminCertificate test = new AdminCertificate(Language.English, null, "Test");
              test.CreateSelfSignature();
              Assert.AreEqual(CertificateValidationResult.NoSignature, test.Validate(storage));

              test.AddSignature(intermediate, DateTime.Now.AddDays(1));
              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage));
        }
Esempio n. 2
0
        public void MyTestInitialize()
        {
            this.storage = new CertificateStorage();

              this.root = new CACertificate(null, "Root");
              this.root.CreateSelfSignature();
              this.storage.AddRoot(this.root.OnlyPublicPart);

              var rootCrl = new RevocationList(this.root.Id, DateTime.Now, DateTime.Now.AddDays(1), new Guid[] { });
              var signedRootCrl = new Signed<RevocationList>(rootCrl, this.root);
              this.storage.AddRevocationList(signedRootCrl);

              this.intermediate = new CACertificate(null, "Intermediate");
              this.intermediate.CreateSelfSignature();
              this.intermediate.AddSignature(this.root, DateTime.Now.AddDays(1));
              this.storage.Add(intermediate.OnlyPublicPart);

              var intermediateCrl = new RevocationList(this.intermediate.Id, DateTime.Now, DateTime.Now.AddDays(1), new Guid[] { });
              var signedIntermediateCrl = new Signed<RevocationList>(intermediateCrl, this.intermediate);
              this.storage.AddRevocationList(signedIntermediateCrl);

              this.admin = new AdminCertificate(Language.English, null, "Test");
              this.admin.CreateSelfSignature();
              this.admin.AddSignature(this.intermediate, DateTime.Now.AddDays(1));

              this.eve = new AdminCertificate(Language.English, null, "Eve");
              this.eve.CreateSelfSignature();
              this.eve.AddSignature(this.intermediate, DateTime.Now.AddDays(1));
        }
Esempio n. 3
0
        public void BadPassphraseTest()
        {
            var root = new CACertificate("test", "Root");
              root.CreateSelfSignature();
              root.Lock();

              root.Unlock("other");
        }
Esempio n. 4
0
        public void MyTestInitialize()
        {
            CACertificate rootCertificate = new CACertificate(null, "Root CA");
              rootCertificate.CreateSelfSignature();
              rootCertificate.Save("root.pi-cert");

              ServerCertificate serverCertificate = new ServerCertificate("Server");
              serverCertificate.CreateSelfSignature();
              serverCertificate.AddSignature(rootCertificate, DateTime.Now.AddDays(1));
              serverCertificate.Save("server.pi-cert");
        }
Esempio n. 5
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. 6
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. 7
0
        public void Set(CACertificate certificate, CertificateStorage certificateStorage)
        {
            this.caInfo.Certificate = certificate;

              int index = 0;
              Height = this.caPanel.Height + this.okPanel.Height + 30;

              foreach (Signature signature in certificate.Signatures)
              {
            SignatureInfoControl signatureInfo = new SignatureInfoControl();
            signatureInfo.Title = string.Format("Parent #{0} Authority", index);
            signatureInfo.Set(signature, certificateStorage);
            signatureInfo.Left = this.caInfo.Left;
            signatureInfo.Top = index * (signatureInfo.Height + 10);
            this.parentsPanel.Controls.Add(signatureInfo);
            Height = (index + 1) * (signatureInfo.Height + 10) + this.caPanel.Height + this.okPanel.Height + 30;
            index++;
              }
        }
Esempio n. 8
0
        public void RevocationTest()
        {
            CertificateStorage storage = new CertificateStorage();

              CACertificate root = new CACertificate(null, "Root");
              root.CreateSelfSignature();
              storage.AddRoot(root.OnlyPublicPart);

              var rootCrl = new RevocationList(root.Id, DateTime.Now, DateTime.Now.AddYears(10), new Guid[] { });
              var signedRootCrl = new Signed<RevocationList>(rootCrl, root);
              storage.AddRevocationList(signedRootCrl);

              CACertificate intermediate = new CACertificate(null, "Intermediate");
              intermediate.CreateSelfSignature();
              intermediate.AddSignature(root, DateTime.Now.AddYears(10));
              storage.Add(intermediate.OnlyPublicPart);

              AdminCertificate test = new AdminCertificate(Language.English, null, "Test");
              test.CreateSelfSignature();
              test.AddSignature(intermediate, DateTime.Now.AddYears(10));

              for (int startDay = 0; startDay < 10; startDay += 2)
              {
            DateTime validFrom = DateTime.Now.AddDays(startDay);
            DateTime validUntil = validFrom.AddDays(1);
            IEnumerable<Guid> revoked = startDay > 5 ? new Guid[] { test.Id } : new Guid[] { };
            var intermediateCrl = new RevocationList(intermediate.Id, validFrom, validUntil, revoked);
            var signedIntermediateCrl = new Signed<RevocationList>(intermediateCrl, intermediate);
            storage.AddRevocationList(signedIntermediateCrl);
              }

              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage, DateTime.Now));
              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage, DateTime.Now.AddDays(1)));
              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage, DateTime.Now.AddDays(2)));
              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage, DateTime.Now.AddDays(3)));
              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage, DateTime.Now.AddDays(4)));
              Assert.AreEqual(CertificateValidationResult.Valid, test.Validate(storage, DateTime.Now.AddDays(5)));

              Assert.AreEqual(CertificateValidationResult.Revoked, test.Validate(storage, DateTime.Now.AddDays(6)));
              Assert.AreEqual(CertificateValidationResult.Revoked, test.Validate(storage, DateTime.Now.AddDays(7)));
              Assert.AreEqual(CertificateValidationResult.Revoked, test.Validate(storage, DateTime.Now.AddDays(8)));
              Assert.AreEqual(CertificateValidationResult.Revoked, test.Validate(storage, DateTime.Now.AddDays(9)));
              Assert.AreEqual(CertificateValidationResult.CrlMissing, test.Validate(storage, DateTime.Now.AddDays(10)));
              Assert.AreEqual(CertificateValidationResult.CrlMissing, test.Validate(storage, DateTime.Now.AddDays(11)));
              Assert.AreEqual(CertificateValidationResult.CrlMissing, test.Validate(storage, DateTime.Now.AddDays(12)));
              Assert.AreEqual(CertificateValidationResult.CrlMissing, test.Validate(storage, DateTime.Now.AddDays(30)));
              Assert.AreEqual(CertificateValidationResult.CrlMissing, test.Validate(storage, DateTime.Now.AddYears(1)));
              Assert.AreEqual(CertificateValidationResult.CrlMissing, test.Validate(storage, DateTime.Now.AddYears(5)));
        }
Esempio n. 9
0
        public void PassphraseTest()
        {
            var root = new CACertificate("test", "Root");
              root.CreateSelfSignature();
              root.Lock();

              root.Unlock("test");

              root.Sign(Encoding.UTF8.GetBytes("hello"));

              root.Lock();
        }
Esempio n. 10
0
        private void KioskForm_Load(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Maximized;

              this.caCertificate = Serializable.Load<CACertificate>(Files.RootCertificateFileName);
              this.controller = new ClientController();
              this.state = controller.State;
              this.run = true;
              this.halted = false;

              Show();

              this.certificateStorageTextBox.Text = "Laden...";

              while (this.run)
              {
            DoWork();
            Application.DoEvents();
            Thread.Sleep(1);
              }

              this.halted = true;

              Close();
        }
Esempio n. 11
0
        private void createToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateCaDialog dialog = new CreateCaDialog();

              if (dialog.ShowDialog() == DialogResult.OK)
              {
            if (dialog.RootCa)
            {
              CaCertificate = new CACertificate(dialog.Passphrase, dialog.CaName);
              CaCertificate.CreateSelfSignature();
              CaCertificate.Save(DataPath(CaCertFileName));
              CertificateStorage.AddRoot(CaCertificate.OnlyPublicPart);
              CertificateStorage.Save(DataPath(StorageFileName));
            }
            else
            {
              OpenFileDialog openDialog = new OpenFileDialog();
              openDialog.Title = "Open Root Certificate Authority Certificate";
              openDialog.CheckPathExists = true;
              openDialog.CheckFileExists = true;
              openDialog.Filter = Files.CertificateFileFilter;

              if (openDialog.ShowDialog() == DialogResult.OK)
              {
            CACertificate caCertificate = Serializable.Load<CACertificate>(openDialog.FileName);
            CertificateStorage.AddRoot(caCertificate);
            CaCertificate = new CACertificate(dialog.Passphrase, dialog.CaName);
            CaCertificate.CreateSelfSignature();
            CaCertificate.Save(DataPath(CaCertFileName));
            CertificateStorage.Add(CaCertificate.OnlyPublicPart);
            CertificateStorage.Save(DataPath(StorageFileName));
              }
            }
              }
        }
Esempio n. 12
0
 /// <summary>
 /// Refuse signature and create response.
 /// </summary>
 /// <param name="caCertificate">Certificate of the CA.</param>
 /// <param name="reason">Reason for refusing to sign.</param>
 public void Refuse(CACertificate caCertificate, string reason)
 {
     SignatureRequest request = RequestValue(caCertificate);
       SignatureResponse response = new SignatureResponse(Request.Certificate.Id, reason);
       Response = new Signed<SignatureResponse>(response, caCertificate);
 }
Esempio n. 13
0
 public bool ContainsToken(string token, CACertificate  caCertificate)
 {
     return
     this.request.FullName.ToLower().Contains(token.ToLower()) ||
     this.certificate.Id.ToString().ToLower().Contains(token.ToLower()) ||
     this.certificate.GetGroupName().ToLower().Contains(token.ToLower());
 }
Esempio n. 14
0
        public ListViewItem CreateItem(CACertificate caCertificate)
        {
            Item = new ListViewItem(this.Certificate.Id.ToString());

              Item.SubItems.Add(this.certificate.ToType().Text());

              if (this.certificate is VoterCertificate)
              {
            Item.SubItems.Add(GroupList.GetGroupName(((VoterCertificate)this.certificate).GroupId));
              }
              else
              {
            Item.SubItems.Add(string.Empty);
              }

              if (request.FamilyName.IsNullOrEmpty())
              {
            Item.SubItems.Add(request.FirstName);
              }
              else
              {
            Item.SubItems.Add(string.Format("{0}, {1}", request.FamilyName, request.FirstName));
              }

              if (this.response == null)
              {
            Item.SubItems.Add(string.Empty);
            Item.SubItems.Add(string.Empty);
            Item.SubItems.Add("New");
              }
              else
              {
            switch (this.response.Status)
            {
              case SignatureResponseStatus.Accepted:
            Item.SubItems.Add(response.Signature.ValidFrom.ToString());
            Item.SubItems.Add(response.Signature.ValidUntil.ToString());

            if (this.entry.Revoked)
            {
              Item.SubItems.Add("Revoked");
            }
            else
            {
              Item.SubItems.Add("Valid");
            }
            break;
              case SignatureResponseStatus.Declined:
            Item.SubItems.Add("N/A");
            Item.SubItems.Add("N/A");
            Item.SubItems.Add("Refused");
            break;
              default:
            break;
            }
              }

              Item.BackColor = BackColor;
              Item.Tag = this;

              return Item;
        }
Esempio n. 15
0
        public void UpdateItem(CACertificate caCertificate)
        {
            Item.Text = this.certificate.Id.ToString();
              Item.SubItems[1].Text = this.certificate.ToType().Text();

              if (this.certificate is VoterCertificate)
              {
            Item.SubItems[2].Text = GroupList.GetGroupName(((VoterCertificate)this.certificate).GroupId);
              }
              else
              {
            Item.SubItems[2].Text = string.Empty;
              }

              if (request.FamilyName.IsNullOrEmpty())
              {
            Item.SubItems[3].Text = request.FirstName;
              }
              else
              {
            Item.SubItems[3].Text = string.Format("{0}, {1}", request.FamilyName, request.FirstName);
              }

              switch (Status)
              {
            case CertificateStatus.Valid:
            case CertificateStatus.NotYet:
            case CertificateStatus.Outdated:
            case CertificateStatus.Revoked:
              SignatureResponse response = this.entry.Response.Value;
              Item.SubItems[4].Text = response.Signature.ValidFrom.ToString();
              Item.SubItems[5].Text = response.Signature.ValidUntil.ToString();
              break;
            case CertificateStatus.Refused:
              Item.SubItems[4].Text = "N/A";
              Item.SubItems[5].Text = "N/A";
              break;
            default:
              Item.SubItems[4].Text = string.Empty;
              Item.SubItems[5].Text = string.Empty;
              break;
              }

              Item.SubItems[6].Text = Status.Text();
              Item.BackColor = BackColor;
        }
Esempio n. 16
0
 public void Sign(CACertificate caCertificate, DateTime validFrom, DateTime validUntil)
 {
     this.entry.Sign(caCertificate, validFrom, validUntil);
       this.response = this.entry.Response.Value;
 }
Esempio n. 17
0
 public void Refuse(CACertificate caCertificate, string reason)
 {
     this.entry.Refuse(caCertificate, reason);
       this.response = this.entry.Response.Value;
 }
Esempio n. 18
0
        public void DataTest()
        {
            CertificateStorage storage = new CertificateStorage();

              CACertificate root = new CACertificate(null, "Root");
              root.CreateSelfSignature();
              storage.AddRoot(root.OnlyPublicPart);

              var rootCrl = new RevocationList(root.Id, DateTime.Now, DateTime.Now.AddDays(1), new Guid[] { });
              var signedRootCrl = new Signed<RevocationList>(rootCrl, root);
              storage.AddRevocationList(signedRootCrl);

              CACertificate intermediate = new CACertificate(null, "Intermediate");
              intermediate.CreateSelfSignature();
              intermediate.AddSignature(root, DateTime.Now.AddDays(1));
              storage.Add(intermediate.OnlyPublicPart);

              var intermediateCrl = new RevocationList(intermediate.Id, DateTime.Now, DateTime.Now.AddDays(1), new Guid[] { });
              var signedIntermediateCrl = new Signed<RevocationList>(intermediateCrl, intermediate);
              storage.AddRevocationList(signedIntermediateCrl);

              AdminCertificate test = new AdminCertificate(Language.English, null, "Test");
              test.CreateSelfSignature();
              test.AddSignature(intermediate, DateTime.Now.AddDays(1));

              byte[] data = test.ToBinary();
              data[data.Length - 3]++;
              AdminCertificate other = Serializable.FromBinary<AdminCertificate>(data);
              Assert.AreEqual(CertificateValidationResult.SelfsignatureInvalid, other.Validate(storage));
        }
Esempio n. 19
0
        /// <summary>
        /// Voting entity test.
        /// </summary>
        /// <remarks>
        /// Used only during development.
        /// </remarks>
        public void EntityTest()
        {
            IRpcConnection connection = new DummyConnection();

              DateTime validUntil = DateTime.Now.AddDays(1);
              var root = new CACertificate(null, "Root");
              root.CreateSelfSignature();
              var rootCrl = new RevocationList(root.Id, DateTime.Now, validUntil, new List<Guid>());
              var sigRootCrl = new Signed<RevocationList>(rootCrl, root);

              var intermediate = new CACertificate(null, "Intermediate");
              intermediate.CreateSelfSignature();
              intermediate.AddSignature(root, validUntil);
              var intCrl = new RevocationList(intermediate.Id, DateTime.Now, validUntil, new List<Guid>());
              var sigIntCrl = new Signed<RevocationList>(intCrl, intermediate);

              var admin = new AdminCertificate(Language.English, null, "Admin");
              admin.CreateSelfSignature();
              admin.AddSignature(intermediate, DateTime.Now.AddDays(1));

              var serverCert = new ServerCertificate("Server");
              serverCert.CreateSelfSignature();
              serverCert.AddSignature(intermediate, DateTime.Now.AddDays(1));

              VotingParameters parameters =
            new VotingParameters(
              new MultiLanguageString("Zufrieden"),
              new MultiLanguageString("Tada"),
              new MultiLanguageString(string.Empty),
              DateTime.Now,
              DateTime.Now.AddDays(1),
              0);
              parameters.GenerateNumbers(Files.TestDataPath);

              Question question = new Question(new MultiLanguageString("Zufrieden?"), new MultiLanguageString(string.Empty), new MultiLanguageString(string.Empty), 1);
              question.AddOption(new Option(new MultiLanguageString("Nein"), new MultiLanguageString("Dagegen"), new MultiLanguageString(string.Empty)));
              question.AddOption(new Option(new MultiLanguageString("Ja"), new MultiLanguageString("Dafür"), new MultiLanguageString(string.Empty)));
              parameters.AddQuestion(question);

              Signed<VotingParameters> signedParameters = new Signed<VotingParameters>(parameters, admin);

              DateTime start = DateTime.Now;
              Console.WriteLine();
              Console.Write("Voting begins...");

              CertificateStorage serverCertStorage = new CertificateStorage();
              serverCertStorage.AddRoot(root);
              serverCertStorage.Add(intermediate);
              serverCertStorage.AddRevocationList(sigRootCrl);
              serverCertStorage.AddRevocationList(sigIntCrl);

              VotingServerEntity vs = new VotingServerEntity(null, signedParameters, serverCertStorage, serverCert);

              var a1c = new AuthorityCertificate(Language.English, "Authority 1", null);
              a1c.CreateSelfSignature();
              a1c.AddSignature(intermediate, validUntil);
              var a2c = new AuthorityCertificate(Language.English, "Authority 2", null);
              a2c.CreateSelfSignature();
              a2c.AddSignature(intermediate, validUntil);
              var a3c = new AuthorityCertificate(Language.English, "Authority 3", null);
              a3c.CreateSelfSignature();
              a3c.AddSignature(intermediate, validUntil);
              var a4c = new AuthorityCertificate(Language.English, "Authority 4", null);
              a4c.CreateSelfSignature();
              a4c.AddSignature(intermediate, validUntil);
              var a5c = new AuthorityCertificate(Language.English, "Authority 5", null);
              a5c.CreateSelfSignature();
              a5c.AddSignature(intermediate, validUntil);

              var a1 = new AuthorityEntity(serverCertStorage, a1c);
              var a2 = new AuthorityEntity(serverCertStorage, a2c);
              var a3 = new AuthorityEntity(serverCertStorage, a3c);
              var a4 = new AuthorityEntity(serverCertStorage, a4c);
              var a5 = new AuthorityEntity(serverCertStorage, a5c);

              vs.AddAuthority(connection, a1.Certificate);
              vs.AddAuthority(connection, a2.Certificate);
              vs.AddAuthority(connection, a3.Certificate);
              vs.AddAuthority(connection, a4.Certificate);
              vs.AddAuthority(connection, a5.Certificate);

              a1.Prepare(1, vs.SignedParameters);
              a2.Prepare(2, vs.SignedParameters);
              a3.Prepare(3, vs.SignedParameters);
              a4.Prepare(4, vs.SignedParameters);
              a5.Prepare(5, vs.SignedParameters);

              a1.SetAuthorities(vs.AuthorityList);
              a2.SetAuthorities(vs.AuthorityList);
              a3.SetAuthorities(vs.AuthorityList);
              a4.SetAuthorities(vs.AuthorityList);
              a5.SetAuthorities(vs.AuthorityList);

              vs.DepositShares(connection, a1.GetShares());
              vs.DepositShares(connection, a2.GetShares());
              vs.DepositShares(connection, a3.GetShares());
              vs.DepositShares(connection, a4.GetShares());
              vs.DepositShares(connection, a5.GetShares());

              var r1 = a1.VerifyShares(vs.GetAllShares());
              var r2 = a2.VerifyShares(vs.GetAllShares());
              var r3 = a3.VerifyShares(vs.GetAllShares());
              var r4 = a4.VerifyShares(vs.GetAllShares());
              var r5 = a5.VerifyShares(vs.GetAllShares());

              vs.DepositShareResponse(connection, r1);
              vs.DepositShareResponse(connection, r2);
              vs.DepositShareResponse(connection, r3);
              vs.DepositShareResponse(connection, r4);
              vs.DepositShareResponse(connection, r5);

              var v1c = new VoterCertificate(Language.English, null, 0);
              v1c.CreateSelfSignature();
              v1c.AddSignature(intermediate, validUntil);

              var cs = new CertificateStorage();
              cs.AddRoot(root);
              var v1 = new VoterEntity(cs);

              IEnumerable<int> questionVota = new int[] { 0, 1 };

              var vote1 = v1.Vote(vs.GetVotingMaterial(), v1c, new IEnumerable<int>[] { questionVota }, null);

              vs.Vote(connection, vote1);

              int voters = 10;

              for (int i = 1000; i < 1000 + voters; i++)
              {
            var vc = new VoterCertificate(Language.English, null, 0);
            vc.CreateSelfSignature();
            vc.AddSignature(intermediate, validUntil);

            var vx = new VoterEntity(cs);

            IEnumerable<int> questionVota2 = new int[] { 0, 1 };
            var votex = vx.Vote(vs.GetVotingMaterial(), vc, new IEnumerable<int>[] { questionVota2 }, null);

            vs.Vote(connection, votex);
              }

              for (int i = 2000; i < 2000 + voters; i++)
              {
            var vc = new VoterCertificate(Language.English, null, 0);
            vc.CreateSelfSignature();
            vc.AddSignature(intermediate, validUntil);

            var vx = new VoterEntity(cs);

            IEnumerable<int> questionVota3 = new int[] { 1, 0 };
            var votex = vx.Vote(vs.GetVotingMaterial(), vc, new IEnumerable<int>[] { questionVota3 }, null);

            vs.Vote(connection, votex);
              }

              vs.EndVote();

              a1.TallyBegin(vs.GetVotingMaterial());
              a2.TallyBegin(vs.GetVotingMaterial());
              a3.TallyBegin(vs.GetVotingMaterial());
              a4.TallyBegin(vs.GetVotingMaterial());
              a5.TallyBegin(vs.GetVotingMaterial());

              for (int envelopeIndex = 0; envelopeIndex < vs.GetEnvelopeCount(); envelopeIndex++)
              {
            a1.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a2.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a3.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a4.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a5.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
              }

              var pd1 = a1.PartiallyDecipher();
              var pd2 = a2.PartiallyDecipher();
              var pd3 = a3.PartiallyDecipher();
              var pd4 = a4.PartiallyDecipher();
              var pd5 = a5.PartiallyDecipher();

              vs.DepositPartialDecipher(connection, pd1);
              vs.DepositPartialDecipher(connection, pd2);
              vs.DepositPartialDecipher(connection, pd3);
              vs.DepositPartialDecipher(connection, pd4);
              vs.DepositPartialDecipher(connection, pd5);

              v1.TallyBegin(vs.GetVotingMaterial(), BaseParameters.StandardProofCount);

              for (int envelopeIndex = 0; envelopeIndex < vs.GetEnvelopeCount(); envelopeIndex++)
              {
            v1.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
              }

              for (int authorityIndex = 1; authorityIndex < vs.Parameters.AuthorityCount + 1; authorityIndex++)
              {
            v1.TallyAddPartialDecipher(vs.GetPartialDecipher(authorityIndex));
              }

              var res1 = v1.TallyResult;

              TimeSpan duration = DateTime.Now.Subtract(start);
              Console.WriteLine("Succeded {0}", duration.ToString());
        }
Esempio n. 20
0
 /// <summary>
 /// Creates a copy of the certificate.
 /// </summary>
 /// <param name="original">Original certificate to copy.</param>
 /// <param name="onlyPublicPart">Leave the private key part out?</param>
 protected CACertificate(CACertificate original, bool onlyPublicPart)
     : base(original, onlyPublicPart)
 {
     this.fullName = original.fullName;
 }
Esempio n. 21
0
 /// <summary>
 /// Signs the certificates and create response
 /// </summary>
 /// <param name="caCertificate">Certificate of the CA.</param>
 /// <param name="validUntil">Signature valid from.</param>
 /// <param name="validUntil">Signature valid until.</param>
 public void Sign(CACertificate caCertificate, DateTime validFrom, DateTime validUntil)
 {
     SignatureRequest request = RequestValue(caCertificate);
       Signature signature = Certificate.AddSignature(caCertificate, validFrom, validUntil);
       SignatureResponse response = new SignatureResponse(Request.Certificate.Id, signature);
       Response = new Signed<SignatureResponse>(response, caCertificate);
 }