Ejemplo n.º 1
0
        public IPanel <Form> Create(IIdentity identity, out IActionDefinition action)
        {
            var result = new ThreatEventListPanel();

            if (_actions != null)
            {
                result.SetContextAwareActions(_actions);
            }

            action = new ActionDefinition(result.Id, "ThreatEventList", "Threat Event\nList", Resources.threat_event_big,
                                          Resources.threat_event);

            return(result);
        }
Ejemplo n.º 2
0
        public IPanel <Form> Create(IIdentity identity, out IActionDefinition action)
        {
            var result = new CalculatedSeverityListPanel();

            if (_actions != null)
            {
                result.SetContextAwareActions(_actions);
            }

            action = new ActionDefinition(result.Id, "CalculatedSeverityList", "Calculated Severity\nList",
                                          Properties.Resources.threat_event_big_sum,
                                          Properties.Resources.threat_event_sum);

            return(result);
        }
Ejemplo n.º 3
0
 private static ActionDefinition ConvertToConcrete(IActionDefinition ad)
 {
     return(new ActionDefinition
     {
         Description = ad.Description,
         FullName = ad.FullName,
         KnownActionType = ad.KnownActionType,
         Name = ad.Name,
         SupportsBulk = ad.SupportsBulk,
         SupportsConstraints = ad.SupportsConstraints,
         SupportsInput = ad.SupportsInput,
         SupportsLookupConditions = ad.SupportsLookupConditions,
         SupportsMultipleRecordOperations = ad.SupportsMultipleRecordOperations,
         SupportsRelations = ad.SupportsRelations,
         SupportsSequences = ad.SupportsSequences
     });
 }
Ejemplo n.º 4
0
 public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
 {
     try
     {
         switch (action.Name)
         {
         case "ApplyAutoGenRules":
             Ask?.Invoke(this, threatModel, Resources.ApplyAutoGenRules_Caption, Resources.ApplyAutoGenRules_Confirm, false, RequestOptions.OkCancel);
             break;
         }
     }
     catch
     {
         ShowWarning?.Invoke("Automatic Threat Event generation failed.\nPlease close the document without saving it.");
         throw;
     }
 }
Ejemplo n.º 5
0
 public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
 {
     try
     {
         switch (action.Name)
         {
         case "SomeAction":
             // TODO: specify the execution for the action.
             break;
         }
     }
     catch
     {
         ShowWarning?.Invoke($"{action.Name} failed.");
         throw;
     }
 }
Ejemplo n.º 6
0
        public IPanel <Form> Create(IIdentity identity, out IActionDefinition action)
        {
            IPanel <Form> result = null;

            action = null;

            if (identity is IDiagram diagram)
            {
                result = CreatePanel(diagram);

                var diagramActionDefinition = new DiagramActionDefinition(diagram.Id);
                diagramActionDefinition.Initialize(diagram);

                action = diagramActionDefinition;
            }

            return(result);
        }
