Exemplo n.º 1
0
        public static VerificationResults VerifyAndGetResults(VerificationParameters parameters)
        {
            var result = XmlDsigVerifyOperation.VerifyAndGetResults(parameters);

            VerifySigningCertificate(parameters, result.SigningCertificate);
            return(result);
        }
Exemplo n.º 2
0
        public void ReprocessVerification(VerificationParameters parameters, IRecognitionForm ans, List <IRecognitionForm> res)
        {
            extractor = new ExtractReviewCollectionOperation(answers, results, verificationParameters);
            extractor.Start();

            this.answerReviewCounts = extractor.AnswerReviewCount;
            this.resultReviewCounts = extractor.ResultsReviewCount;
        }
        public ExtractReviewCollectionOperation(IRecognitionForm answers, List <IRecognitionForm> forms, VerificationParameters verificationParameters) : base()
        {
            this.answers = answers;
            this.forms   = forms;

            this.verificationParameters = verificationParameters;

            useWaitWindow = false;
        }
Exemplo n.º 4
0
        public ReviewParameters(List <string> list, List <string> errors, string answerVals, string id, VerificationParameters erroredParams, int pageNumber)
        {
            this.omrValues     = list;
            this.errors        = errors;
            this.answerVals    = answerVals;
            this.owningId      = id;
            this.erroredParams = erroredParams;
            this.pageNumber    = pageNumber;

            reviewRequired = errors.Count > 0;
        }
Exemplo n.º 5
0
        private void AdvanceToNextZone(int dir)
        {
            int tempColumnIndex = columnIndex;

            tempColumnIndex += dir;

            int min = dgv.Columns[0].Tag == null ? 1 : 0;
            int max = dgv.Columns.Count;// + (dgv.Columns[0].Tag == null ? 0 : 1);

            bool found = true;

            while (found)
            {
                while (tempColumnIndex >= min && tempColumnIndex < max)
                {
                    DataGridViewCell cell = dgv[tempColumnIndex, rowIndex];
                    if (rdbtnAllFields.Checked && ((cell.Tag is Field && !chkSkipNonOMR.Checked) || (cell.Tag is Field == false)))
                    {
                        columnIndex          = tempColumnIndex;
                        cbZones.SelectedItem = dgv.Columns[columnIndex];
                        return;
                    }

                    if (cell.Tag is OmrCollection)
                    {
                        OmrCollection    oc = (OmrCollection)cell.Tag;
                        ReviewParameters rp = (ReviewParameters)oc.Tag;

                        VerificationParameters errorParams = rp.ErroredParameters;

                        if (workspace.VerificationParameters.IsAtLeastOneTrue(errorParams))
                        {
                            columnIndex          = tempColumnIndex;
                            cbZones.SelectedItem = dgv.Columns[columnIndex];
                            return;
                        }
                    }
                    else if (cell.Tag != null && chkSkipNonOMR.Checked == false)
                    {
                        columnIndex          = tempColumnIndex;
                        cbZones.SelectedItem = dgv.Columns[columnIndex];
                        return;
                    }

                    tempColumnIndex += dir;
                }

                tempColumnIndex = dir == 1 ? min : max - 1;
                found           = AdvanceToNextWorkSheet(dir, tempColumnIndex);
            }

            MessageBox.Show("No other matches found for the specified criteria.");
        }
Exemplo n.º 6
0
        internal static VerificationResults VerifyAndGetResults(VerificationParameters parameters)
        {
            //XmlHelper.ValidateFromSchemas(parameters.InputPath, XmlHelper.XmlSchemaUrl, SignedXml.XmlDsigNamespaceUrl);
            var xmlDocument = new XmlDocument {
                PreserveWhitespace = true
            };

            xmlDocument.LoadXml(File.ReadAllText(parameters.InputPath));
            var xml = xmlDocument.OuterXml;

            return(PerformValidationFromXml(xml, parameters));
        }
