Пример #1
0
        public void Do_DOB_Twenty_Years_Ago_And_EffectiveDate_One_Hundred_Years_Ago_Returns_True()
        {
            //Arrange
            var model = new EnrollmentRecord
            {
                DOB           = DateTime.Now.AddYears(-20),
                EffectiveDate = DateTime.Now.AddYears(-100)
            };

            var sut = new EnrollmentDateRules();

            //Act
            var result = sut.Do(model);

            //Assert
            Assert.IsTrue(result);
        }
Пример #2
0
        public void Do_DOB_Eighteen_Years_In_The_Future_And_EffectiveDate_Now_Returns_False()
        {
            //Arrange
            var model = new EnrollmentRecord
            {
                DOB           = DateTime.Now.AddYears(18),
                EffectiveDate = DateTime.Now
            };

            var sut = new EnrollmentDateRules();

            //Act
            var result = sut.Do(model);

            //Assert
            Assert.IsFalse(result);
        }
Пример #3
0
        public void Do_DOB_Nineteen_Years_Ago_And_EffectiveDate_Now_Returns_True()
        {
            //Arrange
            var model = new EnrollmentRecord
            {
                DOB           = DateTime.Now.AddYears(-19),
                EffectiveDate = DateTime.Now
            };

            var sut = new EnrollmentDateRules();

            //Act
            var result = sut.Do(model);

            //Assert
            Assert.IsTrue(result);
        }
Пример #4
0
        public void Do_DOB_Twenty_Years_Ago_And_EffectiveDate_Thirty_One_Days_In_Future_Returns_False()
        {
            //Arrange
            var model = new EnrollmentRecord
            {
                DOB           = DateTime.Now.AddYears(-20),
                EffectiveDate = DateTime.Now.AddDays(31)
            };

            var sut = new EnrollmentDateRules();

            //Act
            var result = sut.Do(model);

            //Assert
            Assert.IsFalse(result);
        }
Пример #5
0
        /// <summary>
        /// Creates EnrollmentRecord which is then supposed to be stored in  database for further authentication
        /// Also generates a key which then can be used to protect user's data.
        /// </summary>
        /// <returns>The account.</returns>
        /// <param name="pwdBytes">Password bytes.</param>
        /// <param name="pheRespData">Phe resp data.</param>
        public (byte[], byte[]) EnrollAccount(byte[] pwdBytes, byte[] pheRespData)
        {
            Validation.NotNullOrEmptyByteArray(pwdBytes);
            Validation.NotNullOrEmptyByteArray(pheRespData);

            var pheResp = Phe.EnrollmentResponse.Parser.ParseFrom(ByteString.CopyFrom(pheRespData));

            var isValid = this.Crypto.ValidateProofOfSuccess(
                pheResp.Proof,
                this.ServicePublicKey,
                pheResp.Ns.ToByteArray(),
                pheResp.C0.ToByteArray(),
                pheResp.C1.ToByteArray());

            if (!isValid)
            {
                throw new ProofOfSuccessNotValidException();
            }

            var nS = pheResp.Ns;
            var nC = this.Crypto.GenerateNonce();

            var(t0, t1, key) = this.Crypto.ComputeT(
                this.AppSecretKey,
                pwdBytes,
                nC,
                pheResp.C0.ToByteArray(),
                pheResp.C1.ToByteArray());

            var enrollmentRecord = new EnrollmentRecord
            {
                Nc = ByteString.CopyFrom(nC),
                Ns = nS,
                T0 = ByteString.CopyFrom(t0),
                T1 = ByteString.CopyFrom(t1),
            };

            return(enrollmentRecord.ToByteArray(), key);
        }
Пример #6
0
        /// <summary>
        /// Update the specified EnrollmentRecord record.
        /// </summary>
        /// <returns>The updated Encrypted EnrollmentRecord.</returns>
        public byte[] UpdateEnrollmentRecord(byte[] token, byte[] enrollmentRecordData)
        {
            Validation.NotNullOrEmptyByteArray(token);
            Validation.NotNullOrEmptyByteArray(enrollmentRecordData);

            var enrollmentRecord = EnrollmentRecord.Parser.ParseFrom(ByteString.CopyFrom(enrollmentRecordData));

            var(t0, t1) = this.Crypto.UpdateT(
                enrollmentRecord.Ns.ToByteArray(),
                enrollmentRecord.T0.ToByteArray(),
                enrollmentRecord.T1.ToByteArray(),
                token);

            var updatedEnrollmentRecord = new EnrollmentRecord
            {
                Nc = enrollmentRecord.Nc,
                Ns = enrollmentRecord.Ns,
                T0 = ByteString.CopyFrom(t0),
                T1 = ByteString.CopyFrom(t1),
            };

            return(updatedEnrollmentRecord.ToByteArray());
        }