Ejemplo n.º 7
0
        public static ButtonItem CreateButton([NotNull] this RibbonBar bar, [NotNull] IActionDefinition actionDefinition, [NotNull] SuperTooltip tooltip)
        {
            ButtonItem result = null;

            string key = $"{actionDefinition.Id:N}_{actionDefinition.Name}";

            if (!bar.Items.Contains(key))
            {
                result = new ButtonItem
                {
                    ButtonStyle         = DevComponents.DotNetBar.eButtonStyle.ImageAndText,
                    ImagePosition       = DevComponents.DotNetBar.eImagePosition.Top,
                    SubItemsExpandWidth = 14,
                    Name           = key,
                    Text           = actionDefinition.Label,
                    Image          = actionDefinition.Icon,
                    ImageSmall     = actionDefinition.SmallIcon,
                    ImageFixedSize = new Size(32, 32),
                    Enabled        = actionDefinition.Enabled,
                    Tag            = actionDefinition
                };

                if (actionDefinition.Shortcut != Shortcut.None)
                {
                    result.Shortcuts.Add((eShortcut)actionDefinition.Shortcut);
                }

                if (actionDefinition.Shortcut != Shortcut.None || !string.IsNullOrWhiteSpace(actionDefinition.Tooltip))
                {
                    string header;
                    if (actionDefinition.Shortcut != Shortcut.None)
                    {
                        header = $"{actionDefinition.Label} ({GetShortcutString(actionDefinition.Shortcut)})";
                    }
                    else
                    {
                        header = $"{actionDefinition.Label}";
                    }
                    tooltip.SetSuperTooltip(result, new SuperTooltipInfo(header, null, actionDefinition.Tooltip, null, null, eTooltipColor.Gray));
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                var connector = DevOpsManager.GetConnector(threatModel);

                switch (action.Name)
                {
                case "Connect":
                    var dialog = new DevOpsConnectionDialog();
                    dialog.Connector = connector;
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        connector = dialog.Connector;
                        var project = dialog.ProjectName;
                        if (connector != null && !string.IsNullOrWhiteSpace(project))
                        {
                            connector.OpenProject(project);
                            DevOpsManager.Register(connector, threatModel);
                            ChangeDisconnectButtonStatus(connector, true);
                        }
                    }

                    break;

                case "Disconnect":
                    if (connector != null && MessageBox.Show(Form.ActiveForm,
                                                             "You are about to disconnect the current DevOps Connector.\nIf you proceed, all the links between the Threat Model and the DevOps system may be lost.\nAre you sure?",
                                                             "DevOps Disconnect", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                        DialogResult.Yes)
                    {
                        DevOpsManager.Unregister(threatModel);
                        ChangeDisconnectButtonStatus(null, false);
                    }
                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Connection failed.");
                throw;
            }
        }
Ejemplo n.º 9
0
        private void AddDiagramToFormList([NotNull] ButtonItem button, [NotNull] IActionDefinition item)
        {
            if (button.Tag is IActionDefinition action && !_childParentActions.ContainsKey(item.Id))
            {
                _childParentActions.Add(item.Id, action.Id);

                var childButton = button.CreateButton(item, _superTooltip);
                if (childButton != null)
                {
                    childButton.Click += Button_Click;
                    button.SubItems.Add(childButton);

                    // ReSharper disable once SuspiciousTypeConversion.Global
                    if (item is INotifyPropertyChanged childButtonAction)
                    {
                        childButtonAction.PropertyChanged += OnChildButtonActionPropertyChanged;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public async void ExecuteRibbonAction([NotNull] IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                switch (action.Name)
                {
                case "Configure":
                    var dialog = new DevOpsConfigurationDialog();
                    await dialog.Initialize(threatModel);

                    dialog.ShowDialog(Form.ActiveForm);
                    var connector = DevOpsManager.GetConnector(threatModel);
                    Connect.ChangeDisconnectButtonStatus(connector, true);
                    break;
                }
            }
            catch
            {
                throw;
            }
        }
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                switch (action.Name)
                {
                case "ImportAzure":

                    threatModel.AddEntity <IProcess>("Azure Function");
                    threatModel.AddEntity <IProcess>("Azure ML");
                    threatModel.AddEntity <IDataStore>("Azure SQL");
                    threatModel.AddEntity <IDataStore>("Azure Storage Blob");

                    ShowMessage?.Invoke("Import Azure Subscription succeeded.");

                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Import Azure Subscription failed.");
            }
        }
Ejemplo n.º 12
0
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            switch (action.Name)
            {
            case "OpenWeb":
                if (_tree.SelectedNode?.Tag is Page page)
                {
                    ProcessStartInfo sInfo = new ProcessStartInfo(page.Url);
#pragma warning disable SCS0001 // Command injection possible in {1} argument passed to '{0}'
                    Process.Start(sInfo);
#pragma warning restore SCS0001 // Command injection possible in {1} argument passed to '{0}'
                }
                break;

            case "CopyUrl":
                if (_tree.SelectedNode?.Tag is Page page2)
                {
                    Clipboard.SetText(page2.Url);
                    ShowMessage?.Invoke("URL copied successfully.");
                }
                break;
            }
        }
Ejemplo n.º 13
0
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                switch (action.Name)
                {
                case "ExportTemplate":
                    using (var dialog = new ExportTemplateDialog(threatModel))
                    {
                        if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                        {
                            ShowMessage?.Invoke("Export Template succeeded.");
                        }
                    }

                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Export Template failed.");
                throw;
            }
        }
 public IPanel <Form> Create(IActionDefinition action)
 {
     return(new AzureDevOpsPanel());
 }
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "AddDataFlow":
                    //text = "Add Data Flow";
                    //_model.AddEntity<IDataStore>();
                    break;

                case "RemoveDataFlow":
                    var selected = _grid.GetSelectedCells()?.OfType <GridCell>()
                                   .Select(x => x.GridRow)
                                   .Distinct()
                                   .ToArray();

                    if (_currentRow != null)
                    {
                        if ((selected?.Length ?? 0) > 1)
                        {
                            var outcome = MessageBox.Show(Form.ActiveForm,
                                                          $"You have selected {selected.Length} Flows. Do you want to remove them all?\nPlease click 'Yes' to remove all selected Flows,\nNo to remove only the last one you selected, '{_currentRow?.Tag?.ToString()}'.\nPress Cancel to abort.",
                                                          "Remove Flows", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
                                                          MessageBoxDefaultButton.Button3);
                            switch (outcome)
                            {
                            case DialogResult.Yes:
                                bool removed = true;
                                foreach (var row in selected)
                                {
                                    bool r = false;
                                    if (row.Tag is IDataFlow flow)
                                    {
                                        r = _model.RemoveDataFlow(flow.Id);
                                    }

                                    removed &= r;

                                    if (r && row == _currentRow)
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                    }
                                }

                                if (removed)
                                {
                                    text = "Remove Flows";
                                }
                                else
                                {
                                    warning = true;
                                    text    = "One or more Flows cannot be removed.";
                                }
                                break;

                            case DialogResult.No:
                                if (_currentRow != null && _currentRow.Tag is IDataFlow flow2)
                                {
                                    if (_model.RemoveDataFlow(flow2.Id))
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                        text             = "Remove Flow";
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "The Flow cannot be removed.";
                                    }
                                }
                                break;
                            }
                        }
                        else if (_currentRow != null && _currentRow.Tag is IDataFlow dataFlow &&
                                 MessageBox.Show(Form.ActiveForm,
                                                 $"You are about to remove Flow '{dataFlow.Name}'. Are you sure?",
                                                 "Remove Flow", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (_model.RemoveDataFlow(dataFlow.Id))
                            {
                                _properties.Item = null;
                                text             = "Remove Flow";
                            }
                            else
                            {
                                warning = true;
                                text    = "The Flow cannot be removed.";
                            }
                        }
                    }
                    break;

                case "FindDataFlow":
                    bool found = false;
                    if (_currentRow != null && _currentRow.Tag is IDataFlow dataFlow2)
                    {
                        var diagrams = _model.Diagrams?.ToArray();
                        if (diagrams?.Any() ?? false)
                        {
                            foreach (var diagram in diagrams)
                            {
                                var flow = diagram.GetLink(dataFlow2.Id);
                                if (flow != null)
                                {
                                    found = true;
                                    var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                                    if (factory != null)
                                    {
                                        OpenPanel?.Invoke(factory, diagram);
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    if (!found)
                    {
                        warning = true;
                        text    = "The Flow has not been found in any Diagram.";
                    }
                    break;

                case "Refresh":
                    LoadModel();
                    break;
                }

                if (warning)
                {
                    ShowWarning?.Invoke(text);
                }
                else if (text != null)
                {
                    ShowMessage?.Invoke($"{text} has been executed successfully.");
                }
            }
            catch
            {
                ShowWarning?.Invoke($"An error occurred during the execution of the action.");
                throw;
            }
        }
Ejemplo n.º 16
0
        public IPanel <Form> Create([NotNull] IActionDefinition action)
        {
            var result = new ThreatModelPanel();

            return(result);
        }
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "AddActor":
                    using (var dialog = new GenericIdentityCreationDialog())
                    {
                        dialog.IdentityTypeName = "Threat Actor";
                        if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                        {
                            text = "Add Threat Actor";
                            _model.AddThreatActor(dialog.IdentityName, dialog.IdentityDescription);
                        }
                    }
                    break;

                case "RemoveActor":
                    var selected = _grid.GetSelectedCells()?.OfType <GridCell>()
                                   .Select(x => x.GridRow)
                                   .Distinct()
                                   .ToArray();

                    if (_currentRow != null)
                    {
                        if ((selected?.Length ?? 0) > 1)
                        {
                            var outcome = MessageBox.Show(Form.ActiveForm,
                                                          $"You have selected {selected.Length} Threat Actors. Do you want to remove them all?\nPlease click 'Yes' to remove all selected Threat Actors,\nNo to remove only the last one you selected, '{_currentRow.Tag?.ToString()}'.\nPress Cancel to abort.",
                                                          "Remove Threat Actors", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
                                                          MessageBoxDefaultButton.Button3);
                            switch (outcome)
                            {
                            case DialogResult.Yes:
                                bool removed = true;
                                foreach (var row in selected)
                                {
                                    bool r = false;
                                    if (row.Tag is IThreatActor actor)
                                    {
                                        r = _model.RemoveThreatActor(actor.Id);
                                    }

                                    removed &= r;

                                    if (r && row == _currentRow)
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                    }
                                }

                                if (removed)
                                {
                                    text = "Remove Threat Actors";
                                }
                                else
                                {
                                    warning = true;
                                    text    = "One or more Threat Actors cannot be removed.";
                                }

                                break;

                            case DialogResult.No:
                                if (_currentRow != null && _currentRow.Tag is IThreatActor actor2)
                                {
                                    if (_model.RemoveThreatActor(actor2.Id))
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                        text             = "Remove Threat Actor";
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "The Threat Actor cannot be removed.";
                                    }
                                }

                                break;
                            }
                        }
                        else if (_currentRow?.Tag is IThreatActor actor &&
                                 MessageBox.Show(Form.ActiveForm,
                                                 $"You are about to remove Threat Actor '{actor.Name}'. Are you sure?",
                                                 "Remove Threat Actor", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (_model.RemoveThreatActor(actor.Id))
                            {
                                text             = "Remove Threat Actor";
                                _properties.Item = null;
                            }
                            else
                            {
                                warning = true;
                                text    = "The Threat Actor cannot be removed.";
                            }
                        }
                    }

                    break;

                case "Restore":
                    var initializer = new ActorsInitializer();
                    initializer.Initialize(_model);
                    text = "Threat Actors restore";
                    break;

                case "Refresh":
                    LoadModel();
                    break;
                }

                if (warning)
                {
                    ShowWarning?.Invoke(text);
                }
                else if (text != null)
                {
                    ShowMessage?.Invoke($"{text} has been executed successfully.");
                }
            }
            catch
            {
                ShowWarning?.Invoke($"An error occurred during the execution of the action.");
                throw;
            }
        }
        public IPanel <Form> Create([NotNull] IActionDefinition action)
        {
            var result = new QuestionListPanel();

            return(result);
        }