Exemplo n.º 7
0
        private static void VerifySigningCertificate(VerificationParameters parameters, X509Certificate2 signingCertificate)
        {
            var certificateBase64 = signingCertificate.RawData;
            var calculatedHash    = CryptoHelper.GetBytesSHA1(certificateBase64);

            var xmlDocument = new XmlDocument();

            xmlDocument.Load(parameters.InputPath);
            var signingCertificateNode = XmlHelper.FindNodesIn(xmlDocument.DocumentElement,
                                                               "Signature/Object/QualifyingProperties/SignedProperties/" +
                                                               "SignedSignatureProperties/SigningCertificate/Cert/CertDigest");
            var certificateHashNode = XmlHelper.FindNodesIn(signingCertificateNode[0],
                                                            "DigestValue");
            var certificateHashInSignature = Convert.FromBase64String(certificateHashNode[0].InnerText);

            if (!ArrayHelper.ArraysAreEqual(certificateHashInSignature, calculatedHash))
            {
                throw new InvalidSignedDocumentException("SigningCertificate cannot be verified");
            }
        }
Exemplo n.º 8
0
        private static VerificationResults PerformValidationFromXml(string xml, VerificationParameters validationParameters)
        {
            var document = new XmlDocument {
                PreserveWhitespace = true
            };

            document.LoadXml(xml);

            var newsignedXml = new ExtendedSignedXml(document);

            if (document.DocumentElement == null)
            {
                throw new InvalidDocumentException("Document has no root element");
            }

            var signatureNode = XmlDsigNodesHelper.GetSignatureNode(document);

            newsignedXml.LoadXml(signatureNode);

            var verificationCertificate = GetVerificationCertificate(newsignedXml, validationParameters);

            if (verificationCertificate == null)
            {
                throw new Exception("Signer public key could not be found");
            }
            if (!newsignedXml.CheckSignature(verificationCertificate, !validationParameters.VerifyCertificate))
            {
                throw new InvalidOperationException("Signature is invalid.");
            }
            var results = new VerificationResults
            {
                Timestamp          = GetTimeStampFromSignature(document),
                OriginalDocument   = GetDocumentFromSignature(document),
                SigningCertificate = GetCertificateFromSignature(document)
            };

            return(results);
        }
Exemplo n.º 9
0
        public Workspace(InputPanel ip, KeyPanel kp, ITemplateForm currentTemplate) : this()
        {
            for (int i = 0; i < ip.SelectedInputs.Count; i++)
            {
                string guid = Guid.NewGuid().ToString();

                imageManager.Add(guid, ip.SelectedInputs[i]);

                myImages.Add(guid, ip.SelectedInputs[i]);
            }

            if (kp.AnswerImage != null)
            {
                imageManager.Add(Workspace.IMGMGR_ANSWERS, kp.AnswerImagePath);

                myAnswerkeyPath = kp.AnswerImagePath;
            }

            omrProcessor = new ProcessOmrDocumentsOperation(kp.AnswerImage, currentTemplate, imageManager, myImages);

            this.PassingGrade           = kp.PassingGrade;
            this.verificationParameters = VerificationParameters.GetTemplate(VerificationParameters.FilterTemplate.CommonIssues);
        }
