Example #1
0
        private void openExamBtn_Click(object sender, EventArgs e)
        {
            try
            {
                Random         r          = new Random();
                OpenFileDialog opendialog = new OpenFileDialog();
                opendialog.Filter       = "FCT Exam File (*.FCTEX)|*.FCTEX";
                opendialog.DefaultExt   = "FCTEX";
                opendialog.AddExtension = true;
                requiredDetails         = new RequiredDetails(studentNameTxtBox.Text, studentIDTxtBox.Text, studentPassTxtBox.Text, "TODO");
                if (opendialog.ShowDialog() == DialogResult.OK)
                {
                    var examStringEncrypted = ExamHelper.GetExamFileAsBytes(opendialog.FileName);
                    anExam = ExamHelper.GetExamFromFile(opendialog.FileName, studentPassTxtBox.Text, "", Security.FilterationSecurityLevel.Moderate);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


            if (anExam == null)
            {
                MessageBox.Show("Invalid Exam");
                return;
            }

            PrepareExamEnvironment();
        }
Example #2
0
 public FilterationResult IsValidRequest(RequiredDetails details, string srcIP)
 {
     if (SecurityLevel == FilterationSecurityLevel.Moderate)
     {
         return(ModerateFilterationProcessRequest(details));
     }
     else if (SecurityLevel == FilterationSecurityLevel.High)
     {
         return(HighFilterationProcessRequest(details, srcIP));
     }
     return(FilterationResult.DroppedUnknown); //Fail Safe
 }
Example #3
0
        private FilterationResult ModerateFilterationProcessRequest(RequiredDetails details)
        {
            if (!IsValidExamKey(details))
            {
                return(FilterationResult.InvalidSharedExamKey);
            }

            //AddEntryToTrackingList(details); // to be checked in submision phase, WE REMOVE THIS TO MAKE TEH SERVER STATELESS


            return(FilterationResult.Accepted);
        }
Example #4
0
        public void GetExamCopy()
        {
            //  try
            {
                HighSecurity = highSecChkBox.Checked;
                //Create a client to connecto to phone book service on local server and
                //10048 TCP port.
                client = ScsServiceClientBuilder.CreateClient <INetworkExamService>(
                    new ScsTcpEndPoint(ipTxtBox.Text, int.Parse(portTxtBox.Text)));

                // client.Timeout = 3;
                aLogger.LogMessage($"Trying to connect to the server (timeout {client.Timeout} Seconds)", LogMsgType.Verbose);
                //Connect to the server
                client.Connect();

                aLogger.LogMessage("Connected to server", LogMsgType.Verbose);


                RequiredDetails requiredDetails = new RequiredDetails(studentNameTxtBox.Text, studentIDTxtBox.Text, examKeyTxtBox.Text, (HighSecurity? sharedKeyISTxtBox.Text:"Low Security Settings Selected"));
                //Add some persons
                var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails);
                requiredDetails.DecryptDetails(examKeyTxtBox.Text);
                if (!ExamHelper.ValidateExamCopy(copy, examKeyTxtBox.Text, aLogger, sharedKeyISTxtBox.Text,
                                                 (highSecChkBox.Checked ? Security.FilterationSecurityLevel.High : Security.FilterationSecurityLevel.Moderate), requiredDetails.SequenceNumber))
                {
                    return;
                }

                aLogger.LogMessage("Received Exam Copy", LogMsgType.Verbose);

                aLogger.LogMessage("Checking Exam Copy...", LogMsgType.Verbose);

                var exam = Quizez.ExamHelper.GetExamFromByteArray(copy, examKeyTxtBox.Text, sharedKeyISTxtBox.Text,
                                                                  (highSecChkBox.Checked?Security.FilterationSecurityLevel.High:Security.FilterationSecurityLevel.Moderate));

                aLogger.LogMessage("Exam Checked Correcly ...", LogMsgType.Verbose);

                //Disconnect from server
                //   client.Disconnect();

                //  aLogger.LogMessage("Disconnected from server", LogMsgType.Verbose);

                anExam = exam;
            }
            // catch (Exception ex)
            {
                //  aLogger.LogMessage(ex.Message, LogMsgType.Error);
            }
        }
Example #5
0
        private bool IsValidSrcIP(RequiredDetails details, ExaminationFilterRule rule, string srcIP)
        {
            if (rule.AllowSpecificIPs == false) //no filteration required
            {
                return(true);
            }

            foreach (var ipRule in rule.AllowedIPs)
            {
                if (srcIP == ipRule) // TODO:: implement subnets filteration
                {
                    return(true);
                }
            }
            return(false);
        }
Example #6
0
        //private void AddEntryToTrackingList(RequiredDetailsForSendingExam details)
        //{
        //    try {

        //        var iV = new InstructorValidationData(details.StudentID, Guid.NewGuid(), DateTime.Now, int.Parse(details.SequenceNumber) + 1);
        //    TrackingEntry entry = new TrackingEntry(details.StudentID, details.SequenceNumber,iV);

        //    lock (TrackingList)
        //    {
        //        TrackingList.Add(details.StudentID, entry);
        //    }
        //    }
        //    catch(Exception ex)
        //    {
        //        aLogger.LogMessage(ex.Message + "[exception in AddEntryToTrackingList]", LogMsgType.Error);
        //        throw ex;
        //    }
        //}

        private InstructorValidationData GetIV(RequiredDetails details)
        {
            try
            {
                Random r = new Random();

                var iV = new InstructorValidationData(details.StudentID,
                                                      DateTime.Now, int.Parse(details.SequenceNumber), int.Parse(details.SequenceNumber) + 1);
                //    TrackingEntry entry = new TrackingEntry(details.StudentID, details.SequenceNumber, iV);
                return(iV);
            }
            catch (Exception ex)
            {
                //  aLogger.LogMessage(ex.Message + "[exception in GetIV]", LogMsgType.Error);
                throw ex;
            }
        }
Example #7
0
        public FilterationResult IsValidSubmission(RequiredDetails details, string srcIP)
        {
            details.DecryptDetails(ExamKey);


            if (SecurityLevel == FilterationSecurityLevel.Moderate)
            {
                return(ModerateFilterationProcessSubmit(details));
            }
            else if (SecurityLevel == FilterationSecurityLevel.High)
            {
                return(HighFilterationProcessRequestSubmit(details, srcIP));
            }


            return(FilterationResult.DroppedUnknown); //Fail Safe
        }
Example #8
0
        private FilterationResult HighFilterationProcessRequestSubmit(RequiredDetails details, string srcIP)
        {
            var basicFilteration = HighFilterationProcessRequest(details, srcIP);

            if (basicFilteration != FilterationResult.Accepted)
            {
                return(basicFilteration);
            }

            var ivFel = ValidateIV(details);

            if (ivFel != FilterationResult.Accepted)
            {
                return(ivFel);
            }

            return(FilterationResult.Accepted);
        }
Example #9
0
        private FilterationResult ModerateFilterationProcessSubmit(RequiredDetails details)
        {
            var basicFilteration = ModerateFilterationProcessRequest(details);

            if (basicFilteration != FilterationResult.Accepted)
            {
                return(basicFilteration);
            }



            var ivFel = ValidateIV(details);

            if (ivFel != FilterationResult.Accepted)
            {
                return(ivFel);
            }



            return(FilterationResult.Accepted);
        }
Example #10
0
        private FilterationResult ValidateIV(RequiredDetails details)
        {
            var ReceivedV = details.GetV(InstructorPassword);

            if (ReceivedV == null)
            {
                return(FilterationResult.InvalidSubmissionInstructorValidation);
            }

            //if(ReceivedV.GetNonce ==  )//Nonce is not needed because now stateless

            if (ReceivedV.StdID != details.StudentID)
            {
                return(FilterationResult.InvalidStdID_ImpersonationAttack);
            }

            if (int.Parse(details.SequenceNumber) != ReceivedV.GetIncrementedSN + 1)
            {
                return(FilterationResult.InvalidSequenceNumber);
            }

            return(FilterationResult.Accepted);
        }
Example #11
0
        private FilterationResult HighFilterationProcessRequest(RequiredDetails details, string srcIP)
        {
            // Valid Exam Key by decripting the request message details
            if (!IsValidExamKey(details))
            {
                return(FilterationResult.InvalidSharedExamKey);
            }

            //Check if the studnet is listed in the firewall list



            if (!Rules.ContainsKey(details.StudentID))  //this means student is not listed, the fail safe drop it
            {
                return(FilterationResult.StudentIsNotListedInFirewallRules);
            }

            //find the specific filteration rule for that student based on ID
            var specificRule = Rules[details.StudentID];

            //check if it is a valid KeyIS
            if (!IsValidSharedKeyIS(details, specificRule))
            {
                return(FilterationResult.InvalidSharedStudentKeyIS);
            }


            if (!IsValidSrcIP(details, specificRule, srcIP))
            {
                return(FilterationResult.InvalidSrcIP);
            }

            //AddEntryToTrackingList(details); // to be checked in submision phase


            return(FilterationResult.Accepted);
        }
Example #12
0
 private bool IsValidExamKey(RequiredDetails details)
 {
     return(details.ExamKey == ExamKey);
 }
Example #13
0
        public FilterationRequestResult GenerateExamCopyForSendingToStudent(Exam orgExamCopyEmpty, RequiredDetails details, string srcIP)
        {
            details.DecryptDetails(ExamKey);



            var filterResult = IsValidRequest(details, srcIP);

            if (filterResult != FilterationResult.Accepted)
            {
                throwFirewallException(filterResult, $"IP:{srcIP}");
                return(new FilterationRequestResult(filterResult, null));
            }
            var v = GetIV(details);

            details.SequenceNumber   = (long.Parse(details.SequenceNumber) + 1).ToString();
            details.VEncryptedWithKI = ExamHelper.GetVAsByteArray(v, InstructorPassword);

            var examInstance = orgExamCopyEmpty;

            examInstance.RequiredStudentDetails = details; //we received this from the student


            // examInstance.RequiredStudentDetails.SetV_CompressedEncryptedWithKI(v, InstructorPassword);

            //if(examInstance.RequiredStudentDetails.VEncryptedWithKI== null)
            //{
            //    MessageBox.Show("Set To Null");
            //}
            //else
            //{
            //    MessageBox.Show("examInstance.RequiredStudentDetails.VEncryptedWithKI");
            //}

            return(new FilterationRequestResult(filterResult, ExamHelper.GetExamFileWithoutSave(examInstance, ExamKey, details.SharedKeyIS, SecurityLevel)));
        }
Example #14
0
 /// <summary>
 /// this method protects against impersonation
 /// </summary>
 /// <param name="details"></param>
 /// <param name="rule"></param>
 /// <returns></returns>
 private bool IsValidStudentID(RequiredDetails details, ExaminationFilterRule rule)
 {
     return(details.StudentID == details.StudentID);
 }
Example #15
0
        private bool IsValidSharedKeyIS(RequiredDetails details, ExaminationFilterRule rule)
        {
            details.DecryptSharedKey(rule.SharedKeyIS);

            return(details.SharedKeyIS == rule.SharedKeyIS);
        }
Example #16
0
        private void PerformTest(TestType type, int numOfQ, int numOfStd)
        {
            TestParameters submitParam  = new TestParameters();
            TestParameters receiveParam = new TestParameters();

            submitParam.MethodCallCount   = int.Parse(numberOfTimesTxtBox.Text);
            submitParam.NumberOfQuestions = numOfQ;
            submitParam.NumberOfStudent   = numOfStd;

            receiveParam.MethodCallCount   = int.Parse(numberOfTimesTxtBox.Text);
            receiveParam.NumberOfQuestions = numOfQ;
            receiveParam.NumberOfStudent   = numOfStd;

            var secucirytLevel = highSecChkBox.Checked ? FilterationSecurityLevel.High : FilterationSecurityLevel.Moderate;
            var endpoint       = new ScsTcpEndPoint(ipTxtBox.Text, int.Parse(portTxtBox.Text));
            SortedList <string, string> ExamsReceived = new SortedList <string, string>();

            var stopwatchReceiving = Stopwatch.StartNew();

            Parallel.For(0, numOfStd, index =>
            {
                using (var client = ScsServiceClientBuilder.CreateClient <INetworkExamServiceTesting>(endpoint))
                {
                    var val     = index % numOfStd;
                    var keyUsed = $"Keyyyyyyy{val}";
                    //STEP 1 -- Only get exam copy
                    client.Connect();
                    var requiredDetails = new RequiredDetails($"StdName{val}", $"Std{val}", "123456", keyUsed, 1);
                    try
                    {
                        var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails, numOfQ, numOfStd);
                        lock (ExamsReceived)
                        {
                            if (!ExamsReceived.Keys.Contains(keyUsed))
                            {
                                ExamsReceived.Add(keyUsed, copy);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        lock (receiveParam)
                        {
                            receiveParam.DroppedMessages += 1;
                        }
                    }
                }
            });
            List <Task> tasksReq = new List <Task>();

            Parallel.For(0, receiveParam.MethodCallCount - numOfStd, index =>
                         //  for (int index = 0; index < param.MethodCallCount; index++)
            {
                var t = Task.Run(() =>
                {
                    using (var client = ScsServiceClientBuilder.CreateClient <INetworkExamServiceTesting>(endpoint))
                    {
                        var val     = index % numOfStd;
                        var keyUsed = $"Keyyyyyyy{val}";
                        //STEP 1 -- Only get exam copy
                        client.Connect();
                        var requiredDetails = new RequiredDetails($"StdName{val}", $"Std{val}", "123456", keyUsed, 1);
                        try
                        {
                            var copy = client.ServiceProxy.GetExamCopyEncryptedZipped(requiredDetails, numOfQ, numOfStd);
                        }
                        catch (Exception ex)
                        {
                            lock (receiveParam)
                            {
                                receiveParam.DroppedMessages += 1;
                            }
                        }
                    }
                });
                lock (tasksReq)
                {
                    tasksReq.Add(t);
                }
            }
                         );
            Task.WaitAll(tasksReq.ToArray());
            stopwatchReceiving.Stop();
            receiveParam.TimeRequired = stopwatchReceiving;
            ReceivingResults.Add(receiveParam);


            SortedList <string, KeyValuePair <RequiredDetails, string> > ExamsToSubmit = new SortedList <string, KeyValuePair <RequiredDetails, string> >();

            if (type == TestType.SubmitExam || type == TestType.Both) // we need to answer and submit aswell
            {
                //  List<KeyValuePair<RequiredDetails, string>> ExamsToSubmit = new List<KeyValuePair<RequiredDetails, string>>();
                Parallel.For(0, numOfStd, index =>
                {
                    var val     = index % numOfStd;
                    var keyUsed = $"Keyyyyyyy{val}";
                    //STEP 2 : Answering the EXAM (assuming all students will have the same answers)
                    var examCopyUnencrypted     = ExamHelper.GetExamFromByteArray(ExamsReceived[keyUsed], "123456", keyUsed, secucirytLevel);
                    examCopyUnencrypted.ExamLog = new List <string>();
                    examCopyUnencrypted.RequiredStudentDetails.SequenceNumber = (long.Parse(examCopyUnencrypted.RequiredStudentDetails.SequenceNumber) + 1).ToString();
                    var rD            = examCopyUnencrypted.RequiredStudentDetails;
                    var examEncrypted = ExamHelper.GetExamFileWithoutSave(examCopyUnencrypted, "123456", keyUsed, secucirytLevel);
                    rD.EncryptDetails();
                    lock (ExamsToSubmit)
                    {
                        if (!ExamsToSubmit.Keys.Contains(keyUsed))
                        {
                            ExamsToSubmit.Add(keyUsed, new KeyValuePair <RequiredDetails, string>(rD, examEncrypted));
                        }
                    }
                });


                ExamsReceived = null;
                var stopwatchSubmitting = Stopwatch.StartNew();
                //step 3 Submit (we want to measure only this


                List <Task> tasks = new List <Task>();


                Parallel.For(0, submitParam.MethodCallCount, index =>
                {
                    var t = Task.Run(() =>
                    {
                        var val     = index % numOfStd;
                        var keyUsed = $"Keyyyyyyy{val}";
                        try
                        {
                            using (var clientSubmit = ScsServiceClientBuilder.CreateClient <INetworkExamServiceTesting>(endpoint))
                            {
                                clientSubmit.Connect();
                                clientSubmit.ServiceProxy.SubmitExamEncryptedZipped(ExamsToSubmit[keyUsed].Value, ExamsToSubmit[keyUsed].Key, numOfQ, numOfStd);
                            }
                        }
                        catch (Exception ex)
                        {
                            lock (submitParam)
                            {
                                submitParam.DroppedMessages += 1;
                            }
                        }
                    });
                    lock (tasks)
                    {
                        tasks.Add(t);
                    }
                });

                Task.WaitAll(tasks.ToArray());
                stopwatchSubmitting.Stop();
                submitParam.TimeRequired = stopwatchSubmitting;
                SubmissionResults.Add(submitParam);
            }
        }