Beispiel #1
0
        public void Initialize([NotNull] IThreatModel model)
        {
            var schemaManager = new ModelConfigPropertySchemaManager(model);
            var schema        = schemaManager.GetSchema();

            var horizontalPT = schema.GetPropertyType("Diagram Layout Horizontal Spacing");
            var horizontal   = model.GetProperty(horizontalPT);

            if (horizontal == null)
            {
                model.AddProperty(horizontalPT, "200");
            }
            else
            {
                if (string.IsNullOrWhiteSpace(horizontal.StringValue))
                {
                    horizontal.StringValue = "200";
                }
            }

            var verticalPT = schema.GetPropertyType("Diagram Layout Vertical Spacing");
            var vertical   = model.GetProperty(verticalPT);

            if (vertical == null)
            {
                model.AddProperty(verticalPT, "100");
            }
            else
            {
                if (string.IsNullOrWhiteSpace(vertical.StringValue))
                {
                    vertical.StringValue = "100";
                }
            }
        }
        public void RegisterConnection([NotNull] IDevOpsConnector connector)
        {
            var propertyType = GetPropertyTypeDevOpsConnector();

            if (propertyType != null)
            {
                var property = _model.GetProperty(propertyType) ?? _model.AddProperty(propertyType, null);

                if (property is IPropertyJsonSerializableObject jsonSerializableObject)
                {
                    jsonSerializableObject.Value = new DevOpsConnection(connector);
                }
            }
        }
Beispiel #3
0
        public void Initialize([NotNull] IThreatModel model)
        {
            var schemaManager = new DefinitionsPropertySchemaManager(model);

            var propertyType = schemaManager.DefinitionsPropertyType;

            if (propertyType != null)
            {
                var property = model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null);

                if (property is IPropertyJsonSerializableObject jsonProperty)
                {
                    var definitions = new DefinitionContainer();
                    definitions.SetDefinition("Threat Model",
                                              "Threat Modeling is a process to understand potential threat events to a system, determine risks from those threats, and establish appropriate mitigations.");
                    definitions.SetDefinition("Threat Events",
                                              "Potential attack scenarios to the system. Who performs those attack scenarios is called Threat Actor.");
                    definitions.SetDefinition("Risks",
                                              "Potential loss caused by the occurring of a Threat Event. It is typically expressed in monetary terms.");
                    definitions.SetDefinition("Mitigations",
                                              "Actions that may decrease the Risk associated to a Threat Event.");

                    jsonProperty.Value = definitions;
                }
            }
        }
Beispiel #4
0
        public void AddQuestion([NotNull] Question question)
        {
            var propertyType = GetQuestionsPropertyType();

            if (propertyType != null)
            {
                var property = _model.GetProperty(propertyType);
                if (property == null)
                {
                    property = _model.AddProperty(propertyType, null);
                    if (property is IPropertyJsonSerializableObject jsonSerializableObject)
                    {
                        var questions = new Questions();
                        questions.Add(question);
                        jsonSerializableObject.Value = questions;
                    }
                }
                else if (property is IPropertyJsonSerializableObject jsonSerializableObject)
                {
                    if (!(jsonSerializableObject.Value is Questions questions))
                    {
                        questions = new Questions();
                        jsonSerializableObject.Value = questions;
                    }
                    questions.Add(question);
                }
            }
        }
        public void SetIgnoredFields(string placeholderName, IEnumerable <string> fields)
        {
            var schemaManager = new WordPropertySchemaManager(_model);
            var schema        = schemaManager.GetSchema();
            var propertyType  = schema?.GetPropertyType("IgnoredListFields");

            if (propertyType != null)
            {
                var property = _model.GetProperty(propertyType) ?? _model.AddProperty(propertyType, null);
                if (property is IPropertyArray propertyArray)
                {
                    var list     = new List <string>();
                    var existing = propertyArray.Value?
                                   .Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith($"{placeholderName}#"))
                                   .ToArray();
                    if (existing?.Any() ?? false)
                    {
                        list.AddRange(existing);
                    }
                    if (fields?.Any() ?? false)
                    {
                        list.AddRange(fields.Select(x => $"{placeholderName}#{x}"));
                    }
                    propertyArray.Value = list;
                }
            }
        }
        public void SetFactProviderParameters(IEnumerable <Parameter> parameters)
        {
            var propertyType = GetSchema()?.GetPropertyType("FactProviderParams");

            if (propertyType != null)
            {
                var property = _model.GetProperty(propertyType) ?? _model.AddProperty(propertyType, null);
                if (property is IPropertyJsonSerializableObject jsonObject)
                {
                    var container = new Parameters();

                    var p = parameters?.ToArray();
                    if (p?.Any() ?? false)
                    {
                        container.Items = new List <Parameter>(p);
                    }

                    jsonObject.Value = container;
                }
            }
        }
Beispiel #7
0
        private static IPropertyJsonSerializableObject GetExtensionConfigurationProperty([NotNull] IThreatModel model, [Required] string extensionId)
        {
            var propertySchema =
                model.GetSchema("ExtensionsConfiguration", "https://github.com/simonec73/ThreatsManager") ?? model.AddSchema("ExtensionsConfiguration", "https://github.com/simonec73/ThreatsManager");

            propertySchema.AppliesTo             = Scope.ThreatModel;
            propertySchema.AutoApply             = false;
            propertySchema.NotExportable         = true;
            propertySchema.Priority              = 100;
            propertySchema.RequiredExecutionMode = ExecutionMode.Business;
            propertySchema.System  = true;
            propertySchema.Visible = false;

            var propertyType = propertySchema.GetPropertyType(extensionId) ?? propertySchema.AddPropertyType(extensionId, PropertyValueType.JsonSerializableObject);

            propertyType.Visible    = false;
            propertyType.DoNotPrint = true;

            return((model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null)) as IPropertyJsonSerializableObject);
        }
        public void SetThreatModel(IThreatModel model)
        {
            try
            {
                if (model != null)
                {
                    var schema       = new DefinitionsPropertySchemaManager(model);
                    var propertyType = schema.DefinitionsPropertyType;
                    if (propertyType != null)
                    {
                        var property = model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null);
                        if (property is IPropertyJsonSerializableObject jsonProperty)
                        {
                            if (jsonProperty.Value is DefinitionContainer container)
                            {
                                _container = container;

                                var definitions = container.Definitions?.ToArray();
                                if (definitions?.Any() ?? false)
                                {
                                    foreach (var definition in definitions)
                                    {
                                        _data.Rows.Add(definition.Key, definition.Value);
                                    }
                                }
                            }
                            else
                            {
                                _container         = new DefinitionContainer();
                                jsonProperty.Value = _container;
                            }
                        }
                    }
                }
            }
            finally
            {
                _loading = false;
            }
        }