Exemplo n.º 10
0
        private bool DoZoneSetup(DataGridViewCell cell, bool stayOnPage)
        {
            bool zoneIsOnCurrentPage = DoPageSetup(cell, stayOnPage);

            UpdateNavigationEnables();

            if (!zoneIsOnCurrentPage)
            {
                return(false);
            }

            object ff = cell.Tag;

            if (annotationField != null)
            {
                annotationField.IsVisible = true;
            }

            dgv.CurrentCell = cell;

            string header = cell.OwningColumn.HeaderText;

            this.Text = "Review: " + header;

            LeadRect bounds       = LeadRect.Empty;
            LeadRect answerBounds = LeadRect.Empty;
            string   color        = "Green";

            if (ff is OmrCollection)
            {
                OmrCollection sff = (OmrCollection)ff;

                RasterImage target = GetCroppedImage(masterSheet, sff.Bounds);

                sfp.Visible = true;
                trp.Visible = false;
                sfp.Populate(sff, target, cell);
                bounds = sff.Bounds;
                color  = "Green";

                ReviewParameters       rp = sff.Tag as ReviewParameters;
                VerificationParameters p  = rp.ErroredParameters;
                p.IsReviewed         = true;
                p.UseValueChanged    = sff.Value != sff.OriginalValue;
                rp.ErroredParameters = p;
            }
            else if (ff is OmrField)
            {
                OmrField       omr = (OmrField)ff;
                OmrFieldResult ofr = (OmrFieldResult)omr.Result;

                RasterImage target = GetCroppedImage(masterSheet, omr.Bounds);

                sfp.Visible = false;
                trp.Visible = true;

                trp.Populate(target, cell, ofr.Text);
                bounds = omr.Bounds;
                color  = "Green";
            }
            else if (ff is BarcodeField)
            {
                BarcodeField       bcf  = (BarcodeField)ff;
                BarcodeFieldResult bcfr = (BarcodeFieldResult)bcf.Result;

                RasterImage target = GetCroppedImage(masterSheet, bcf.Bounds);

                sfp.Visible = false;
                trp.Visible = true;

                string value = "";

                if (bcfr != null && bcfr.BarcodeData != null && bcfr.BarcodeData.Count > 0)
                {
                    value = bcfr.BarcodeData[0].Value;
                }

                trp.Populate(target, cell, value);
                bounds = bcf.Bounds;
                color  = "Blue";
            }
            else if (ff is OcrField)
            {
                OcrField       ocf    = (OcrField)ff;
                OcrFieldResult ofr    = (OcrFieldResult)ocf.Result;
                RasterImage    target = GetCroppedImage(masterSheet, ocf.Bounds);

                sfp.Visible = false;
                trp.Visible = true;

                string text       = ofr != null ? ofr.Text : "";
                int    confidence = ofr != null ? ofr.Confidence : -1;

                trp.Populate(target, cell, text, confidence);
                bounds = ocf.Bounds;
                color  = "Red";
            }
            else if (ff is ImageField)
            {
                ImageField       imf  = (ImageField)ff;
                ImageFieldResult imfr = (ImageFieldResult)imf.Result;

                sfp.Visible = false;
                trp.Visible = true;

                if (imfr == null)
                {
                    RasterImage target = GetCroppedImage(masterSheet, imf.Bounds);
                    trp.Populate(target, cell, imf.Name);
                }
                else
                {
                    trp.Populate(imfr.Image, cell, imf.Name);
                }

                bounds = imf.Bounds;
                color  = "Yellow";
            }

            DoAnswerFieldSetup(cell);
            AddHighlight(bounds, color);

            return(true);
        }
Exemplo n.º 11
0
        private static X509Certificate2 GetVerificationCertificate(SignedXml signedXml, VerificationParameters verificationParameters)
        {
            var validationCertificate = verificationParameters.VerificationCertificate;

            if (validationCertificate == null)
            {
                if (signedXml.KeyInfo != null)
                {
                    var certificates = signedXml.KeyInfo.GetEnumerator();
                    if (certificates.MoveNext())
                    {
                        var x509Data = (KeyInfoX509Data)certificates.Current;
                        if (x509Data != null)
                        {
                            if (x509Data.Certificates.Count > 0)
                            {
                                validationCertificate = (X509Certificate2)x509Data.Certificates[0];
                            }
                        }
                    }
                }
            }
            return(validationCertificate);
        }
Exemplo n.º 12
0
 internal static bool Verify(VerificationParameters parameters)
 {
     VerifyAndGetResults(parameters);
     return(true);
 }
