Exemplo n.º 1
0
        public void SetThreatModel([NotNull] IThreatModel model)
        {
            _model         = model;
            _schemaManager = new AnnotationsPropertySchemaManager(_model);
            _propertyType  = _schemaManager.GetAnnotationsPropertyType();

            LoadModel();
        }
Exemplo n.º 2
0
        private bool Generate([NotNull] IThreatModel model)
        {
            var result = false;

            var schemaManager = new QuestionsPropertySchemaManager(model);
            var questions     = schemaManager.GetQuestions()?.ToArray();

            if (questions?.Any() ?? false)
            {
                var asm = new AnnotationsPropertySchemaManager(model);
                var pt  = asm.GetAnnotationsPropertyType();

                var ei  = model.Entities?.OfType <IExternalInteractor>().OrderBy(x => x.Name);
                var p   = model.Entities?.OfType <IProcess>().OrderBy(x => x.Name);
                var ds  = model.Entities?.OfType <IDataStore>().OrderBy(x => x.Name);
                var f   = model.DataFlows?.OrderBy(x => x.Name);
                var tb  = model.Groups?.OfType <ITrustBoundary>().OrderBy(x => x.Name);
                var te  = model.GetThreatEvents()?.OrderBy(x => x.Name);
                var tem = model.GetThreatEventMitigations()?
                          .OrderBy(x => x.Mitigation.Name)
                          .ThenBy(x => x.ThreatEvent.Name)
                          .ThenBy(x => x.ThreatEvent.Parent.Name);
                var tt = model.ThreatTypes?.OrderBy(x => x.Name);
                var km = model.Mitigations?.OrderBy(x => x.Name);
                var sm = model.GetThreatTypeMitigations()?
                         .OrderBy(x => x.Mitigation.Name)
                         .ThenBy(x => x.ThreatType.Name);
                var et  = model.EntityTemplates?.OrderBy(x => x.Name);
                var ft  = model.FlowTemplates?.OrderBy(x => x.Name);
                var tbt = model.TrustBoundaryTemplates?.OrderBy(x => x.Name);

                foreach (var question in questions)
                {
                    Generate(question, ei, asm);
                    Generate(question, p, asm);
                    Generate(question, ds, asm);
                    Generate(question, f, asm);
                    Generate(question, tb, asm);
                    Generate(question, te, asm);
                    Generate(question, tem, asm);
                    Generate(question, tt, asm);
                    Generate(question, km, asm);
                    Generate(question, sm, asm);
                    Generate(question, et, asm);
                    Generate(question, ft, asm);
                    Generate(question, tbt, asm);
                    Generate(question, model, asm);
                }

                result = true;
            }

            return(result);
        }
Exemplo n.º 3
0
        public void Initialize([NotNull] IThreatModel model)
        {
            if (_model != null)
            {
                Dispose();
            }

            _model                       = model;
            _schemaManager               = new AnnotationsPropertySchemaManager(model);
            _propertyType                = _schemaManager.GetAnnotationsPropertyType();
            _model.PropertyAdded        += PropertyUpdated;
            _model.PropertyRemoved      += PropertyUpdated;
            _model.PropertyValueChanged += PropertyUpdated;
            _model.ChildPropertyAdded   += ChildPropertyUpdated;
            _model.ChildPropertyChanged += ChildPropertyUpdated;
            _model.ChildPropertyChanged += ChildPropertyUpdated;
        }
Exemplo n.º 4
0
        private bool GeneratePdf([Required] string fileName)
        {
            using (var doc = new PdfDocument(PdfConformanceLevel.None))
            {
                doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
                var page = doc.Pages.Add();
                var y    = AddPdfHeader(page);

                var font    = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
                var minSize = font.MeasureString("Ag");
                _minTextHeight = minSize.Height;
                var healthIndex = _analyzersManager.Analyze(_model,
                                                            QualityPropertySchemaManager.IsFalsePositive,
                                                            out var outcomes);
                AddSummary(doc, page, y + 10, font, healthIndex, outcomes);

                var analyzers = QualityAnalyzersManager.QualityAnalyzers?.ToArray();
                if (analyzers?.Any() ?? false)
                {
                    foreach (var analyzer in analyzers)
                    {
                        var outcome = outcomes?.FirstOrDefault(x => x.Id == analyzer.GetExtensionId());
                        if (outcome != null)
                        {
                            AddOutcomePage(doc, font, analyzer, outcome);
                        }
                    }
                }

                var schemaManager = new AnnotationsPropertySchemaManager(_model);
                var propertyType  = schemaManager.GetAnnotationsPropertyType();
                var containers    = GetContainers(schemaManager, propertyType)?.ToArray();
                if (containers?.Any() ?? false)
                {
                    AddReviewNotesPage(doc, font, containers, schemaManager, propertyType);
                }

                AddFooters(doc, font);

                doc.Save(fileName);
            }

            return(true);
        }