Ejemplo n.º 19
0
 public IPanel <Form> Create([NotNull] IActionDefinition action)
 {
     return(new StrengthListPanel());
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the type of the action.
        /// </summary>
        /// <param name="actionDefinition">The action definition.</param>
        /// <returns>ActionTypes.</returns>
        /// <exception cref="System.ArgumentException">Unknown action type.;actionDefinition</exception>
        public ActionTypes GetActionType(IActionDefinition actionDefinition)
        {
            if (actionDefinition is IApprovalActionDefinition)
                return ActionTypes.Approval;

            if (actionDefinition is IAssignmentActionDefinition)
                return ActionTypes.Assignment;

            throw new ArgumentException("Unknown action type.", "actionDefinition");
        }
Ejemplo n.º 21
0
        public IPanel <Form> Create([NotNull] IActionDefinition action)
        {
            var result = new TroubleshootingPanel();

            return(result);
        }
Ejemplo n.º 22
0
 public IPanel <Form> Create([NotNull] IActionDefinition action)
 {
     return(new CapecImportPanel());
 }
Ejemplo n.º 23
0
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            //string text = null;
            //bool warning = false;

            try
            {
                switch (action.Name)
                {
                case "ConfigureEstimator":
                    var dialog = new ResidualRiskEstimatorConfigurationDialog();
                    dialog.Initialize(_model);
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        LoadModel();
                    }
                    break;

                case "Filter":
                    var dialogFilter = new RoadmapFilterDialog(_model);
                    dialogFilter.Filter = _filter;
                    if (dialogFilter.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        _filter = dialogFilter.Filter;
                        LoadModel();
                    }
                    break;

                case "ExportCsv":
                    var saveFileDialog = new SaveFileDialog()
                    {
                        AddExtension       = true,
                        AutoUpgradeEnabled = true,
                        CheckFileExists    = false,
                        CheckPathExists    = true,
                        RestoreDirectory   = true,
                        DefaultExt         = "csv",
                        Filter             = "CSV file (*.csv)|*.csv",
                        Title         = "Create CSV file for Azure DevOps",
                        ValidateNames = true
                    };
                    if (saveFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        ExportCsv(saveFileDialog.FileName);
                    }
                    break;

                case "ExportShortCsv":
                    var saveFileDialogShort = new SaveFileDialog()
                    {
                        AddExtension       = true,
                        AutoUpgradeEnabled = true,
                        CheckFileExists    = false,
                        CheckPathExists    = true,
                        RestoreDirectory   = true,
                        DefaultExt         = "csv",
                        Filter             = "CSV file (*.csv)|*.csv",
                        Title         = "Create CSV file for Azure DevOps",
                        ValidateNames = true
                    };
                    if (saveFileDialogShort.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        ExportCsv(saveFileDialogShort.FileName, RoadmapStatus.ShortTerm);
                    }
                    break;

                case "ExportMidCsv":
                    var saveFileDialogMid = new SaveFileDialog()
                    {
                        AddExtension       = true,
                        AutoUpgradeEnabled = true,
                        CheckFileExists    = false,
                        CheckPathExists    = true,
                        RestoreDirectory   = true,
                        DefaultExt         = "csv",
                        Filter             = "CSV file (*.csv)|*.csv",
                        Title         = "Create CSV file for Azure DevOps",
                        ValidateNames = true
                    };
                    if (saveFileDialogMid.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        ExportCsv(saveFileDialogMid.FileName, RoadmapStatus.MidTerm);
                    }
                    break;

                case "ExportLongCsv":
                    var saveFileDialogLong = new SaveFileDialog()
                    {
                        AddExtension       = true,
                        AutoUpgradeEnabled = true,
                        CheckFileExists    = false,
                        CheckPathExists    = true,
                        RestoreDirectory   = true,
                        DefaultExt         = "csv",
                        Filter             = "CSV file (*.csv)|*.csv",
                        Title         = "Create CSV file for Azure DevOps",
                        ValidateNames = true
                    };
                    if (saveFileDialogLong.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        ExportCsv(saveFileDialogLong.FileName, RoadmapStatus.LongTerm);
                    }
                    break;

                case "Refresh":
                    LoadModel();
                    break;

                default:
                    if (action.Tag is IIdentityContextAwareAction identityContextAwareAction)
                    {
                        if ((identityContextAwareAction.Scope & Scope.ThreatModel) != 0)
                        {
                            identityContextAwareAction.Execute(_model);
                        }
                    }
                    break;
                }

                //if (warning)
                //    ShowWarning?.Invoke(text);
                //else if (text != null)
                //    ShowMessage?.Invoke($"{text} has been executed successfully.");
            }
            catch
            {
                //ShowWarning?.Invoke($"An error occurred during the execution of the action.");
                throw;
            }
        }