Exemplo n.º 13
0
        public static ReviewCounter GetManualReviewCollection(IRecognitionForm recognizeForm, VerificationParameters parameters, IRecognitionForm answers = null, bool[][][] reviewed = null)
        {
            ReviewCounter reviewCounter = new ReviewCounter();

            for (int i = 0; i < recognizeForm.Pages.Count; i++)
            {
                Page page = recognizeForm.Pages[i];
                for (int j = 0; j < page.Fields.Count; j++)
                {
                    Field field = page.Fields[j];

                    if (field == null)
                    {
                        continue;
                    }

                    field.PageNumber = page.PageNumber;

                    OmrField omrField = field as OmrField;

                    if (omrField != null)
                    {
                        for (int k = 0; k < omrField.Fields.Count; k++)
                        {
                            OmrCollection omr = omrField.Fields[k];
                            reviewCounter.TotalCounts++;

                            //string errors = "The field confidence value is below the required confidence value, the field does not have exactly one bubble filled in, the field has the same value as the answer key, the field has a different value from the answer key, ";

                            List <string>          errors        = new List <string>();
                            VerificationParameters erroredParams = new VerificationParameters(false, false, false, false, parameters.Threshold, false, false);

                            ReviewParameters rp = null;
                            if (omr.Tag != null)
                            {
                                rp            = (ReviewParameters)omr.Tag;
                                erroredParams = rp.ErroredParameters;
                            }


                            string answerVals = null;
                            erroredParams.Threshold = omr.Confidence;

                            if (/* parameters.UseThreshold && */ omr.Confidence < parameters.Threshold)
                            {
                                errors.Add("OMR confidence value too low");
                                erroredParams.UseThreshold = true;
                                reviewCounter.BelowThreshold++;
                            }

                            //                        if (parameters.UseExactlyOneBubble)
                            {
                                int selectedCells = omr.Fields.Count <OmrBubble>(delegate(OmrBubble bub) { return(bub.IsChecked); });
                                if (selectedCells != 1)
                                {
                                    errors.Add("Does not have exactly one bubble filled in");
                                    erroredParams.UseExactlyOneBubble = true;
                                    reviewCounter.NotExactlyOneBubble++;
                                }
                            }
                            erroredParams.UseValueChanged = omr.Value != omr.OriginalValue;

                            if (answers != null && answers.Pages.Count > 0)
                            {
                                OmrField ansField = answers.Pages[i].Fields[j] as OmrField;

                                OmrFieldResult ofr = (OmrFieldResult)ansField.Result;

                                string value = ansField.Fields[k].Value;
                                answerVals = value;

                                if (/* parameters.UseAgreeWithKey && */ omr.Value == value)
                                {
                                    errors.Add("Same value as answer key");
                                    erroredParams.UseAgreeWithKey = true;
                                    reviewCounter.AgreeWithKey++;
                                }
                                if (/* parameters.UseDisagreeWithKey && */ omr.Value != value)
                                {
                                    errors.Add("Different value from answer key");
                                    erroredParams.UseDisagreeWithKey = true;
                                    reviewCounter.DisagreeWithKey++;
                                }
                            }

                            //page.Image.Page = omrField.PageNumber + 1;
                            if (rp != null)
                            {
                                rp.ErroredParameters = erroredParams;
                                omr.Tag = rp;
                            }
                            else
                            {
                                omr.Tag = new ReviewParameters(omrField.GetValues(), errors, answerVals, recognizeForm.Id, erroredParams, page.PageNumber);
                            }

                            if (errors.Count > 0)
                            {
                                if (reviewed != null)
                                {
                                    bool             flag = reviewed[i][j][k];
                                    ReviewParameters rps  = (ReviewParameters)omr.Tag;
                                    rps.ReviewRequired = flag;

                                    VerificationParameters vp = rps.ErroredParameters;
                                    vp.IsReviewed         = !flag;
                                    rps.ErroredParameters = vp;
                                }
                            }
                        }
                    }
                }
            }

            return(reviewCounter);
        }