This class holds all an ID holders information. In the case of this project, candidate is synonomyous with ID holder and client.
Наследование: IPackable, IUnpackable
Пример #1
0
        /// <summary>
        ///     Enroll a candidate a to Factom. A new chain is created and the candidate data is packed and split into entries for
        ///     that chain.
        ///     This operation is irreversable.
        /// </summary>
        /// <param name="c">The candidate to enroll</param>
        /// <param name="password">The password provided by the candidate</param>
        /// <param name="privKey">The private key to pack the data with</param>
        /// <returns>The chain ID of the enrolled candidate</returns>
        public static byte[] EnrollCandidate(Candidate c, string password, RSAParameters privKey)
        {
            var packed = Pack(c, password, privKey);

            Chain.ChainType factomChain = null;

            foreach (
                var segment in
                    DataSegment.Segmentize(packed,
                        firstSegmentLength: DataSegment.DefaultMaxSegmentLength - ExtIDsLength)) {
                var dataToUpload = segment.Pack();
                var factomEntry = Entry.NewEntry(dataToUpload, null, null);
                if (segment.CurrentSegment == 0) {
                    //New chain
                    factomEntry.ExtIDs = GenerateExtIDs(packed);
                    factomChain = Chain.NewChain(factomEntry);
                    Chain.CommitChain(factomChain, FactomWallet); // Wallet Name
                    Thread.Sleep(10100);
                    Chain.RevealChain(factomChain);
                }
                else {
                    //new entry
                    Debug.Assert(factomChain != null, "factomChain != null");
                    factomEntry.ChainId = factomChain.ChainId;
                    Entry.CommitEntry(factomEntry, FactomWallet);
                    Thread.Sleep(10100);
                    Entry.RevealEntry(factomEntry);
                }
            }

            return factomChain.ChainId;
        }
Пример #2
0
        public void LoadCandidateInfo(byte[] packed, string pasword, byte[] chainId = null)
        {
            try {
                _c = CandidateDelegate.Unpack(packed, pasword, _publicKey);
            }
                // ReSharper disable once UnusedVariable
            catch (Exception ex) {
                MessageBox.Show(Resources.NOT_VERIFY_ID_ERROR);
                Close();
                return;
            }

            headshotBox.Image = _c.Image;
            candidateDump.Text = JsonConvert.SerializeObject(_c, Formatting.Indented);

            if (chainId != null) {
                chainHistory.View = View.List;
                foreach (var cid in CandidateDelegate.GetCandidateChainHistory(chainId, _publicKey)) {
                    chainHistory.Items.Add(new ListViewItem(Convert.ToBase64String(cid)));
                }
            }
        }
Пример #3
0
        /// <summary>
        ///     Verify a candidates fingerprint
        /// </summary>
        /// <param name="c">The candidate to compare against</param>
        /// <param name="fp">The provided fingerprint</param>
        /// <returns>A float from 0 to 100 which represents the strength of the fingerprint match. Higher is better.</returns>
        public static float VerifyFingerprint(Candidate c, Fingerprint fp)
        {
            var afis = new AfisEngine();

            var test = new Person(fp);
            afis.Extract(test);

            var candidate = new Person(c.Fingerprint);

            return afis.Verify(candidate, test);
        }
Пример #4
0
        /// <summary>
        ///     - Verifies that we are allowed to update this chain
        ///     - Enrolls a new candidate chain with a CandidateOldVersionRecord referencing the old chain
        ///     - Adds a OldVersionRecord to the old chain referencing the new chain
        ///     - Adds a ChainUpdateRecord to the chain requesting update, forwarding it to the new chain.
        ///     This operation is irreversable.
        /// </summary>
        /// <param name="newCandidate">The updated candidate information</param>
        /// <param name="password">The password provided by the candidate</param>
        /// <param name="fp">The fingerprint to verify against</param>
        /// <param name="privKey">The private key to pack the data with</param>
        /// <param name="chainToUpdate">The chain ID of the chain to be updated</param>
        /// <returns>The chain ID pointing to the updated candidate</returns>
        public static byte[] UpdateCandidate(Candidate newCandidate, string password, Fingerprint fp,
            RSAParameters privKey, byte[] chainToUpdate)
        {
            if (FullVerifyFromChain(chainToUpdate, password, fp, privKey) < 50f)
                throw new AccessConfidenceTooLowException("Access confidence too low to update candidate.");

            var newChainId = EnrollCandidate(newCandidate, password, privKey);

            var ovr = new CandidateOldVersionRecord(chainToUpdate, newChainId);
            var cur = new CandidateUpdatedRecord(chainToUpdate, newChainId);

            var oldRecordEntry = Entry.NewEntry(ovr.Pack(privKey), null, newChainId);
            var newRecordEntry = Entry.NewEntry(cur.Pack(privKey), null, chainToUpdate);

            Entry.CommitEntry(oldRecordEntry, FactomWallet);
            Entry.CommitEntry(newRecordEntry, FactomWallet);

            Thread.Sleep(10100);

            Entry.RevealEntry(oldRecordEntry);
            Entry.RevealEntry(newRecordEntry);

            return newChainId;
        }
Пример #5
0
        /// <summary>
        ///     Pack a candidate object into storable data
        /// </summary>
        /// <param name="c">The candidate object to pack</param>
        /// <param name="password">The password provided by the candidate</param>
        /// <param name="privKey">The private key to sign the data with</param>
        /// <returns></returns>
        public static byte[] Pack(Candidate c, string password, RSAParameters privKey)
        {
            // Serialize with MsgPack
            var data = c.Serialize();

            // Encrypted serialized data with password
            data = Crypto.AES_Encrypt(data, password);

            // Generate a unique ID by hashing the encrypted serialized data
            var uid = SHA512.Create().ComputeHash(data);

            // Append the uid to the front of encrypted data
            data = uid.Concat(data).ToArray();

            // Sign the data and append the RSA signature to the end
            data = data.Concat(Crypto.RSA_Sign(data, privKey)).ToArray();

            return data;
        }
Пример #6
0
        private void SetCandidate(Candidate c, byte[] packed)
        {
            output = packed;

            lastName.Text = c.Dcs;
            firstName.Text = c.Dac;
            middleName.Text = c.Dad;
            issued.Value = c.Dbd;
            dob.Value = c.Dbb;
            sex.SelectedIndex = (int) c.Dbc - 1;
            eye.SelectedIndex = (int) c.Day;
            inches.Value = c.Dau.Inches;
            feet.Value = c.Dau.Feet;
            address.Text = c.Dag;
            city.Text = c.Dai;
            state.Text = c.Daj;
            zipcode.Text = c.Dak.AnsiFormat;
            country.Text = c.Dcg;
            headshotBox.Image = c.Image;

            password.Text = "";
            confirmPassword.Text = "";

            _c = c;
        }
Пример #7
0
 /// <summary>
 ///     Creates a new CardGenerator instance
 /// </summary>
 /// <param name="cardCandidate">The candidate to create the card for</param>
 /// <param name="pdfTemplateFile">The PDF template to generate the card</param>
 public CardGenerator(Candidate cardCandidate, string pdfTemplateFile)
 {
     _cardCandidate = cardCandidate;
     _pdfTemplateFile = pdfTemplateFile;
 }