Ejemplo n.º 24
0
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                switch (action.Name)
                {
                case "ImportQuestions":
                    var openFileDialog = new OpenFileDialog()
                    {
                        DefaultExt       = "tmq",
                        Filter           = "Questions file (*.tmq)|*.tmq",
                        RestoreDirectory = true,
                        Title            = "Import Questions"
                    };
                    if (openFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        using (var file = File.OpenRead(openFileDialog.FileName))
                        {
                            using (var ms = new MemoryStream())
                            {
                                file.CopyTo(ms);

                                var json = ms.ToArray();
                                if (json.Length > 0)
                                {
                                    string jsonText;
                                    if (json[0] == 0xFF)
                                    {
                                        jsonText = Encoding.Unicode.GetString(json, 2, json.Length - 2);
                                    }
                                    else
                                    {
                                        jsonText = Encoding.Unicode.GetString(json);
                                    }

                                    IEnumerable <Question> questions;
                                    using (var textReader = new StringReader(jsonText))
                                        using (var reader = new JsonTextReader(textReader))
                                        {
                                            var serializer = new JsonSerializer
                                            {
                                                TypeNameHandling      = TypeNameHandling.All,
                                                SerializationBinder   = new KnownTypesBinder(),
                                                MissingMemberHandling = MissingMemberHandling.Ignore
                                            };
                                            questions = serializer.Deserialize <ICollection <Question> >(reader)?.ToArray();
                                        }


                                    if (questions?.Any() ?? false)
                                    {
                                        var schemaManager = new QuestionsPropertySchemaManager(threatModel);
                                        var existing      = schemaManager.GetQuestions()?.ToArray();

                                        foreach (var question in questions)
                                        {
                                            if (!(existing?.Any(x =>
                                                                string.CompareOrdinal(x.Text, question.Text) == 0) ?? false))
                                            {
                                                schemaManager.AddQuestion(question);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Question Import failed.\nThe Threat Model may have some questions applied.");
                throw;
            }
        }
Ejemplo n.º 25
0
 public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
 {
     (new DevOpsManageIterationsDialog(threatModel)).ShowDialog(Form.ActiveForm);
 }
Ejemplo n.º 26
0
 public IPanel <Form> Create(IActionDefinition action)
 {
     return(new DefinitionsPanel());
 }
Ejemplo n.º 27
0
 public IPanel <Form> Create([NotNull] IActionDefinition action)
 {
     return(new WordReportingPanel());
 }
Ejemplo n.º 28
0
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            _right.SuspendLayout();

            switch (action.Name)
            {
            case "AddReviewNote":
                if (_selected != null)
                {
                    var review = new ReviewNote();
                    _schemaManager.AddAnnotation(_selected, review);
                    AddButton(review);
                }
                break;

            case "RemoveReviewNote":
                if (_selected != null && _annotation.Annotation is ReviewNote reviewNote &&
                    MessageBox.Show("You are about to remove the currently selected Review Note. Are you sure?",
                                    "Clear All Review Notes", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning,
                                    MessageBoxDefaultButton.Button2) == DialogResult.OK)
                {
                    _schemaManager.RemoveAnnotation(_selected, reviewNote);
                    _annotation.Annotation = null;
                    RemoveButton(reviewNote);
                }
                break;

            case "ClearAllReviewNotes":
                if (MessageBox.Show("You are about to remove all the Review Notes. Are you sure?",
                                    "Remove Review Note", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning,
                                    MessageBoxDefaultButton.Button2) == DialogResult.OK)
                {
                    _schemaManager.RemoveAnnotations(_model);
                    RemoveAnnotations(_model.Entities);
                    RemoveAnnotations(_model.DataFlows);
                    RemoveAnnotations(_model.Groups);
                    RemoveAnnotations(_model.GetThreatEvents());
                    RemoveAnnotations(_model.GetThreatEventMitigations());
                    RemoveAnnotations(_model.ThreatTypes);
                    RemoveAnnotations(_model.Mitigations);
                    RemoveAnnotations(_model.GetThreatTypeMitigations());
                    RemoveAnnotations(_model.EntityTemplates);
                    RemoveAnnotations(_model.FlowTemplates);
                    RemoveAnnotations(_model.TrustBoundaryTemplates);
                    RemoveAnnotations(_model.Diagrams);
                    _annotation.Annotation = null;
                    LoadModel();
                }
                break;

            case "Export":
                var saveFileDialog = new SaveFileDialog()
                {
                    AddExtension       = true,
                    AutoUpgradeEnabled = true,
                    CheckFileExists    = false,
                    CheckPathExists    = true,
                    RestoreDirectory   = true,
                    DefaultExt         = "csv",
                    Filter             = "CSV file (*.csv)|*.csv",
                    Title         = "Create CSV file",
                    ValidateNames = true
                };
                if (saveFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                {
                    ExportCsv(saveFileDialog.FileName);
                }
                break;

            case "Refresh":
                LoadModel();
                break;
            }

            _right.ResumeLayout();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets the due date.
        /// </summary>
        /// <param name="actionDefinition">The action definition.</param>
        /// <param name="item">The item.</param>
        /// <returns>DateTime.</returns>
        public DateTime GetDueDate(IActionDefinition actionDefinition, IDynamicObject item)
        {
            var actionDef = actionDefinition as IAssignmentActionDefinition;

            if (actionDef == null)
            {
                return DateTime.MinValue;
            }

            if (item == null)
            {
                return DateTime.MinValue;
            }

            if (string.IsNullOrEmpty(actionDef.DueDateFieldName))
            {
                return DateTime.MinValue;
            }

            var date = item.GetValueByPropertyName(actionDef.DueDateFieldName) as DateTime?;
            return date ?? DateTime.MinValue;
        }
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "AddSchema":
                    using (var dialogSchema = new PropertySchemaCreationDialog())
                    {
                        if (dialogSchema.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                        {
                            var schema = _model.AddSchema(dialogSchema.SchemaName, dialogSchema.SchemaNamespace);
                            schema.Description = dialogSchema.Description;
                            text = "Add Property Schema";
                            _schemas.SelectedIndex = _schemas.Items.Add(schema);
                        }
                    }
                    break;

                case "AddProperty":
                    if (_schemas.SelectedItem is IPropertySchema schema1 && (!schema1.System || _promoted))
                    {
                        using (var dialogProperty = new PropertyTypeCreationDialog(schema1))
                        {
                            if (dialogProperty.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                            {
                                text = "Add Property";
                                var propertyType = schema1.AddPropertyType(dialogProperty.PropertyName,
                                                                           dialogProperty.PropertyValueType);
                                if (propertyType != null)
                                {
                                    propertyType.Description = dialogProperty.Description;
                                    propertyType.Visible     = true;
                                    if (propertyType is IListPropertyType listPt)
                                    {
                                        listPt.SetListProvider(new ListProvider());
                                    }
                                    else if (propertyType is IListMultiPropertyType listMultiPt)
                                    {
                                        listMultiPt.SetListProvider(new ListProvider());
                                    }
                                    AddGridRow(propertyType, _grid.PrimaryGrid);
                                }
                            }
                        }
                    }
                    else
                    {
                        warning = true;
                        text    = "The action is possible only on non-System Property Schemas.";
                    }
                    break;

                case "RemoveSchema":
                    if (_schemas.SelectedItem is IPropertySchema schema2 && (!schema2.System || _promoted))
                    {
                        var found = false;

                        if (_updaters?.Any() ?? false)
                        {
                            foreach (var updater in _updaters)
                            {
                                found = updater.HasPropertySchema(_model, schema2.Name, schema2.Namespace);
                                if (found)
                                {
                                    break;
                                }
                            }
                        }

                        if (!found)
                        {
                            if (MessageBox.Show(Form.ActiveForm,
                                                "Are you sure that you want to remove the current Property Schema?",
                                                "Property Schema removal", MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Exclamation) == DialogResult.Yes)
                            {
                                if (_model.RemoveSchema(schema2.Id))
                                {
                                    text = "Remove Property Schema";
                                    _schemas.Items.Remove(schema2);
                                    Reset();
                                }
                                else
                                {
                                    if (MessageBox.Show(Form.ActiveForm,
                                                        "The Property Schema is in use. Do you want to force its removal?",
                                                        "Property Schema Removal", MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Exclamation) == DialogResult.Yes)
                                    {
                                        if (_model.RemoveSchema(schema2.Id, true))
                                        {
                                            text = "Remove Property Schema";
                                            _schemas.Items.Remove(schema2);
                                            Reset();
                                        }
                                        else
                                        {
                                            warning = true;
                                            text    = "Schema removal has failed.";
                                        }
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "Schema removal has failed.";
                                    }
                                }
                            }
                        }
                        else
                        {
                            warning = true;
                            text    = "Schema cannot be removed because it is used somewhere.";
                        }
                    }
Ejemplo n.º 31
0
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "CreateFile":
                    _saveFile.FileName = _model.Name;
                    if (_saveFile.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        if (SaveExcelFile(_saveFile.FileName))
                        {
                            text = "Excel file creation";
                            SaveSelectedProperties();

                            _lastDocument = _saveFile.FileName;
                        }
                    }
                    break;

                case "Open":
                    if (!string.IsNullOrWhiteSpace(_lastDocument) && File.Exists(_lastDocument))
                    {
                        Process.Start(_lastDocument);
                    }
                    break;

                case "Check":
                    ChangeStatus(_fieldsExternalInteractors, true);
                    ChangeStatus(_fieldsProcesses, true);
                    ChangeStatus(_fieldsDataStores, true);
                    ChangeStatus(_fieldsDataFlows, true);
                    ChangeStatus(_fieldsThreatEvents, true);
                    ChangeStatus(_fieldsMitigations, true);
                    break;

                case "Uncheck":
                    ChangeStatus(_fieldsExternalInteractors, false);
                    ChangeStatus(_fieldsProcesses, false);
                    ChangeStatus(_fieldsDataStores, false);
                    ChangeStatus(_fieldsDataFlows, false);
                    ChangeStatus(_fieldsThreatEvents, false);
                    ChangeStatus(_fieldsMitigations, false);
                    break;

                case "Refresh":
                    LoadModel(_model);
                    break;
                }

                if (warning)
                {
                    ShowWarning?.Invoke(text);
                }
                else if (text != null)
                {
                    ShowMessage?.Invoke($"{text} has been executed successfully.");
                }
            }
            catch (Exception exc)
            {
                ShowWarning?.Invoke($"An error occurred during the execution of the action.");
                throw;
            }
        }
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "AddEntityTemplate":
                    using (var dialog = new CreateEntityTemplateDialog())
                    {
                        if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                        {
                            var entityTemplate = _model.AddEntityTemplate(dialog.EntityName,
                                                                          dialog.EntityDescription,
                                                                          dialog.BigImage,
                                                                          dialog.Image,
                                                                          dialog.SmallImage,
                                                                          dialog.EntityType);
                            _model.AutoApplySchemas(entityTemplate);
                            text = "Add Entity Template";
                        }
                    }
                    break;

                case "AddFlowTemplate":
                    using (var dialog = new GenericIdentityCreationDialog())
                    {
                        dialog.IdentityTypeName = "Flow Template";
                        if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                        {
                            var flowTemplate = _model.AddFlowTemplate(dialog.IdentityName,
                                                                      dialog.IdentityDescription);
                            _model.AutoApplySchemas(flowTemplate);
                            text = "Add Flow Template";
                        }
                    }
                    break;

                case "AddTrustBoundaryTemplate":
                    using (var dialog = new GenericIdentityCreationDialog())
                    {
                        dialog.IdentityTypeName = "Trust Boundary Template";
                        if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                        {
                            var trustBoundaryTemplate = _model.AddTrustBoundaryTemplate(dialog.IdentityName,
                                                                                        dialog.IdentityDescription);
                            _model.AutoApplySchemas(trustBoundaryTemplate);
                            text = "Add Trust Boundary Template";
                        }
                    }
                    break;

                case "RemoveItemTemplates":
                    var selected = _grid.GetSelectedCells()?.OfType <GridCell>()
                                   .Select(x => x.GridRow)
                                   .Distinct()
                                   .ToArray();

                    if (_currentRow != null)
                    {
                        if ((selected?.Length ?? 0) > 1)
                        {
                            var outcome = MessageBox.Show(Form.ActiveForm,
                                                          $"You have selected {selected.Length} Item Templates. Do you want to remove them all?\nPlease click 'Yes' to remove all selected Item Templates,\nNo to remove only the last one you selected, '{_currentRow.Tag?.ToString()}'.\nPress Cancel to abort.",
                                                          "Remove Item Templates", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
                                                          MessageBoxDefaultButton.Button3);
                            switch (outcome)
                            {
                            case DialogResult.Yes:
                                bool removed = true;
                                foreach (var row in selected)
                                {
                                    bool r = false;
                                    if (row.Tag is IEntityTemplate template)
                                    {
                                        r = _model.RemoveEntityTemplate(template.Id);
                                    }
                                    else if (row.Tag is IFlowTemplate flowTemplate)
                                    {
                                        r = _model.RemoveFlowTemplate(flowTemplate.Id);
                                    }
                                    else if (row.Tag is ITrustBoundaryTemplate trustBoundaryTemplate)
                                    {
                                        r = _model.RemoveTrustBoundaryTemplate(trustBoundaryTemplate.Id);
                                    }

                                    removed &= r;

                                    if (r && row == _currentRow)
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                    }
                                }

                                if (removed)
                                {
                                    text = "Remove Item Templates";
                                }
                                else
                                {
                                    warning = true;
                                    text    = "One or more Item Templates cannot be removed.";
                                }

                                break;

                            case DialogResult.No:
                                if (_currentRow?.Tag is IEntityTemplate template2)
                                {
                                    if (_model.RemoveEntityTemplate(template2.Id))
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                        text             = "Remove Entity Template";
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "The Entity Template cannot be removed.";
                                    }
                                }
                                else if (_currentRow?.Tag is IFlowTemplate template3)
                                {
                                    if (_model.RemoveFlowTemplate(template3.Id))
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                        text             = "Remove Flow Template";
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "The Flow Template cannot be removed.";
                                    }
                                }
                                else if (_currentRow?.Tag is ITrustBoundaryTemplate template4)
                                {
                                    if (_model.RemoveTrustBoundaryTemplate(template4.Id))
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                        text             = "Remove Trust Boundary Template";
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "The Trust Boundary Template cannot be removed.";
                                    }
                                }

                                break;
                            }
                        }
                        else if (_currentRow?.Tag is IEntityTemplate template &&
                                 MessageBox.Show(Form.ActiveForm,
                                                 $"You are about to remove Entity Template '{template.Name}'. Are you sure?",
                                                 "Remove Entity Template", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (_model.RemoveEntityTemplate(template.Id))
                            {
                                text             = "Remove Entity Template";
                                _properties.Item = null;
                            }
                            else
                            {
                                warning = true;
                                text    = "The Entity Template cannot be removed.";
                            }
                        }
                        else if (_currentRow?.Tag is IFlowTemplate flowTemplate &&
                                 MessageBox.Show(Form.ActiveForm,
                                                 $"You are about to remove Flow Template '{flowTemplate.Name}'. Are you sure?",
                                                 "Remove Flow Template", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (_model.RemoveFlowTemplate(flowTemplate.Id))
                            {
                                text             = "Remove Flow Template";
                                _properties.Item = null;
                            }
                            else
                            {
                                warning = true;
                                text    = "The Flow Template cannot be removed.";
                            }
                        }
                        else if (_currentRow?.Tag is ITrustBoundaryTemplate trustBoundaryTemplate &&
                                 MessageBox.Show(Form.ActiveForm,
                                                 $"You are about to remove Trust Boundary Template '{trustBoundaryTemplate.Name}'. Are you sure?",
                                                 "Remove Trust Boundary Template", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (_model.RemoveTrustBoundaryTemplate(trustBoundaryTemplate.Id))
                            {
                                text             = "Remove Trust Boundary Template";
                                _properties.Item = null;
                            }
                            else
                            {
                                warning = true;
                                text    = "The Trust Boundary Template cannot be removed.";
                            }
                        }
                    }
                    break;