Пример #7
0
        private async Task SynEnrollmentData()
        {
            var progressHandler = new Progress <int>(value =>
            {
                labelTotalSuccess.Text = value.ToString();
            });
            var progress = (IProgress <int>)progressHandler;

            //Download User Profiles
            toolStripStatusLabel.Text = @"Searching and Downloading New User Profiles, Please Wait... ";
            await Task.Run(() => DatabaseOpperations.DownloadNewUserProfiles());

            toolStripStatusLabel.Text = @"User Profiles Update Completed ";

            if (_UserProfile == null)
            {
                toolStripStatusLabel.Text = @"Sync Job Terminated, User Must Login";
                return;
            }

            //Scroll through records in result
            if (_BaseDatas.Any())
            {
                toolStripStatusLabel.Text = @"Sync Job Processing, Please Wait...";
                var startDate = DateTime.Now;
                labelSyncStartTime.Text = startDate.ToString("dd/MM/yyyy hh:mm tt");
                DisableUI(false);

                //0. Create Entry into the SyncJobLog
                var syncJobId = DatabaseOpperations.CreateSyncJobSession(_UserProfile, startDate);

                //1. Find User Custom Datas
                var i = 0;//This is the counter to Updating UI on total Completed So For
                _BaseDatas.ForEach(async res =>
                {
                    var enrollmentRecordInfo = await Task.Run(() =>
                    {
                        try
                        {
                            var enrollmentRecordDetails = new EnrollmentRecord
                            {
                                CustomDatas         = DatabaseOpperations.GetEnrolleeCustomData(res.EnrollmentId),
                                Photograph          = DatabaseOpperations.GetEnrolleePhotoGraph(res.EnrollmentId),
                                FingerprintTemplate = DatabaseOpperations.GetEnrolleeFingerprintTemplate(res.EnrollmentId),
                                FingerprintImages   = DatabaseOpperations.GetEnrolleeFingerprintImages(res.EnrollmentId),
                                Signature           = DatabaseOpperations.GetEnrolleeSignature(res.EnrollmentId)
                            };
                            return(enrollmentRecordDetails);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            return(new EnrollmentRecord());
                        }
                    });

                    if (enrollmentRecordInfo == null || !enrollmentRecordInfo.CustomDatas.Any())
                    {
                        MessageBox.Show(@"An error was encountered. Data to be synchronised could not be retrieved");
                        return;
                    }

                    enrollmentRecordInfo.BaseData = res;

                    if (!enrollmentRecordInfo.CustomDatas.Any())
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised with empty Custom data!");
                        return;
                    }

                    if (!enrollmentRecordInfo.FingerprintImages.Any())
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised without Fingerprints");
                        return;
                    }

                    if (string.IsNullOrEmpty(enrollmentRecordInfo.Photograph?.EnrollmentId))
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised without Fingerprints");
                        return;
                    }

                    await Task.Run(() => DatabaseOpperations.SynchroniseDataToServer(enrollmentRecordInfo));

                    //5. Update Local Database SyncJobHistoy for specific Record
                    DatabaseOpperations.UpdateDbSyncHistory(syncJobId, res.EnrollmentId);

                    i++; // IncreamentItems Completed Counter
                    if (progress != null)
                    {
                        progress.Report(i);
                    }
                });

                //6. Log Sync End Time for Sync Job
                DatabaseOpperations.CloseSyncJobSession(syncJobId);
                toolStripStatusLabel.Text = @"Sync Job Completed Succesfully";
                labelSyncEndTime.Text     = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
                DisableUI(true);
            }
            else
            {
                toolStripStatusLabel.Text = @"No Records to Synchronize. Try Applying a Filter.";
            }
        }