public bool Execute(IWeaknessMitigation mitigation)
        {
            var result = false;

            var model = mitigation.Model;

            if (model != null)
            {
                var rule   = mitigation.GetRule(model);
                var parent = mitigation.Weakness;

                if (parent != null)
                {
                    var parentRule = parent.GetRule(model);

                    if (string.CompareOrdinal(rule?.ToString(), parentRule?.ToString()) != 0)
                    {
                        Ask?.Invoke(this, new Context()
                        {
                            Container = mitigation, Rule = parentRule
                        },
                                    "Inherit Auto Gen Rule from Weakness", $"Are you sure you want to replace the existing rule for '{mitigation.Mitigation.Name}' with the one assigned to Weakness '{parent.Name}'?",
                                    true, RequestOptions.YesNo);
                    }
                    else
                    {
                        ShowMessage?.Invoke("Nothing to do, because the Auto Gen Rules are equivalent.");
                    }
                }
            }

            return(result);
        }
        public bool Execute(IWeaknessMitigation mitigation)
        {
            bool result = false;

            if (mitigation is IPropertiesContainer container)
            {
                result = Execute(container);
            }

            return(result);
        }
Exemplo n.º 3
0
        public bool Execute(IWeaknessMitigation mitigation)
        {
            var result = false;

            if (Clipboard.GetDataObject() is DataObject dataObject &&
                dataObject.GetDataPresent("AutoGenRule") &&
                dataObject.GetData("AutoGenRule") is string autoGenRule)
            {
                result = ApplyGenRule(mitigation, autoGenRule);
            }

            return(result);
        }
        public IWeaknessMitigation AddMitigation([NotNull] IMitigation mitigation, IStrength strength)
        {
            IWeaknessMitigation result = null;

            if (GetMitigation(mitigation.Id) == null)
            {
                result = new WeaknessMitigation(Model, this, mitigation, strength);
                if (_mitigations == null)
                {
                    _mitigations = new List <IWeaknessMitigation>();
                }
                _mitigations.Add(result);
                SetDirty();
                _weaknessMitigationAdded?.Invoke(this, result);
            }

            return(result);
        }
Exemplo n.º 5
0
        private void AddGridRow([NotNull] IWeaknessMitigation mitigation, [NotNull] GridPanel panel)
        {
            GridRow row = new GridRow(
                mitigation.Mitigation.Name,
                mitigation.Mitigation.ControlType.ToString(),
                mitigation.Strength.ToString())
            {
                Tag = mitigation
            };

            row.Cells[0].CellStyles.Default.Image = mitigation.Mitigation.GetImage(ImageSize.Small);
            for (int i = 0; i < row.Cells.Count; i++)
            {
                row.Cells[i].PropertyChanged += OnMitigationCellChanged;
            }
            panel.Rows.Add(row);

            ((INotifyPropertyChanged)mitigation).PropertyChanged            += OnMitigationPropertyChanged;
            ((INotifyPropertyChanged)mitigation.Mitigation).PropertyChanged += OnMitigationPropertyChanged;
        }
Exemplo n.º 6
0
 private void _ok_Click(object sender, EventArgs e)
 {
     if (_associateExisting.Checked)
     {
         if (_existingMitigation.SelectedItem is IMitigation mitigation &&
             _strengthExisting.SelectedItem != null)
         {
             _mitigation = _weakness.AddMitigation(mitigation, _strengthExisting.SelectedItem as IStrength);
         }
     }
     else if (_createNew.Checked)
     {
         if (Enum.TryParse <SecurityControlType>((string)_controlType.SelectedItem, out var controlType) &&
             _strength.SelectedItem != null)
         {
             var newMitigation = _weakness.Model.AddMitigation(_name.Text);
             newMitigation.Description = _description.Text;
             newMitigation.ControlType = controlType;
             _mitigation = _weakness.AddMitigation(newMitigation, _strength.SelectedItem as IStrength);
         }
     }
 }
Exemplo n.º 7
0
        private GridRow GetRow([NotNull] IWeaknessMitigation mitigation)
        {
            GridRow result = null;

            var rows = _grid.PrimaryGrid.Rows.OfType <GridRow>().ToArray();

            foreach (var row in rows)
            {
                var panel = row.Rows.OfType <GridPanel>()
                            .FirstOrDefault(x => string.CompareOrdinal("Mitigations", x.Name) == 0);
                if (panel != null)
                {
                    result = panel.Rows.OfType <GridRow>().FirstOrDefault(x =>
                                                                          (x.Tag is IWeaknessMitigation weaknessMitigation) &&
                                                                          weaknessMitigation == mitigation);
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        private void OnWeaknessMitigationRemoved(IWeaknessMitigationsContainer container, IWeaknessMitigation mitigation)
        {
            if (container is IWeakness weakness)
            {
                var row = GetRow(weakness);

                var panel       = row?.Rows.OfType <GridPanel>().FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0);
                var scenarioRow = panel?.Rows.OfType <GridRow>()
                                  .FirstOrDefault(x =>
                                                  (x.Tag is IWeaknessMitigation weaknessMitigation) && weaknessMitigation == mitigation);
                if (scenarioRow != null)
                {
                    panel.Rows.Remove(scenarioRow);

                    if (panel.Rows.Count == 0)
                    {
                        row.Rows.Remove(panel);
                    }

                    UpdateMitigationLevel(weakness, row);
                }
            }
        }
Exemplo n.º 9
0
        private void OnWeaknessMitigationAdded(IWeaknessMitigationsContainer container, IWeaknessMitigation mitigation)
        {
            if (container is IWeakness weakness)
            {
                var filterSpecial = EnumExtensions.GetEnumValue <WeaknessListFilter>((string)_specialFilter.SelectedItem);
                if (IsSelected(weakness, _filter.Text, filterSpecial))
                {
                    var row = GetRow(weakness);
                    if (row == null)
                    {
                        row = AddGridRow(weakness, _grid.PrimaryGrid);
                    }

                    var scenarioPanel = row.Rows.OfType <GridPanel>()
                                        .FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0);
                    if (scenarioPanel != null)
                    {
                        AddGridRow(mitigation, scenarioPanel);
                    }
                    else
                    {
                        scenarioPanel = CreateMitigationsPanel(weakness);
                        if (scenarioPanel != null)
                        {
                            row.Rows.Add(scenarioPanel);
                        }
                    }

                    UpdateMitigationLevel(weakness, row);
                }
            }
        }
Exemplo n.º 10
0
 public static SelectionRule GetRule([NotNull] IWeaknessMitigation weaknessMitigation)
 {
     return(weaknessMitigation.GetRule(weaknessMitigation.Model));
 }
Exemplo n.º 11
0
 public bool Execute(IWeaknessMitigation mitigation)
 {
     return(mitigation != null && Execute(mitigation as IPropertiesContainer));
 }