def onDeleteDimension(self, evt):
        idx = self.GetFocusedItem()
        roleToGo = set([self.GetItemText(idx)])
        DimensionListCtrl.onDeleteDimension(self, evt)
        if (self.GetItemCount() > 0):
            noOfPersonas = self.thePersonaList.GetItemCount()
            if (noOfPersonas > 0):
                keysToGo = set([])
                for x in range(noOfPersonas):
                    personaTask = (self.thePersonaList.GetItem(x, 0)).GetText()
                    personaName = (self.thePersonaList.GetItem(x, 1)).GetText()
                    personaObjt = self.dbProxy.dimensionObject(
                        personaName, 'persona')
                    if (len(
                            set.difference(
                                set(
                                    personaObjt.roles(
                                        self.theCurrentEnvironment, '')),
                                roleToGo)) == 0):
                        keysToGo.add((personaTask, personaName))

                for ttg, ptg in keysToGo:
                    for x in range(noOfPersonas):
                        if ((ttg == (self.thePersonaList.GetItem(x,
                                                                 0)).GetText())
                                and (ptg == (self.thePersonaList.GetItem(
                                    x, 1)).GetText())):
                            self.thePersonaList.DeleteItem(x)
        else:
            self.thePersonaList.DeleteAllItems()
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent,
                          ENVIRONMENT_PANELENVIRONMENTPROPERTIES_ID)
        self.theEnvironmentPanel = parent

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        environmentBox = wx.StaticBox(
            self,
            -1,
        )
        environmentFrameSizer = wx.StaticBoxSizer(environmentBox, wx.VERTICAL)
        mainSizer.Add(environmentFrameSizer, 1, wx.EXPAND)
        self.environmentList = DimensionListCtrl(
            self, ENVIRONMENT_LISTENVIRONMENTS_ID, wx.DefaultSize,
            'Environment', 'environment', dp,
            'Adding one or more environments indicates that this is a composite environment'
        )
        environmentFrameSizer.Add(self.environmentList, 1, wx.EXPAND)

        propertiesBox = wx.StaticBox(self, -1, 'Duplication properties')
        propertiesFrameSizer = wx.StaticBoxSizer(propertiesBox, wx.VERTICAL)
        mainSizer.Add(propertiesFrameSizer, 1, wx.EXPAND)
        propertiesSizer = wx.FlexGridSizer(rows=2, cols=3)
        propertiesFrameSizer.Add(propertiesSizer, 1, wx.EXPAND)
        propertiesSizer.Add(wx.StaticText(self, -1, 'Override'))
        self.overrideRadio = wx.RadioButton(self,
                                            ENVIRONMENT_RADIOOVERRIDE_ID,
                                            style=wx.RB_GROUP)
        self.overrideRadio.SetToolTip(
            wx.ToolTip(
                'If an artifact exists in multiple environments, choose the artifact\'s value for the overriding environment.'
            ))
        propertiesSizer.Add(self.overrideRadio)
        self.overrideCombo = wx.ComboBox(self,
                                         ENVIRONMENT_COMBOOVERRIDE_ID,
                                         '',
                                         choices=[],
                                         style=wx.CB_READONLY | wx.CB_DROPDOWN)
        propertiesSizer.Add(self.overrideCombo, 0, wx.EXPAND)
        propertiesSizer.Add(wx.StaticText(self, -1, 'Maximise'))
        self.maxRadio = wx.RadioButton(self, ENVIRONMENT_RADIOMAXIMISE_ID)
        self.maxRadio.SetToolTip(
            wx.ToolTip(
                'If an artifact exists in multiple environments, choose the artifact\'s maximal values.'
            ))
        propertiesSizer.Add(self.maxRadio)
        propertiesSizer.AddGrowableCol(2)
        self.SetSizer(mainSizer)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.onEnvironmentAdded)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.onEnvironmentDeleted)
        self.overrideRadio.Bind(wx.EVT_RADIOBUTTON, self.onOverrideClick)
        self.maxRadio.Bind(wx.EVT_RADIOBUTTON, self.onMaximiseClick)
        self.overrideRadio.Disable()
        self.overrideCombo.Disable()
        self.maxRadio.Disable()
示例#3
0
 def __init__(self,parent,winId,dp):
   DimensionListCtrl.__init__(self,parent,winId,wx.DefaultSize,'Environment','environment',dp,'Context of use',wx.LC_REPORT | wx.LC_SINGLE_SEL)
   b = Borg()
   self.dbProxy = b.dbProxy
   self.theInheritedEnvironment = ''
   self.theDimMenu.Append(ENVLIST_MENUNEWENVIRONMENT_ID,'New Environment')
   self.theDimMenu.Append(ENVLIST_MENUINHERITENVIRONMENT_ID,'Inherit Environment')
   wx.EVT_MENU(self.theDimMenu,ENVLIST_MENUNEWENVIRONMENT_ID,self.onNewEnvironment)
   wx.EVT_MENU(self.theDimMenu,ENVLIST_MENUINHERITENVIRONMENT_ID,self.onInheritEnvironment)
 def __init__(self, parent, dp, personaList):
     DimensionListCtrl.__init__(self,
                                parent,
                                armid.COUNTERMEASURE_LISTROLES_ID,
                                wx.DefaultSize,
                                'Role',
                                'role',
                                dp,
                                listStyle=wx.LC_REPORT | wx.LC_SINGLE_SEL)
     self.thePersonaList = personaList
示例#5
0
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, ROLE_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = DimensionListCtrl(self,
                                                 ROLE_LISTENVIRONMENTS_ID,
                                                 wx.DefaultSize,
                                                 'Environment',
                                                 'environment',
                                                 self.dbProxy,
                                                 listStyle=wx.LC_REPORT
                                                 | wx.LC_SINGLE_SEL)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)

        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        rSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(rSizer, 1, wx.EXPAND)
        self.responseList = DimensionCostListCtrl(self, ROLE_LISTRESPONSES_ID,
                                                  'Response')
        responseBox = wx.StaticBox(self)
        responseSizer = wx.StaticBoxSizer(responseBox, wx.HORIZONTAL)
        responseSizer.Add(self.responseList, 1, wx.EXPAND)
        rSizer.Add(responseSizer, 1, wx.EXPAND)

        cSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(cSizer, 1, wx.EXPAND)
        self.cmList = DimensionListCtrl(self,
                                        ROLE_LISTCOUNTERMEASURES_ID,
                                        wx.DefaultSize,
                                        'Countermeasure',
                                        'countermeasure',
                                        self.dbProxy,
                                        listStyle=wx.LC_REPORT
                                        | wx.LC_SINGLE_SEL)
        cmBox = wx.StaticBox(self)
        cmSizer = wx.StaticBoxSizer(cmBox, wx.HORIZONTAL)
        cmSizer.Add(self.cmList, 1, wx.EXPAND)
        cSizer.Add(cmSizer, 1, wx.EXPAND)

        self.SetSizer(mainSizer)
        self.environmentList.Unbind(wx.EVT_RIGHT_DOWN)
        self.responseList.Unbind(wx.EVT_RIGHT_DOWN)
        self.cmList.Unbind(wx.EVT_RIGHT_DOWN)
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,THREAT_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theThreatId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,THREATENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    lhoodBox = wx.StaticBox(self)
    lhoodSizer = wx.StaticBoxSizer(lhoodBox,wx.HORIZONTAL)
    environmentDimSizer.Add(lhoodSizer,0,wx.EXPAND)
    lhoodSizer.Add(wx.StaticText(self,-1,'Likelihood'))
    lhoodList = ['Incredible','Improbable','Remote','Occasional','Probable','Frequent']
    self.lhoodCtrl = wx.ComboBox(self,THREATENVIRONMENT_COMBOLIKELIHOOD_ID,choices=lhoodList,size=wx.DefaultSize,style=wx.CB_READONLY)
    lhoodSizer.Add(self.lhoodCtrl,1,wx.EXPAND) 

    aaSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(aaSizer,1,wx.EXPAND)
    self.attackerList = DimensionListCtrl(self,THREATENVIRONMENT_LISTATTACKERS_ID,wx.DefaultSize,'Attacker','attacker',self.dbProxy)
    attackerBox = wx.StaticBox(self)
    attackerSizer = wx.StaticBoxSizer(attackerBox,wx.HORIZONTAL)
    attackerSizer.Add(self.attackerList,1,wx.EXPAND)
    aaSizer.Add(attackerSizer,1,wx.EXPAND)

    self.assetList = DimensionListCtrl(self,THREATENVIRONMENT_LISTASSETS_ID,wx.DefaultSize,'Asset','asset',self.dbProxy)
    assetBox = wx.StaticBox(self)
    assetSizer = wx.StaticBoxSizer(assetBox,wx.HORIZONTAL)
    assetSizer.Add(self.assetList,1,wx.EXPAND)
    aaSizer.Add(assetSizer,1,wx.EXPAND)

    propertiesBox = wx.StaticBox(self)
    propertiesSizer = wx.StaticBoxSizer(propertiesBox,wx.HORIZONTAL)
    environmentDimSizer.Add(propertiesSizer,1,wx.EXPAND)
    values = self.dbProxy.getDimensionNames('threat_value')
    valueLookup = ValueDictionary(values)
    self.propertiesList = PropertiesListCtrl(self,THREATENVIRONMENT_LISTPROPERTIES_ID,valueLookup)
    propertiesSizer.Add(self.propertiesList,1,wx.EXPAND)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
示例#7
0
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,THREAT_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theThreatId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,THREATENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    lhoodBox = wx.StaticBox(self)
    lhoodSizer = wx.StaticBoxSizer(lhoodBox,wx.HORIZONTAL)
    environmentDimSizer.Add(lhoodSizer,0,wx.EXPAND)
    lhoodSizer.Add(wx.StaticText(self,-1,'Likelihood'))
    lhoodList = ['Incredible','Improbable','Remote','Occasional','Probable','Frequent']
    self.lhoodCtrl = wx.ComboBox(self,THREATENVIRONMENT_COMBOLIKELIHOOD_ID,choices=lhoodList,size=wx.DefaultSize,style=wx.CB_READONLY)
    lhoodSizer.Add(self.lhoodCtrl,1,wx.EXPAND) 

    aaSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(aaSizer,1,wx.EXPAND)
    self.attackerList = DimensionListCtrl(self,THREATENVIRONMENT_LISTATTACKERS_ID,wx.DefaultSize,'Attacker','attacker',self.dbProxy)
    attackerBox = wx.StaticBox(self)
    attackerSizer = wx.StaticBoxSizer(attackerBox,wx.HORIZONTAL)
    attackerSizer.Add(self.attackerList,1,wx.EXPAND)
    aaSizer.Add(attackerSizer,1,wx.EXPAND)

    self.assetList = DimensionListCtrl(self,THREATENVIRONMENT_LISTASSETS_ID,wx.DefaultSize,'Asset','asset',self.dbProxy)
    assetBox = wx.StaticBox(self)
    assetSizer = wx.StaticBoxSizer(assetBox,wx.HORIZONTAL)
    assetSizer.Add(self.assetList,1,wx.EXPAND)
    aaSizer.Add(assetSizer,1,wx.EXPAND)

    propertiesBox = wx.StaticBox(self)
    propertiesSizer = wx.StaticBoxSizer(propertiesBox,wx.HORIZONTAL)
    environmentDimSizer.Add(propertiesSizer,1,wx.EXPAND)
    values = self.dbProxy.getDimensionNames('threat_value')
    valueLookup = ValueDictionary(values)
    self.propertiesList = PropertiesListCtrl(self,THREATENVIRONMENT_LISTPROPERTIES_ID,valueLookup)
    propertiesSizer.Add(self.propertiesList,1,wx.EXPAND)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent,
                          armid.VULNERABILITY_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theVulId = None
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = EnvironmentListCtrl(
            self, armid.VULNERABILITYENVIRONMENT_LISTENVIRONMENTS_ID,
            self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)

        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        sevBox = wx.StaticBox(self)
        sevSizer = wx.StaticBoxSizer(sevBox, wx.HORIZONTAL)
        environmentDimSizer.Add(sevSizer, 0, wx.EXPAND)
        sevSizer.Add(wx.StaticText(self, -1, 'Severity'))
        sevList = ['Negligible', 'Marginal', 'Critical', 'Catastrophic']
        self.sevCtrl = wx.ComboBox(
            self,
            armid.VULNERABILITYENVIRONMENT_COMBOSEVERITY_ID,
            choices=sevList,
            size=wx.DefaultSize,
            style=wx.CB_READONLY)
        sevSizer.Add(self.sevCtrl, 1, wx.EXPAND)

        aSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(aSizer, 1, wx.EXPAND)
        self.assetList = DimensionListCtrl(
            self, armid.VULNERABILITYENVIRONMENT_LISTASSETS_ID, wx.DefaultSize,
            'Asset', 'asset', self.dbProxy)
        assetBox = wx.StaticBox(self)
        assetSizer = wx.StaticBoxSizer(assetBox, wx.HORIZONTAL)
        assetSizer.Add(self.assetList, 1, wx.EXPAND)
        aSizer.Add(assetSizer, 1, wx.EXPAND)

        self.SetSizer(mainSizer)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)
示例#9
0
  def __init__(self,parent):
    BasePanel.__init__(self,parent,USECASE_ID)
    b = Borg()
    self.dbProxy = b.dbProxy
    mainSizer = wx.BoxSizer(wx.VERTICAL)

    summBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
    mainSizer.Add(summBoxSizer,0,wx.EXPAND)
    summBoxSizer.Add(self.buildTextSizer('Name',(87,30),USECASE_TEXTNAME_ID),1,wx.EXPAND)
    summBoxSizer.Add(self.buildTextSizer('Code',(87,30),USECASE_TEXTSHORTCODE_ID),1,wx.EXPAND)
    mainSizer.Add(self.buildTagCtrlSizer((87,30),USECASE_TAGS_ID),0,wx.EXPAND)
    mainSizer.Add(self.buildTextSizer('Author/s',(87,30),USECASE_TEXTAUTHOR_ID),0,wx.EXPAND)

    objtBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
    mainSizer.Add(objtBoxSizer,0,wx.EXPAND)
    objtBoxSizer.Add(self.buildMLTextSizer('Description',(87,60),USECASE_TEXTDESCRIPTION_ID),1,wx.EXPAND)

    roleBox = wx.StaticBox(self)
    roleSizer = wx.StaticBoxSizer(roleBox,wx.HORIZONTAL)
    self.roleList = DimensionListCtrl(self,USECASE_LISTACTORS_ID,wx.DefaultSize,'Actor','role',self.dbProxy)
    roleSizer.Add(self.roleList,1,wx.EXPAND)
    objtBoxSizer.Add(roleSizer,1,wx.EXPAND)

    self.environmentPanel = UseCaseEnvironmentPanel(self)
    mainSizer.Add(self.environmentPanel,1,wx.EXPAND)
    self.SetSizer(mainSizer)
示例#10
0
 def __init__(self, parent, winId, dp):
     DimensionListCtrl.__init__(self, parent, winId, wx.DefaultSize,
                                'Environment', 'environment', dp,
                                'Context of use',
                                wx.LC_REPORT | wx.LC_SINGLE_SEL)
     b = Borg()
     self.dbProxy = b.dbProxy
     self.theInheritedEnvironment = ''
     self.theDimMenu.Append(ENVLIST_MENUNEWENVIRONMENT_ID,
                            'New Environment')
     self.theDimMenu.Append(ENVLIST_MENUINHERITENVIRONMENT_ID,
                            'Inherit Environment')
     wx.EVT_MENU(self.theDimMenu, ENVLIST_MENUNEWENVIRONMENT_ID,
                 self.onNewEnvironment)
     wx.EVT_MENU(self.theDimMenu, ENVLIST_MENUINHERITENVIRONMENT_ID,
                 self.onInheritEnvironment)
示例#11
0
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, ATTACKER_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theAttackerId = None
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = EnvironmentListCtrl(
            self, ATTACKERENVIRONMENT_LISTENVIRONMENTS_ID, self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)
        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)
        rmSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(rmSizer, 1, wx.EXPAND)
        self.roleList = DimensionListCtrl(self,
                                          ATTACKERENVIRONMENT_LISTROLES_ID,
                                          wx.DefaultSize, 'Role', 'role',
                                          self.dbProxy)
        roleBox = wx.StaticBox(self)
        roleSizer = wx.StaticBoxSizer(roleBox, wx.HORIZONTAL)
        roleSizer.Add(self.roleList, 1, wx.EXPAND)
        rmSizer.Add(roleSizer, 1, wx.EXPAND)

        self.motiveList = DimensionListCtrl(
            self, ATTACKERENVIRONMENT_LISTMOTIVES_ID, wx.DefaultSize, 'Motive',
            'motivation', self.dbProxy)
        motiveBox = wx.StaticBox(self)
        motiveSizer = wx.StaticBoxSizer(motiveBox, wx.HORIZONTAL)
        motiveSizer.Add(self.motiveList, 1, wx.EXPAND)
        rmSizer.Add(motiveSizer, 1, wx.EXPAND)
        capBox = wx.StaticBox(self)
        capSizer = wx.StaticBoxSizer(capBox, wx.HORIZONTAL)
        environmentDimSizer.Add(capSizer, 1, wx.EXPAND)
        self.capabilitiesList = CapabilitiesListCtrl(
            self, ATTACKERENVIRONMENT_LISTCAPABILITIES_ID, self.dbProxy)
        capSizer.Add(self.capabilitiesList, 1, wx.EXPAND)
        self.SetSizer(mainSizer)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)
示例#12
0
 def __init__(self,parent,structPage):
   wx.Panel.__init__(self,parent)
   topSizer = wx.BoxSizer(wx.VERTICAL)
   asBox = wx.StaticBox(self,-1)
   asBoxSizer = wx.StaticBoxSizer(asBox,wx.HORIZONTAL)
   topSizer.Add(asBoxSizer,1,wx.EXPAND)
   b = Borg()
   self.requirementList = DimensionListCtrl(self,armid.COMPONENT_LISTREQUIREMENTS_ID,wx.DefaultSize,'Requirement','template_requirement',b.dbProxy)
   asBoxSizer.Add(self.requirementList,1,wx.EXPAND)
   self.SetSizer(topSizer)
示例#13
0
 def __init__(self,parent):
   wx.Panel.__init__(self,parent)
   topSizer = wx.BoxSizer(wx.VERTICAL)
   asBox = wx.StaticBox(self,-1)
   asBoxSizer = wx.StaticBoxSizer(asBox,wx.HORIZONTAL)
   topSizer.Add(asBoxSizer,1,wx.EXPAND)
   b = Borg()
   self.goalList = DimensionListCtrl(self,armid.COMPONENT_LISTGOALS_ID,wx.DefaultSize,'Goal','template_goal',b.dbProxy)
   asBoxSizer.Add(self.goalList,1,wx.EXPAND)
   self.SetSizer(topSizer)
示例#14
0
  def __init__(self,parent,winId,dp):
    wx.Panel.__init__(self,parent)
    topSizer = wx.BoxSizer(wx.VERTICAL)

    sgBox = wx.StaticBox(self,-1)
    sgBoxSizer = wx.StaticBoxSizer(sgBox,wx.HORIZONTAL)
    topSizer.Add(sgBoxSizer,1,wx.EXPAND)
    self.concernList = DimensionListCtrl(self,winId,wx.DefaultSize,'Concern','asset',dp)
    sgBoxSizer.Add(self.concernList,1,wx.EXPAND)
    self.SetSizer(topSizer)
  def onDeleteDimension(self,evt):
    idx = self.GetFocusedItem()
    roleToGo = set([self.GetItemText(idx)])
    DimensionListCtrl.onDeleteDimension(self,evt)
    if (self.GetItemCount() > 0):
      noOfPersonas = self.thePersonaList.GetItemCount()
      if (noOfPersonas > 0):
        keysToGo = set([])
        for x in range(noOfPersonas):
           personaTask = (self.thePersonaList.GetItem(x,0)).GetText()
           personaName = (self.thePersonaList.GetItem(x,1)).GetText()
           personaObjt = self.dbProxy.dimensionObject(personaName,'persona')
           if (len( set.difference(set(personaObjt.roles(self.theCurrentEnvironment,'')),roleToGo)) == 0): 
             keysToGo.add((personaTask,personaName)) 

        for ttg,ptg in keysToGo:
          for x in range(noOfPersonas):
            if ((ttg == (self.thePersonaList.GetItem(x,0)).GetText()) and (ptg == (self.thePersonaList.GetItem(x,1)).GetText())):
              self.thePersonaList.DeleteItem(x)
    else:
      self.thePersonaList.DeleteAllItems()  
示例#16
0
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,ROLE_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = DimensionListCtrl(self,ROLE_LISTENVIRONMENTS_ID,wx.DefaultSize,'Environment','environment',self.dbProxy,listStyle=wx.LC_REPORT | wx.LC_SINGLE_SEL)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    rSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(rSizer,1,wx.EXPAND)
    self.responseList = DimensionCostListCtrl(self,ROLE_LISTRESPONSES_ID,'Response')
    responseBox = wx.StaticBox(self)
    responseSizer = wx.StaticBoxSizer(responseBox,wx.HORIZONTAL)
    responseSizer.Add(self.responseList,1,wx.EXPAND)
    rSizer.Add(responseSizer,1,wx.EXPAND)

    cSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(cSizer,1,wx.EXPAND)
    self.cmList = DimensionListCtrl(self,ROLE_LISTCOUNTERMEASURES_ID,wx.DefaultSize,'Countermeasure','countermeasure',self.dbProxy,listStyle = wx.LC_REPORT | wx.LC_SINGLE_SEL)
    cmBox = wx.StaticBox(self)
    cmSizer = wx.StaticBoxSizer(cmBox,wx.HORIZONTAL)
    cmSizer.Add(self.cmList,1,wx.EXPAND)
    cSizer.Add(cmSizer,1,wx.EXPAND)

    self.SetSizer(mainSizer)
    self.environmentList.Unbind(wx.EVT_RIGHT_DOWN)
    self.responseList.Unbind(wx.EVT_RIGHT_DOWN)
    self.cmList.Unbind(wx.EVT_RIGHT_DOWN)
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,armid.ATTACKER_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theAttackerId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,armid.ATTACKERENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)
    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)
    rmSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(rmSizer,1,wx.EXPAND)
    self.roleList = DimensionListCtrl(self,armid.ATTACKERENVIRONMENT_LISTROLES_ID,wx.DefaultSize,'Role','role',self.dbProxy)
    roleBox = wx.StaticBox(self)
    roleSizer = wx.StaticBoxSizer(roleBox,wx.HORIZONTAL)
    roleSizer.Add(self.roleList,1,wx.EXPAND)
    rmSizer.Add(roleSizer,1,wx.EXPAND)

    self.motiveList = DimensionListCtrl(self,armid.ATTACKERENVIRONMENT_LISTMOTIVES_ID,wx.DefaultSize,'Motive','motivation',self.dbProxy)
    motiveBox = wx.StaticBox(self)
    motiveSizer = wx.StaticBoxSizer(motiveBox,wx.HORIZONTAL)
    motiveSizer.Add(self.motiveList,1,wx.EXPAND)
    rmSizer.Add(motiveSizer,1,wx.EXPAND)
    capBox = wx.StaticBox(self)
    capSizer = wx.StaticBoxSizer(capBox,wx.HORIZONTAL)
    environmentDimSizer.Add(capSizer,1,wx.EXPAND)
    self.capabilitiesList = CapabilitiesListCtrl(self,armid.ATTACKERENVIRONMENT_LISTCAPABILITIES_ID,self.dbProxy)
    capSizer.Add(self.capabilitiesList,1,wx.EXPAND)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,MITIGATE_PANELENVIRONMENT_ID)
    self.theResponsePanel = parent
    self.dbProxy = dp
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = RiskEnvironmentListCtrl(self,MITIGATE_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)
    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    typeBox = wx.StaticBox(self,-1,'Type')
    typeBoxSizer = wx.StaticBoxSizer(typeBox,wx.HORIZONTAL)
    environmentDimSizer.Add(typeBoxSizer,0,wx.EXPAND)
    self.typeCombo = wx.ComboBox(self,MITIGATE_COMBOTYPE_ID,"",choices=['Deter','Prevent','Detect','React'],style=wx.CB_READONLY)
    typeBoxSizer.Add(self.typeCombo,1,wx.EXPAND)
   
    pointBox = wx.StaticBox(self,-1,'Detection Point')
    pointBoxSizer = wx.StaticBoxSizer(pointBox,wx.HORIZONTAL)
    environmentDimSizer.Add(pointBoxSizer,0,wx.EXPAND)
    self.pointCombo = wx.ComboBox(self,MITIGATE_COMBODETECTIONPOINT_ID,"",choices=['Before','At','After'],style=wx.CB_READONLY)
    pointBoxSizer.Add(self.pointCombo,1,wx.EXPAND)


    dmBox = wx.StaticBox(self,-1,)
    dmBoxSizer = wx.StaticBoxSizer(dmBox,wx.HORIZONTAL)
    environmentDimSizer.Add(dmBoxSizer,1,wx.EXPAND)
    self.dmList = DimensionListCtrl(self,MITIGATE_LISTDETMECH_ID,wx.DefaultSize,'Detection Mechanism','detection_mechanism',self.dbProxy,listStyle=wx.LC_REPORT)
    dmBoxSizer.Add(self.dmList,1,wx.EXPAND)

    self.typeCombo.Disable()
    self.pointCombo.Disable() 
    self.dmList.Disable()
    
    self.SetSizer(mainSizer)
    self.typeCombo.Bind(wx.EVT_COMBOBOX,self.onTypeChange)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
示例#19
0
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent)
        self.dbProxy = dp
        topSizer = wx.BoxSizer(wx.VERTICAL)

        directBox = wx.StaticBox(self, -1, 'Direct/Indirect Persona')
        directSizer = wx.StaticBoxSizer(directBox, wx.HORIZONTAL)
        topSizer.Add(directSizer, 0, wx.EXPAND)
        self.directCtrl = wx.CheckBox(self, PERSONA_CHECKDIRECT_ID)
        self.directCtrl.SetValue(True)
        directSizer.Add(self.directCtrl, 0, wx.EXPAND)

        roleBox = wx.StaticBox(self)
        roleSizer = wx.StaticBoxSizer(roleBox, wx.HORIZONTAL)
        topSizer.Add(roleSizer, 1, wx.EXPAND)
        self.roleList = DimensionListCtrl(self, PERSONA_LISTROLES_ID,
                                          wx.DefaultSize, 'Role', 'role',
                                          self.dbProxy)
        roleSizer.Add(self.roleList, 1, wx.EXPAND)

        self.SetSizer(topSizer)
示例#20
0
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent)
        self.dbProxy = dp
        topSizer = wx.BoxSizer(wx.VERTICAL)

        targetSizer = wx.BoxSizer(wx.HORIZONTAL)
        topSizer.Add(targetSizer, 1, wx.EXPAND)

        reqBox = wx.StaticBox(self, -1)
        reqBoxSizer = wx.StaticBoxSizer(reqBox, wx.HORIZONTAL)
        targetSizer.Add(reqBoxSizer, 1, wx.EXPAND)
        self.reqList = DimensionListCtrl(
            self,
            armid.COUNTERMEASURE_LISTREQUIREMENTS_ID,
            wx.DefaultSize,
            'Requirement',
            'requirement',
            self.dbProxy,
            listStyle=wx.LC_REPORT | wx.LC_SINGLE_SEL)
        reqBoxSizer.Add(self.reqList, 1, wx.EXPAND)

        targetBox = wx.StaticBox(self, -1)
        targetBoxSizer = wx.StaticBoxSizer(targetBox, wx.HORIZONTAL)
        targetSizer.Add(targetBoxSizer, 1, wx.HORIZONTAL | wx.EXPAND)
        self.targetList = TargetListCtrl(self,
                                         armid.COUNTERMEASURE_LISTTARGETS_ID)
        targetBoxSizer.Add(self.targetList, 1, wx.EXPAND)

        propertiesBox = wx.StaticBox(self, -1)
        propertiesBoxSizer = wx.StaticBoxSizer(propertiesBox, wx.HORIZONTAL)
        topSizer.Add(propertiesBoxSizer, 1, wx.EXPAND)
        values = self.dbProxy.getDimensionNames('countermeasure_value')
        valueLookup = ValueDictionary(values)
        self.propertiesList = PropertiesListCtrl(
            self, armid.COUNTERMEASURE_LISTPROPERTIES_ID, valueLookup)
        propertiesBoxSizer.Add(self.propertiesList, 1, wx.EXPAND)

        self.SetSizer(topSizer)
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,ENVIRONMENT_PANELENVIRONMENTPROPERTIES_ID)
    self.theEnvironmentPanel= parent

    mainSizer = wx.BoxSizer(wx.VERTICAL)

    environmentBox = wx.StaticBox(self,-1,)
    environmentFrameSizer = wx.StaticBoxSizer(environmentBox,wx.VERTICAL)
    mainSizer.Add(environmentFrameSizer,1,wx.EXPAND)
    self.environmentList = DimensionListCtrl(self,ENVIRONMENT_LISTENVIRONMENTS_ID,wx.DefaultSize,'Environment','environment',dp,'Adding one or more environments indicates that this is a composite environment')
    environmentFrameSizer.Add(self.environmentList,1,wx.EXPAND)

    propertiesBox = wx.StaticBox(self,-1,'Duplication properties')
    propertiesFrameSizer = wx.StaticBoxSizer(propertiesBox,wx.VERTICAL)
    mainSizer.Add(propertiesFrameSizer,1,wx.EXPAND)
    propertiesSizer = wx.FlexGridSizer(rows = 2, cols = 3)
    propertiesFrameSizer.Add(propertiesSizer,1,wx.EXPAND)
    propertiesSizer.Add(wx.StaticText(self,-1,'Override'))
    self.overrideRadio = wx.RadioButton(self,ENVIRONMENT_RADIOOVERRIDE_ID,style=wx.RB_GROUP)
    self.overrideRadio.SetToolTip(wx.ToolTip('If an artifact exists in multiple environments, choose the artifact\'s value for the overriding environment.'))
    propertiesSizer.Add(self.overrideRadio)
    self.overrideCombo = wx.ComboBox(self,ENVIRONMENT_COMBOOVERRIDE_ID,'',choices=[],style=wx.CB_READONLY | wx.CB_DROPDOWN)
    propertiesSizer.Add(self.overrideCombo,0,wx.EXPAND)
    propertiesSizer.Add(wx.StaticText(self,-1,'Maximise'))
    self.maxRadio = wx.RadioButton(self,ENVIRONMENT_RADIOMAXIMISE_ID)
    self.maxRadio.SetToolTip(wx.ToolTip('If an artifact exists in multiple environments, choose the artifact\'s maximal values.'))
    propertiesSizer.Add(self.maxRadio)
    propertiesSizer.AddGrowableCol(2)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.onEnvironmentAdded)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.onEnvironmentDeleted)
    self.overrideRadio.Bind(wx.EVT_RADIOBUTTON,self.onOverrideClick)
    self.maxRadio.Bind(wx.EVT_RADIOBUTTON,self.onMaximiseClick)
    self.overrideRadio.Disable()
    self.overrideCombo.Disable()
    self.maxRadio.Disable()
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,armid.VULNERABILITY_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theVulId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,armid.VULNERABILITYENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    sevBox = wx.StaticBox(self)
    sevSizer = wx.StaticBoxSizer(sevBox,wx.HORIZONTAL)
    environmentDimSizer.Add(sevSizer,0,wx.EXPAND)
    sevSizer.Add(wx.StaticText(self,-1,'Severity'))
    sevList = ['Negligible','Marginal','Critical','Catastrophic']
    self.sevCtrl = wx.ComboBox(self,armid.VULNERABILITYENVIRONMENT_COMBOSEVERITY_ID,choices=sevList,size=wx.DefaultSize,style=wx.CB_READONLY)
    sevSizer.Add(self.sevCtrl,1,wx.EXPAND) 

    aSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(aSizer,1,wx.EXPAND)
    self.assetList = DimensionListCtrl(self,armid.VULNERABILITYENVIRONMENT_LISTASSETS_ID,wx.DefaultSize,'Asset','asset',self.dbProxy)
    assetBox = wx.StaticBox(self)
    assetSizer = wx.StaticBoxSizer(assetBox,wx.HORIZONTAL)
    assetSizer.Add(self.assetList,1,wx.EXPAND)
    aSizer.Add(assetSizer,1,wx.EXPAND)

    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent)
    self.dbProxy = dp
    topSizer = wx.BoxSizer(wx.VERTICAL)

    depsBox = wx.StaticBox(self,-1,'Dependencies')
    depsBoxSizer = wx.StaticBoxSizer(depsBox,wx.VERTICAL)
    topSizer.Add(depsBoxSizer,0,wx.EXPAND)
    self.dependenciesCtrl = wx.TextCtrl(self,armid.TASK_TEXTDEPENDENCIES_ID,'',size=(150,100),style= wx.TE_MULTILINE)
    depsBoxSizer.Add(self.dependenciesCtrl,1,wx.EXPAND)

    personaBox = wx.StaticBox(self)
    personaSizer = wx.StaticBoxSizer(personaBox,wx.HORIZONTAL)
    topSizer.Add(personaSizer,0,wx.EXPAND)
    self.personaList = TaskPersonaListCtrl(self,armid.TASK_LISTPERSONAS_ID,self.dbProxy)
    personaSizer.Add(self.personaList,1,wx.EXPAND)

    assetBox = wx.StaticBox(self)
    assetSizer = wx.StaticBoxSizer(assetBox,wx.HORIZONTAL)
    topSizer.Add(assetSizer,1,wx.EXPAND)
    self.assetList = DimensionListCtrl(self,armid.TASK_LISTASSETS_ID,wx.DefaultSize,'Concerns','asset',self.dbProxy)
    assetSizer.Add(self.assetList,1,wx.EXPAND)

    self.SetSizer(topSizer)
示例#24
0
class AttackerEnvironmentPanel(wx.Panel):
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, ATTACKER_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theAttackerId = None
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = EnvironmentListCtrl(
            self, ATTACKERENVIRONMENT_LISTENVIRONMENTS_ID, self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)
        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)
        rmSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(rmSizer, 1, wx.EXPAND)
        self.roleList = DimensionListCtrl(self,
                                          ATTACKERENVIRONMENT_LISTROLES_ID,
                                          wx.DefaultSize, 'Role', 'role',
                                          self.dbProxy)
        roleBox = wx.StaticBox(self)
        roleSizer = wx.StaticBoxSizer(roleBox, wx.HORIZONTAL)
        roleSizer.Add(self.roleList, 1, wx.EXPAND)
        rmSizer.Add(roleSizer, 1, wx.EXPAND)

        self.motiveList = DimensionListCtrl(
            self, ATTACKERENVIRONMENT_LISTMOTIVES_ID, wx.DefaultSize, 'Motive',
            'motivation', self.dbProxy)
        motiveBox = wx.StaticBox(self)
        motiveSizer = wx.StaticBoxSizer(motiveBox, wx.HORIZONTAL)
        motiveSizer.Add(self.motiveList, 1, wx.EXPAND)
        rmSizer.Add(motiveSizer, 1, wx.EXPAND)
        capBox = wx.StaticBox(self)
        capSizer = wx.StaticBoxSizer(capBox, wx.HORIZONTAL)
        environmentDimSizer.Add(capSizer, 1, wx.EXPAND)
        self.capabilitiesList = CapabilitiesListCtrl(
            self, ATTACKERENVIRONMENT_LISTCAPABILITIES_ID, self.dbProxy)
        capSizer.Add(self.capabilitiesList, 1, wx.EXPAND)
        self.SetSizer(mainSizer)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)

    def loadControls(self, attacker):
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
        self.theAttackerId = attacker.id()
        environmentNames = []
        for cp in attacker.environmentProperties():
            environmentNames.append(cp.name())
        self.environmentList.load(environmentNames)

        for cp in attacker.environmentProperties():
            environmentName = cp.name()
            self.theEnvironmentDictionary[environmentName] = cp
            environmentNames.append(environmentName)
        environmentName = environmentNames[0]
        p = self.theEnvironmentDictionary[environmentName]
        self.roleList.setEnvironment(environmentName)
        self.roleList.load(p.roles())
        self.motiveList.setEnvironment(environmentName)
        self.motiveList.load(p.motives())
        self.capabilitiesList.setEnvironment(environmentName)
        self.capabilitiesList.load(p.capabilities())
        self.environmentList.Select(0)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)
        self.theSelectedIdx = 0

    def OnEnvironmentSelected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        p = self.theEnvironmentDictionary[environmentName]
        self.roleList.setEnvironment(environmentName)
        self.roleList.load(p.roles())
        self.motiveList.setEnvironment(environmentName)
        self.motiveList.load(p.motives())
        self.capabilitiesList.setEnvironment(environmentName)
        self.capabilitiesList.load(p.capabilities())

    def OnEnvironmentDeselected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = AttackerEnvironmentProperties(
                environmentName, self.roleList.dimensions(),
                self.motiveList.dimensions(),
                self.capabilitiesList.capabilities())

        self.roleList.setEnvironment('')
        self.roleList.DeleteAllItems()
        self.motiveList.setEnvironment('')
        self.motiveList.DeleteAllItems()
        self.capabilitiesList.setEnvironment('')
        self.capabilitiesList.DeleteAllItems()
        self.theSelectedIdx = -1

    def OnAddEnvironment(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = AttackerEnvironmentProperties(
                environmentName, [], [], [])
        self.environmentList.Select(self.theSelectedIdx)
        self.capabilitiesList.setEnvironment(environmentName)
        inheritedEnv = self.environmentList.inheritedEnvironment()
        if (inheritedEnv != '' and self.theAttackerId != None):
            p = self.dbProxy.inheritedAttackerProperties(
                self.theAttackerId, inheritedEnv)
            self.theEnvironmentDictionary[environmentName] = p
            self.roleList.setEnvironment(environmentName)
            self.roleList.load(p.roles())
            self.motiveList.setEnvironment(environmentName)
            self.motiveList.load(p.motives())
            self.capabilitiesList.setEnvironment(environmentName)
            self.capabilitiesList.load(p.capabilities())

    def OnDeleteEnvironment(self, evt):
        selectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(selectedIdx)
        del self.theEnvironmentDictionary[environmentName]
        self.theSelectedIdx = -1

    def environmentProperties(self):
        if (self.theSelectedIdx != -1):
            environmentName = self.environmentList.GetItemText(
                self.theSelectedIdx)
            self.theEnvironmentDictionary[
                environmentName] = AttackerEnvironmentProperties(
                    environmentName, self.roleList.dimensions(),
                    self.motiveList.dimensions(),
                    self.capabilitiesList.capabilities())
        return self.theEnvironmentDictionary.values()
class EnvironmentPropertiesPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,ENVIRONMENT_PANELENVIRONMENTPROPERTIES_ID)
    self.theEnvironmentPanel= parent

    mainSizer = wx.BoxSizer(wx.VERTICAL)

    environmentBox = wx.StaticBox(self,-1,)
    environmentFrameSizer = wx.StaticBoxSizer(environmentBox,wx.VERTICAL)
    mainSizer.Add(environmentFrameSizer,1,wx.EXPAND)
    self.environmentList = DimensionListCtrl(self,ENVIRONMENT_LISTENVIRONMENTS_ID,wx.DefaultSize,'Environment','environment',dp,'Adding one or more environments indicates that this is a composite environment')
    environmentFrameSizer.Add(self.environmentList,1,wx.EXPAND)

    propertiesBox = wx.StaticBox(self,-1,'Duplication properties')
    propertiesFrameSizer = wx.StaticBoxSizer(propertiesBox,wx.VERTICAL)
    mainSizer.Add(propertiesFrameSizer,1,wx.EXPAND)
    propertiesSizer = wx.FlexGridSizer(rows = 2, cols = 3)
    propertiesFrameSizer.Add(propertiesSizer,1,wx.EXPAND)
    propertiesSizer.Add(wx.StaticText(self,-1,'Override'))
    self.overrideRadio = wx.RadioButton(self,ENVIRONMENT_RADIOOVERRIDE_ID,style=wx.RB_GROUP)
    self.overrideRadio.SetToolTip(wx.ToolTip('If an artifact exists in multiple environments, choose the artifact\'s value for the overriding environment.'))
    propertiesSizer.Add(self.overrideRadio)
    self.overrideCombo = wx.ComboBox(self,ENVIRONMENT_COMBOOVERRIDE_ID,'',choices=[],style=wx.CB_READONLY | wx.CB_DROPDOWN)
    propertiesSizer.Add(self.overrideCombo,0,wx.EXPAND)
    propertiesSizer.Add(wx.StaticText(self,-1,'Maximise'))
    self.maxRadio = wx.RadioButton(self,ENVIRONMENT_RADIOMAXIMISE_ID)
    self.maxRadio.SetToolTip(wx.ToolTip('If an artifact exists in multiple environments, choose the artifact\'s maximal values.'))
    propertiesSizer.Add(self.maxRadio)
    propertiesSizer.AddGrowableCol(2)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.onEnvironmentAdded)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.onEnvironmentDeleted)
    self.overrideRadio.Bind(wx.EVT_RADIOBUTTON,self.onOverrideClick)
    self.maxRadio.Bind(wx.EVT_RADIOBUTTON,self.onMaximiseClick)
    self.overrideRadio.Disable()
    self.overrideCombo.Disable()
    self.maxRadio.Disable()

  def load(self,environment):
    environments = environment.environments()
    if (len(environments) > 0):
      self.environmentList.load(environments)
      if (environment.duplicateProperty() == 'Maximise'):
        self.maxRadio.Enable()
        self.maxRadio.SetValue(True)
        self.overrideCombo.Disable()
      else:
        self.overrideRadio.Enable()
        self.overrideCombo.Enable()
        self.overrideRadio.SetValue(True)
        self.overrideCombo.SetStringSelection(environment.overridingEnvironment())

  def onOverrideClick(self,evt):
    if (self.overrideRadio.GetValue() == True):
      self.overrideCombo.Enable()
    else: 
      self.overrideCombo.Disable()

  def onMaximiseClick(self,evt):
    if (self.maxRadio.GetValue() == True):
      self.overrideCombo.Disable()
    else: 
      self.overrideCombo.Enable()

  def onEnvironmentAdded(self,evt):
    currentEnvironmentSelection = ''
    if (self.overrideCombo.GetCount() > 0):
      currentEnvironmentSelection =  self.overrideCombo.GetStringSelection() 
    newItem = self.environmentList.GetItemText(evt.GetIndex())
    if (self.overrideCombo.FindString(newItem) == wx.NOT_FOUND):
      self.overrideCombo.Append(newItem)
    if (len(currentEnvironmentSelection) > 0):
      self.overrideCombo.SetStringSelection(currentEnvironmentSelection)
    self.overrideRadio.Enable()
    self.overrideCombo.Enable()
    self.maxRadio.Enable()
    evt.Skip()

  def onEnvironmentDeleted(self,evt):
    currentEnvironmentSelection = ''
    if (self.overrideCombo.GetCount() > 0):
      currentEnvironmentSelection =  self.overrideCombo.GetStringSelection() 
    deletedItem = self.environmentList.GetItemText(evt.GetIndex())
    self.overrideCombo.Delete(self.overrideCombo.FindString(deletedItem))

    environmentCount = self.overrideCombo.GetCount()
    if ((deletedItem == currentEnvironmentSelection) or (environmentCount == 0)):
      self.overrideCombo.SetValue('')
    else:
      self.overrideCombo.SetStringSelection(currentEnvironmentSelection)

    if (environmentCount == 0):
      self.overrideRadio.Disable()
      self.overrideCombo.Disable()
      self.maxRadio.Disable()
    evt.Skip()


  def environments(self):
    return self.environmentList.dimensions()

  def duplicateProperty(self):
    if (self.maxRadio.GetValue() == True):
      return 'Maximise'
    else: 
      return 'Override'
  
  def overridingEnvironment(self):
    if (self.maxRadio.GetValue() == True):
      return ''
    else:
      return self.overrideCombo.GetValue()
class MitigateEnvironmentPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,MITIGATE_PANELENVIRONMENT_ID)
    self.theResponsePanel = parent
    self.dbProxy = dp
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = RiskEnvironmentListCtrl(self,MITIGATE_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)
    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    typeBox = wx.StaticBox(self,-1,'Type')
    typeBoxSizer = wx.StaticBoxSizer(typeBox,wx.HORIZONTAL)
    environmentDimSizer.Add(typeBoxSizer,0,wx.EXPAND)
    self.typeCombo = wx.ComboBox(self,MITIGATE_COMBOTYPE_ID,"",choices=['Deter','Prevent','Detect','React'],style=wx.CB_READONLY)
    typeBoxSizer.Add(self.typeCombo,1,wx.EXPAND)
   
    pointBox = wx.StaticBox(self,-1,'Detection Point')
    pointBoxSizer = wx.StaticBoxSizer(pointBox,wx.HORIZONTAL)
    environmentDimSizer.Add(pointBoxSizer,0,wx.EXPAND)
    self.pointCombo = wx.ComboBox(self,MITIGATE_COMBODETECTIONPOINT_ID,"",choices=['Before','At','After'],style=wx.CB_READONLY)
    pointBoxSizer.Add(self.pointCombo,1,wx.EXPAND)


    dmBox = wx.StaticBox(self,-1,)
    dmBoxSizer = wx.StaticBoxSizer(dmBox,wx.HORIZONTAL)
    environmentDimSizer.Add(dmBoxSizer,1,wx.EXPAND)
    self.dmList = DimensionListCtrl(self,MITIGATE_LISTDETMECH_ID,wx.DefaultSize,'Detection Mechanism','detection_mechanism',self.dbProxy,listStyle=wx.LC_REPORT)
    dmBoxSizer.Add(self.dmList,1,wx.EXPAND)

    self.typeCombo.Disable()
    self.pointCombo.Disable() 
    self.dmList.Disable()
    
    self.SetSizer(mainSizer)
    self.typeCombo.Bind(wx.EVT_COMBOBOX,self.onTypeChange)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)

  def onTypeChange(self,evt):
    self.activateTypeCtrls()
    mitType = self.typeCombo.GetValue()
    riskCombo = self.theResponsePanel.FindWindowById(RESPONSE_COMBORISK_ID)
    riskName = riskCombo.GetValue()
    if (riskName != ''):
      riskNameCtrl = self.theResponsePanel.FindWindowById(RESPONSE_TEXTNAME_ID)
      riskNameLabel = mitType + ' ' + riskName
      riskNameCtrl.SetValue(riskNameLabel)

  def activateTypeCtrls(self):
    mitType = self.typeCombo.GetValue()
    if ((mitType == 'Deter') or (mitType == 'Prevent')):
      self.pointCombo.SetValue('')
      self.pointCombo.Disable() 
      self.dmList.DeleteAllItems()
      self.dmList.Disable()
    elif (mitType == 'Detect'):
      self.pointCombo.Enable() 
      self.dmList.Disable()
    elif (mitType == 'React'):
      self.pointCombo.Disable() 
      self.dmList.Enable()
  
  def loadControls(self,accept):
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
    environmentNames = []
    for cp in accept.environmentProperties():
      environmentNames.append(cp.name())
    self.environmentList.load(environmentNames)

    for cp in accept.environmentProperties():
      environmentName = cp.name()
      self.theEnvironmentDictionary[environmentName] = cp
      environmentNames.append(environmentName) 
    environmentName = environmentNames[0]
    p = self.theEnvironmentDictionary[environmentName]
    
    self.typeCombo.SetStringSelection(p.type())
    self.pointCombo.SetStringSelection(p.detectionPoint())
    self.dmList.setEnvironment(environmentName)
    self.dmList.load(p.detectionMechanisms())

    self.environmentList.Select(0)

    self.activateTypeCtrls()
    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
    self.theSelectedIdx = 0

  def OnEnvironmentSelected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    p = self.theEnvironmentDictionary[environmentName]

    self.typeCombo.SetStringSelection(p.type())
    self.pointCombo.SetStringSelection(p.detectionPoint())
    self.dmList.setEnvironment(environmentName)
    self.dmList.load(p.detectionMechanisms())
    self.typeCombo.Enable()
    self.activateTypeCtrls()

  def OnEnvironmentDeselected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = MitigateEnvironmentProperties(environmentName,self.typeCombo.GetValue(),self.pointCombo.GetValue(),self.dmList.dimensions())
    self.typeCombo.SetValue('')
    self.pointCombo.SetValue('')
    self.dmList.setEnvironment('')
    self.dmList.DeleteAllItems()

    self.theSelectedIdx = -1
    self.typeCombo.Disable() 
    self.pointCombo.Disable() 
    self.dmList.Disable() 

  def OnAddEnvironment(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = MitigateEnvironmentProperties(environmentName)
    self.typeCombo.SetValue('')
    self.pointCombo.SetValue('')
    self.dmList.setEnvironment(environmentName)
    self.dmList.DeleteAllItems()
    self.environmentList.Select(self.theSelectedIdx)
    self.typeCombo.Enable() 

  def OnDeleteEnvironment(self,evt):
    selectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(selectedIdx)
    del self.theEnvironmentDictionary[environmentName]
    self.theSelectedIdx = -1

  def environmentProperties(self):
    if (self.theSelectedIdx != -1):
      environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
      properties = MitigateEnvironmentProperties(environmentName,self.typeCombo.GetValue(),self.pointCombo.GetValue(),self.dmList.dimensions())
      self.theEnvironmentDictionary[environmentName] = properties
    for cname in self.environmentList.dimensions():
      p = self.theEnvironmentDictionary[cname]
      mitType = p.type()
      if (len(mitType) == 0):
        exceptionText = 'No mitigation type selected for environment ' + p.name()
        raise EnvironmentValidationError(exceptionText)
      if (mitType == 'Detect') and (len(p.detectionPoint()) == 0):
        exceptionText = 'No detection point selected for environment ' + p.name()
        raise EnvironmentValidationError(exceptionText)
      if (mitType == 'React') and (len(p.detectionMechanisms()) == 0):
        exceptionText = 'No detection mechanisms selected for environment ' + p.name()
        raise EnvironmentValidationError(exceptionText)
    return self.theEnvironmentDictionary.values() 

  def setRisk(self,riskName):
    self.environmentList.setRisk(riskName)
示例#27
0
class RoleEnvironmentPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,ROLE_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = DimensionListCtrl(self,ROLE_LISTENVIRONMENTS_ID,wx.DefaultSize,'Environment','environment',self.dbProxy,listStyle=wx.LC_REPORT | wx.LC_SINGLE_SEL)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    rSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(rSizer,1,wx.EXPAND)
    self.responseList = DimensionCostListCtrl(self,ROLE_LISTRESPONSES_ID,'Response')
    responseBox = wx.StaticBox(self)
    responseSizer = wx.StaticBoxSizer(responseBox,wx.HORIZONTAL)
    responseSizer.Add(self.responseList,1,wx.EXPAND)
    rSizer.Add(responseSizer,1,wx.EXPAND)

    cSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(cSizer,1,wx.EXPAND)
    self.cmList = DimensionListCtrl(self,ROLE_LISTCOUNTERMEASURES_ID,wx.DefaultSize,'Countermeasure','countermeasure',self.dbProxy,listStyle = wx.LC_REPORT | wx.LC_SINGLE_SEL)
    cmBox = wx.StaticBox(self)
    cmSizer = wx.StaticBoxSizer(cmBox,wx.HORIZONTAL)
    cmSizer.Add(self.cmList,1,wx.EXPAND)
    cSizer.Add(cmSizer,1,wx.EXPAND)

    self.SetSizer(mainSizer)
    self.environmentList.Unbind(wx.EVT_RIGHT_DOWN)
    self.responseList.Unbind(wx.EVT_RIGHT_DOWN)
    self.cmList.Unbind(wx.EVT_RIGHT_DOWN)
    
  def loadControls(self,role):
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)

# We load the environment name control before anything else.  Weird stuff happens if we don't do this.  Don't ask me why!!!
    environmentNames = []
    for cp in role.environmentProperties():
      environmentNames.append(cp.name())
    self.environmentList.load(environmentNames)

    for cp in role.environmentProperties():
      environmentName = cp.name()
      self.theEnvironmentDictionary[environmentName] = cp

    if (len(environmentNames) > 0):
      environmentName = environmentNames[0]
      p = self.theEnvironmentDictionary[environmentName]
      self.responseList.load(p.responses()) 
      self.cmList.load(p.countermeasures()) 
      self.environmentList.Select(0)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
    self.theSelectedIdx = 0

  def OnEnvironmentSelected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    p = self.theEnvironmentDictionary[environmentName]
    self.responseList.load(p.responses()) 
    self.cmList.load(p.countermeasures())
      
  def OnEnvironmentDeselected(self,evt):
    self.responseList.DeleteAllItems() 
    self.cmList.DeleteAllItems() 
    self.theSelectedIdx = -1
示例#28
0
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, armid.MITIGATE_PANELENVIRONMENT_ID)
        self.theResponsePanel = parent
        self.dbProxy = dp
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = RiskEnvironmentListCtrl(
            self, armid.MITIGATE_LISTENVIRONMENTS_ID, self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)
        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        typeBox = wx.StaticBox(self, -1, 'Type')
        typeBoxSizer = wx.StaticBoxSizer(typeBox, wx.HORIZONTAL)
        environmentDimSizer.Add(typeBoxSizer, 0, wx.EXPAND)
        self.typeCombo = wx.ComboBox(
            self,
            armid.MITIGATE_COMBOTYPE_ID,
            "",
            choices=['Deter', 'Prevent', 'Detect', 'React'],
            style=wx.CB_READONLY)
        typeBoxSizer.Add(self.typeCombo, 1, wx.EXPAND)

        pointBox = wx.StaticBox(self, -1, 'Detection Point')
        pointBoxSizer = wx.StaticBoxSizer(pointBox, wx.HORIZONTAL)
        environmentDimSizer.Add(pointBoxSizer, 0, wx.EXPAND)
        self.pointCombo = wx.ComboBox(self,
                                      armid.MITIGATE_COMBODETECTIONPOINT_ID,
                                      "",
                                      choices=['Before', 'At', 'After'],
                                      style=wx.CB_READONLY)
        pointBoxSizer.Add(self.pointCombo, 1, wx.EXPAND)

        dmBox = wx.StaticBox(
            self,
            -1,
        )
        dmBoxSizer = wx.StaticBoxSizer(dmBox, wx.HORIZONTAL)
        environmentDimSizer.Add(dmBoxSizer, 1, wx.EXPAND)
        self.dmList = DimensionListCtrl(self,
                                        armid.MITIGATE_LISTDETMECH_ID,
                                        wx.DefaultSize,
                                        'Detection Mechanism',
                                        'detection_mechanism',
                                        self.dbProxy,
                                        listStyle=wx.LC_REPORT)
        dmBoxSizer.Add(self.dmList, 1, wx.EXPAND)

        self.typeCombo.Disable()
        self.pointCombo.Disable()
        self.dmList.Disable()

        self.SetSizer(mainSizer)
        self.typeCombo.Bind(wx.EVT_COMBOBOX, self.onTypeChange)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)
class AttackerEnvironmentPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,armid.ATTACKER_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theAttackerId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,armid.ATTACKERENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)
    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)
    rmSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(rmSizer,1,wx.EXPAND)
    self.roleList = DimensionListCtrl(self,armid.ATTACKERENVIRONMENT_LISTROLES_ID,wx.DefaultSize,'Role','role',self.dbProxy)
    roleBox = wx.StaticBox(self)
    roleSizer = wx.StaticBoxSizer(roleBox,wx.HORIZONTAL)
    roleSizer.Add(self.roleList,1,wx.EXPAND)
    rmSizer.Add(roleSizer,1,wx.EXPAND)

    self.motiveList = DimensionListCtrl(self,armid.ATTACKERENVIRONMENT_LISTMOTIVES_ID,wx.DefaultSize,'Motive','motivation',self.dbProxy)
    motiveBox = wx.StaticBox(self)
    motiveSizer = wx.StaticBoxSizer(motiveBox,wx.HORIZONTAL)
    motiveSizer.Add(self.motiveList,1,wx.EXPAND)
    rmSizer.Add(motiveSizer,1,wx.EXPAND)
    capBox = wx.StaticBox(self)
    capSizer = wx.StaticBoxSizer(capBox,wx.HORIZONTAL)
    environmentDimSizer.Add(capSizer,1,wx.EXPAND)
    self.capabilitiesList = CapabilitiesListCtrl(self,armid.ATTACKERENVIRONMENT_LISTCAPABILITIES_ID,self.dbProxy)
    capSizer.Add(self.capabilitiesList,1,wx.EXPAND)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)


  def loadControls(self,attacker):
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
    self.theAttackerId = attacker.id()
    environmentNames = []
    for cp in attacker.environmentProperties():
      environmentNames.append(cp.name())
    self.environmentList.load(environmentNames)

    for cp in attacker.environmentProperties():
      environmentName = cp.name()
      self.theEnvironmentDictionary[environmentName] = cp
      environmentNames.append(environmentName) 
    environmentName = environmentNames[0]
    p = self.theEnvironmentDictionary[environmentName]
    self.roleList.setEnvironment(environmentName)
    self.roleList.load(p.roles()) 
    self.motiveList.setEnvironment(environmentName)
    self.motiveList.load(p.motives()) 
    self.capabilitiesList.setEnvironment(environmentName)
    self.capabilitiesList.load(p.capabilities())
    self.environmentList.Select(0)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
    self.theSelectedIdx = 0

  def OnEnvironmentSelected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    p = self.theEnvironmentDictionary[environmentName]
    self.roleList.setEnvironment(environmentName)
    self.roleList.load(p.roles()) 
    self.motiveList.setEnvironment(environmentName)
    self.motiveList.load(p.motives()) 
    self.capabilitiesList.setEnvironment(environmentName)
    self.capabilitiesList.load(p.capabilities())

  def OnEnvironmentDeselected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = AttackerEnvironmentProperties(environmentName,self.roleList.dimensions(),self.motiveList.dimensions(),self.capabilitiesList.capabilities())

    self.roleList.setEnvironment('')
    self.roleList.DeleteAllItems() 
    self.motiveList.setEnvironment('')
    self.motiveList.DeleteAllItems() 
    self.capabilitiesList.setEnvironment('')
    self.capabilitiesList.DeleteAllItems()
    self.theSelectedIdx = -1

  def OnAddEnvironment(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = AttackerEnvironmentProperties(environmentName,[],[],[])
    self.environmentList.Select(self.theSelectedIdx)
    self.capabilitiesList.setEnvironment(environmentName)
    inheritedEnv = self.environmentList.inheritedEnvironment()
    if (inheritedEnv != '' and self.theAttackerId != None):
      p = self.dbProxy.inheritedAttackerProperties(self.theAttackerId,inheritedEnv)
      self.theEnvironmentDictionary[environmentName] = p
      self.roleList.setEnvironment(environmentName)
      self.roleList.load(p.roles()) 
      self.motiveList.setEnvironment(environmentName)
      self.motiveList.load(p.motives()) 
      self.capabilitiesList.setEnvironment(environmentName)
      self.capabilitiesList.load(p.capabilities())


  def OnDeleteEnvironment(self,evt):
    selectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(selectedIdx)
    del self.theEnvironmentDictionary[environmentName]
    self.theSelectedIdx = -1

  def environmentProperties(self):
    if (self.theSelectedIdx != -1):
      environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
      self.theEnvironmentDictionary[environmentName] = AttackerEnvironmentProperties(environmentName,self.roleList.dimensions(),self.motiveList.dimensions(),self.capabilitiesList.capabilities())
    return self.theEnvironmentDictionary.values() 
示例#30
0
class RoleEnvironmentPanel(wx.Panel):
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, ROLE_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = DimensionListCtrl(self,
                                                 ROLE_LISTENVIRONMENTS_ID,
                                                 wx.DefaultSize,
                                                 'Environment',
                                                 'environment',
                                                 self.dbProxy,
                                                 listStyle=wx.LC_REPORT
                                                 | wx.LC_SINGLE_SEL)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)

        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        rSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(rSizer, 1, wx.EXPAND)
        self.responseList = DimensionCostListCtrl(self, ROLE_LISTRESPONSES_ID,
                                                  'Response')
        responseBox = wx.StaticBox(self)
        responseSizer = wx.StaticBoxSizer(responseBox, wx.HORIZONTAL)
        responseSizer.Add(self.responseList, 1, wx.EXPAND)
        rSizer.Add(responseSizer, 1, wx.EXPAND)

        cSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(cSizer, 1, wx.EXPAND)
        self.cmList = DimensionListCtrl(self,
                                        ROLE_LISTCOUNTERMEASURES_ID,
                                        wx.DefaultSize,
                                        'Countermeasure',
                                        'countermeasure',
                                        self.dbProxy,
                                        listStyle=wx.LC_REPORT
                                        | wx.LC_SINGLE_SEL)
        cmBox = wx.StaticBox(self)
        cmSizer = wx.StaticBoxSizer(cmBox, wx.HORIZONTAL)
        cmSizer.Add(self.cmList, 1, wx.EXPAND)
        cSizer.Add(cmSizer, 1, wx.EXPAND)

        self.SetSizer(mainSizer)
        self.environmentList.Unbind(wx.EVT_RIGHT_DOWN)
        self.responseList.Unbind(wx.EVT_RIGHT_DOWN)
        self.cmList.Unbind(wx.EVT_RIGHT_DOWN)

    def loadControls(self, role):
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)

        # We load the environment name control before anything else.  Weird stuff happens if we don't do this.  Don't ask me why!!!
        environmentNames = []
        for cp in role.environmentProperties():
            environmentNames.append(cp.name())
        self.environmentList.load(environmentNames)

        for cp in role.environmentProperties():
            environmentName = cp.name()
            self.theEnvironmentDictionary[environmentName] = cp

        if (len(environmentNames) > 0):
            environmentName = environmentNames[0]
            p = self.theEnvironmentDictionary[environmentName]
            self.responseList.load(p.responses())
            self.cmList.load(p.countermeasures())
            self.environmentList.Select(0)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)
        self.theSelectedIdx = 0

    def OnEnvironmentSelected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        p = self.theEnvironmentDictionary[environmentName]
        self.responseList.load(p.responses())
        self.cmList.load(p.countermeasures())

    def OnEnvironmentDeselected(self, evt):
        self.responseList.DeleteAllItems()
        self.cmList.DeleteAllItems()
        self.theSelectedIdx = -1
class ThreatEnvironmentPanel(wx.Panel):
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, armid.THREAT_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theThreatId = None
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = EnvironmentListCtrl(
            self, armid.THREATENVIRONMENT_LISTENVIRONMENTS_ID, self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)

        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        lhoodBox = wx.StaticBox(self)
        lhoodSizer = wx.StaticBoxSizer(lhoodBox, wx.HORIZONTAL)
        environmentDimSizer.Add(lhoodSizer, 0, wx.EXPAND)
        lhoodSizer.Add(wx.StaticText(self, -1, 'Likelihood'))
        lhoodList = [
            'Incredible', 'Improbable', 'Remote', 'Occasional', 'Probable',
            'Frequent'
        ]
        self.lhoodCtrl = wx.ComboBox(
            self,
            armid.THREATENVIRONMENT_COMBOLIKELIHOOD_ID,
            choices=lhoodList,
            size=wx.DefaultSize,
            style=wx.CB_READONLY)
        lhoodSizer.Add(self.lhoodCtrl, 1, wx.EXPAND)

        aaSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(aaSizer, 1, wx.EXPAND)
        self.attackerList = DimensionListCtrl(
            self, armid.THREATENVIRONMENT_LISTATTACKERS_ID, wx.DefaultSize,
            'Attacker', 'attacker', self.dbProxy)
        attackerBox = wx.StaticBox(self)
        attackerSizer = wx.StaticBoxSizer(attackerBox, wx.HORIZONTAL)
        attackerSizer.Add(self.attackerList, 1, wx.EXPAND)
        aaSizer.Add(attackerSizer, 1, wx.EXPAND)

        self.assetList = DimensionListCtrl(
            self, armid.THREATENVIRONMENT_LISTASSETS_ID, wx.DefaultSize,
            'Asset', 'asset', self.dbProxy)
        assetBox = wx.StaticBox(self)
        assetSizer = wx.StaticBoxSizer(assetBox, wx.HORIZONTAL)
        assetSizer.Add(self.assetList, 1, wx.EXPAND)
        aaSizer.Add(assetSizer, 1, wx.EXPAND)

        propertiesBox = wx.StaticBox(self)
        propertiesSizer = wx.StaticBoxSizer(propertiesBox, wx.HORIZONTAL)
        environmentDimSizer.Add(propertiesSizer, 1, wx.EXPAND)
        values = self.dbProxy.getDimensionNames('threat_value')
        valueLookup = ValueDictionary(values)
        self.propertiesList = PropertiesListCtrl(
            self, armid.THREATENVIRONMENT_LISTPROPERTIES_ID, valueLookup)
        propertiesSizer.Add(self.propertiesList, 1, wx.EXPAND)
        self.SetSizer(mainSizer)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)

    def loadControls(self, threat):
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
        self.theThreatId = threat.id()
        # We load the environment name control before anything else.  Weird stuff happens if we don't do this.  Don't ask me why!!!
        environmentNames = []
        if (len(threat.environmentProperties()) > 0):
            for cp in threat.environmentProperties():
                environmentNames.append(cp.name())
            self.environmentList.load(environmentNames)
            for cp in threat.environmentProperties():
                environmentName = cp.name()
                self.theEnvironmentDictionary[environmentName] = cp
            environmentName = environmentNames[0]
            p = self.theEnvironmentDictionary[environmentName]
            self.lhoodCtrl.SetStringSelection(p.likelihood())
            self.attackerList.setEnvironment(environmentName)
            self.attackerList.load(p.attackers())
            self.assetList.setEnvironment(environmentName)
            self.assetList.load(p.assets())
            self.propertiesList.setEnvironment(environmentName)
            self.propertiesList.load(p.properties(), p.rationale())
            self.environmentList.Select(0)

        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)
        self.theSelectedIdx = 0

    def OnEnvironmentSelected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        p = self.theEnvironmentDictionary[environmentName]
        self.lhoodCtrl.SetStringSelection(p.likelihood())
        self.attackerList.setEnvironment(environmentName)
        self.attackerList.load(p.attackers())
        self.assetList.setEnvironment(environmentName)
        self.assetList.load(p.assets())
        self.propertiesList.setEnvironment(environmentName)
        self.propertiesList.load(p.properties(), p.rationale())

    def OnEnvironmentDeselected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        syProperties, pRationale = self.propertiesList.properties()
        self.theEnvironmentDictionary[
            environmentName] = ThreatEnvironmentProperties(
                environmentName, self.lhoodCtrl.GetValue(),
                self.assetList.dimensions(), self.attackerList.dimensions(),
                syProperties, pRationale)
        self.lhoodCtrl.SetValue('')
        self.attackerList.setEnvironment('')
        self.attackerList.DeleteAllItems()
        self.assetList.setEnvironment('')
        self.assetList.DeleteAllItems()
        self.propertiesList.setEnvironment('')
        self.propertiesList.DeleteAllItems()
        self.theSelectedIdx = -1

    def OnAddEnvironment(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = ThreatEnvironmentProperties(
                environmentName, '', [], [], [0, 0, 0, 0, 0, 0, 0, 0], [
                    'None', 'None', 'None', 'None', 'None', 'None', 'None',
                    'None'
                ])
        self.environmentList.Select(self.theSelectedIdx)
        self.attackerList.setEnvironment(environmentName)
        self.assetList.setEnvironment(environmentName)
        self.propertiesList.setEnvironment(environmentName)
        inheritedEnv = self.environmentList.inheritedEnvironment()
        if (inheritedEnv != '' and self.theThreatId != None):
            p = self.dbProxy.inheritedThreatProperties(self.theThreatId,
                                                       inheritedEnv)
            self.theEnvironmentDictionary[environmentName] = p
            self.lhoodCtrl.SetStringSelection(p.likelihood())
            self.attackerList.setEnvironment(environmentName)
            self.attackerList.load(p.attackers())
            self.assetList.setEnvironment(environmentName)
            self.assetList.load(p.assets())
            self.propertiesList.setEnvironment(environmentName)
            self.propertiesList.load(p.properties(), p.rationale())

    def OnDeleteEnvironment(self, evt):
        selectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(selectedIdx)
        del self.theEnvironmentDictionary[environmentName]
        self.theSelectedIdx = -1

    def environmentProperties(self):
        if (self.theSelectedIdx != -1):
            environmentName = self.environmentList.GetItemText(
                self.theSelectedIdx)
            syProperties, pRationale = self.propertiesList.properties()
            self.theEnvironmentDictionary[
                environmentName] = ThreatEnvironmentProperties(
                    environmentName, self.lhoodCtrl.GetValue(),
                    self.assetList.dimensions(),
                    self.attackerList.dimensions(), syProperties, pRationale)
        return self.theEnvironmentDictionary.values()
示例#32
0
class MitigateEnvironmentPanel(wx.Panel):
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent, armid.MITIGATE_PANELENVIRONMENT_ID)
        self.theResponsePanel = parent
        self.dbProxy = dp
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = RiskEnvironmentListCtrl(
            self, armid.MITIGATE_LISTENVIRONMENTS_ID, self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)
        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        typeBox = wx.StaticBox(self, -1, 'Type')
        typeBoxSizer = wx.StaticBoxSizer(typeBox, wx.HORIZONTAL)
        environmentDimSizer.Add(typeBoxSizer, 0, wx.EXPAND)
        self.typeCombo = wx.ComboBox(
            self,
            armid.MITIGATE_COMBOTYPE_ID,
            "",
            choices=['Deter', 'Prevent', 'Detect', 'React'],
            style=wx.CB_READONLY)
        typeBoxSizer.Add(self.typeCombo, 1, wx.EXPAND)

        pointBox = wx.StaticBox(self, -1, 'Detection Point')
        pointBoxSizer = wx.StaticBoxSizer(pointBox, wx.HORIZONTAL)
        environmentDimSizer.Add(pointBoxSizer, 0, wx.EXPAND)
        self.pointCombo = wx.ComboBox(self,
                                      armid.MITIGATE_COMBODETECTIONPOINT_ID,
                                      "",
                                      choices=['Before', 'At', 'After'],
                                      style=wx.CB_READONLY)
        pointBoxSizer.Add(self.pointCombo, 1, wx.EXPAND)

        dmBox = wx.StaticBox(
            self,
            -1,
        )
        dmBoxSizer = wx.StaticBoxSizer(dmBox, wx.HORIZONTAL)
        environmentDimSizer.Add(dmBoxSizer, 1, wx.EXPAND)
        self.dmList = DimensionListCtrl(self,
                                        armid.MITIGATE_LISTDETMECH_ID,
                                        wx.DefaultSize,
                                        'Detection Mechanism',
                                        'detection_mechanism',
                                        self.dbProxy,
                                        listStyle=wx.LC_REPORT)
        dmBoxSizer.Add(self.dmList, 1, wx.EXPAND)

        self.typeCombo.Disable()
        self.pointCombo.Disable()
        self.dmList.Disable()

        self.SetSizer(mainSizer)
        self.typeCombo.Bind(wx.EVT_COMBOBOX, self.onTypeChange)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)

    def onTypeChange(self, evt):
        self.activateTypeCtrls()
        mitType = self.typeCombo.GetValue()
        riskCombo = self.theResponsePanel.FindWindowById(
            armid.RESPONSE_COMBORISK_ID)
        riskName = riskCombo.GetValue()
        if (riskName != ''):
            riskNameCtrl = self.theResponsePanel.FindWindowById(
                armid.RESPONSE_TEXTNAME_ID)
            riskNameLabel = mitType + ' ' + riskName
            riskNameCtrl.SetValue(riskNameLabel)

    def activateTypeCtrls(self):
        mitType = self.typeCombo.GetValue()
        if ((mitType == 'Deter') or (mitType == 'Prevent')):
            self.pointCombo.SetValue('')
            self.pointCombo.Disable()
            self.dmList.DeleteAllItems()
            self.dmList.Disable()
        elif (mitType == 'Detect'):
            self.pointCombo.Enable()
            self.dmList.Disable()
        elif (mitType == 'React'):
            self.pointCombo.Disable()
            self.dmList.Enable()

    def loadControls(self, accept):
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
        environmentNames = []
        for cp in accept.environmentProperties():
            environmentNames.append(cp.name())
        self.environmentList.load(environmentNames)

        for cp in accept.environmentProperties():
            environmentName = cp.name()
            self.theEnvironmentDictionary[environmentName] = cp
            environmentNames.append(environmentName)
        environmentName = environmentNames[0]
        p = self.theEnvironmentDictionary[environmentName]

        self.typeCombo.SetStringSelection(p.type())
        self.pointCombo.SetStringSelection(p.detectionPoint())
        self.dmList.setEnvironment(environmentName)
        self.dmList.load(p.detectionMechanisms())

        self.environmentList.Select(0)

        self.activateTypeCtrls()
        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)
        self.theSelectedIdx = 0

    def OnEnvironmentSelected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        p = self.theEnvironmentDictionary[environmentName]

        self.typeCombo.SetStringSelection(p.type())
        self.pointCombo.SetStringSelection(p.detectionPoint())
        self.dmList.setEnvironment(environmentName)
        self.dmList.load(p.detectionMechanisms())
        self.typeCombo.Enable()
        self.activateTypeCtrls()

    def OnEnvironmentDeselected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = MitigateEnvironmentProperties(
                environmentName, self.typeCombo.GetValue(),
                self.pointCombo.GetValue(), self.dmList.dimensions())
        self.typeCombo.SetValue('')
        self.pointCombo.SetValue('')
        self.dmList.setEnvironment('')
        self.dmList.DeleteAllItems()

        self.theSelectedIdx = -1
        self.typeCombo.Disable()
        self.pointCombo.Disable()
        self.dmList.Disable()

    def OnAddEnvironment(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = MitigateEnvironmentProperties(environmentName)
        self.typeCombo.SetValue('')
        self.pointCombo.SetValue('')
        self.dmList.setEnvironment(environmentName)
        self.dmList.DeleteAllItems()
        self.environmentList.Select(self.theSelectedIdx)
        self.typeCombo.Enable()

    def OnDeleteEnvironment(self, evt):
        selectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(selectedIdx)
        del self.theEnvironmentDictionary[environmentName]
        self.theSelectedIdx = -1

    def environmentProperties(self):
        if (self.theSelectedIdx != -1):
            environmentName = self.environmentList.GetItemText(
                self.theSelectedIdx)
            properties = MitigateEnvironmentProperties(
                environmentName, self.typeCombo.GetValue(),
                self.pointCombo.GetValue(), self.dmList.dimensions())
            self.theEnvironmentDictionary[environmentName] = properties
        for cname in self.environmentList.dimensions():
            p = self.theEnvironmentDictionary[cname]
            mitType = p.type()
            if (len(mitType) == 0):
                exceptionText = 'No mitigation type selected for environment ' + p.name(
                )
                raise ARM.EnvironmentValidationError(exceptionText)
            if (mitType == 'Detect') and (len(p.detectionPoint()) == 0):
                exceptionText = 'No detection point selected for environment ' + p.name(
                )
                raise ARM.EnvironmentValidationError(exceptionText)
            if (mitType == 'React') and (len(p.detectionMechanisms()) == 0):
                exceptionText = 'No detection mechanisms selected for environment ' + p.name(
                )
                raise ARM.EnvironmentValidationError(exceptionText)
        return self.theEnvironmentDictionary.values()

    def setRisk(self, riskName):
        self.environmentList.setRisk(riskName)
class ThreatEnvironmentPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,THREAT_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theThreatId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,THREATENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    lhoodBox = wx.StaticBox(self)
    lhoodSizer = wx.StaticBoxSizer(lhoodBox,wx.HORIZONTAL)
    environmentDimSizer.Add(lhoodSizer,0,wx.EXPAND)
    lhoodSizer.Add(wx.StaticText(self,-1,'Likelihood'))
    lhoodList = ['Incredible','Improbable','Remote','Occasional','Probable','Frequent']
    self.lhoodCtrl = wx.ComboBox(self,THREATENVIRONMENT_COMBOLIKELIHOOD_ID,choices=lhoodList,size=wx.DefaultSize,style=wx.CB_READONLY)
    lhoodSizer.Add(self.lhoodCtrl,1,wx.EXPAND) 

    aaSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(aaSizer,1,wx.EXPAND)
    self.attackerList = DimensionListCtrl(self,THREATENVIRONMENT_LISTATTACKERS_ID,wx.DefaultSize,'Attacker','attacker',self.dbProxy)
    attackerBox = wx.StaticBox(self)
    attackerSizer = wx.StaticBoxSizer(attackerBox,wx.HORIZONTAL)
    attackerSizer.Add(self.attackerList,1,wx.EXPAND)
    aaSizer.Add(attackerSizer,1,wx.EXPAND)

    self.assetList = DimensionListCtrl(self,THREATENVIRONMENT_LISTASSETS_ID,wx.DefaultSize,'Asset','asset',self.dbProxy)
    assetBox = wx.StaticBox(self)
    assetSizer = wx.StaticBoxSizer(assetBox,wx.HORIZONTAL)
    assetSizer.Add(self.assetList,1,wx.EXPAND)
    aaSizer.Add(assetSizer,1,wx.EXPAND)

    propertiesBox = wx.StaticBox(self)
    propertiesSizer = wx.StaticBoxSizer(propertiesBox,wx.HORIZONTAL)
    environmentDimSizer.Add(propertiesSizer,1,wx.EXPAND)
    values = self.dbProxy.getDimensionNames('threat_value')
    valueLookup = ValueDictionary(values)
    self.propertiesList = PropertiesListCtrl(self,THREATENVIRONMENT_LISTPROPERTIES_ID,valueLookup)
    propertiesSizer.Add(self.propertiesList,1,wx.EXPAND)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)


  def loadControls(self,threat):
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
    self.theThreatId = threat.id()
# We load the environment name control before anything else.  Weird stuff happens if we don't do this.  Don't ask me why!!!
    environmentNames = []
    if (len(threat.environmentProperties()) > 0):
      for cp in threat.environmentProperties():
        environmentNames.append(cp.name())
      self.environmentList.load(environmentNames)
      for cp in threat.environmentProperties():
        environmentName = cp.name()
        self.theEnvironmentDictionary[environmentName] = cp
      environmentName = environmentNames[0]
      p = self.theEnvironmentDictionary[environmentName]
      self.lhoodCtrl.SetStringSelection(p.likelihood())
      self.attackerList.setEnvironment(environmentName)
      self.attackerList.load(p.attackers()) 
      self.assetList.setEnvironment(environmentName)
      self.assetList.load(p.assets()) 
      self.propertiesList.setEnvironment(environmentName)
      self.propertiesList.load(p.properties(),p.rationale())
      self.environmentList.Select(0)

    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
    self.theSelectedIdx = 0

  def OnEnvironmentSelected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    p = self.theEnvironmentDictionary[environmentName]
    self.lhoodCtrl.SetStringSelection(p.likelihood())
    self.attackerList.setEnvironment(environmentName)
    self.attackerList.load(p.attackers()) 
    self.assetList.setEnvironment(environmentName)
    self.assetList.load(p.assets()) 
    self.propertiesList.setEnvironment(environmentName)
    self.propertiesList.load(p.properties(),p.rationale())

  def OnEnvironmentDeselected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    syProperties,pRationale = self.propertiesList.properties()
    self.theEnvironmentDictionary[environmentName] = ThreatEnvironmentProperties(environmentName,self.lhoodCtrl.GetValue(),self.assetList.dimensions(),self.attackerList.dimensions(),syProperties,pRationale)
    self.lhoodCtrl.SetValue('')
    self.attackerList.setEnvironment('')
    self.attackerList.DeleteAllItems() 
    self.assetList.setEnvironment('')
    self.assetList.DeleteAllItems() 
    self.propertiesList.setEnvironment('')
    self.propertiesList.DeleteAllItems()
    self.theSelectedIdx = -1

  def OnAddEnvironment(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = ThreatEnvironmentProperties(environmentName,'',[],[],[0,0,0,0,0,0,0,0],['None','None','None','None','None','None','None','None'])
    self.environmentList.Select(self.theSelectedIdx)
    self.attackerList.setEnvironment(environmentName)
    self.assetList.setEnvironment(environmentName)
    self.propertiesList.setEnvironment(environmentName)
    inheritedEnv = self.environmentList.inheritedEnvironment()
    if (inheritedEnv != '' and self.theThreatId != None):
      p = self.dbProxy.inheritedThreatProperties(self.theThreatId,inheritedEnv)
      self.theEnvironmentDictionary[environmentName] = p
      self.lhoodCtrl.SetStringSelection(p.likelihood())
      self.attackerList.setEnvironment(environmentName)
      self.attackerList.load(p.attackers()) 
      self.assetList.setEnvironment(environmentName)
      self.assetList.load(p.assets()) 
      self.propertiesList.setEnvironment(environmentName)
      self.propertiesList.load(p.properties(),p.rationale())

  def OnDeleteEnvironment(self,evt):
    selectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(selectedIdx)
    del self.theEnvironmentDictionary[environmentName]
    self.theSelectedIdx = -1

  def environmentProperties(self):
    if (self.theSelectedIdx != -1):
      environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
      syProperties,pRationale = self.propertiesList.properties() 
      self.theEnvironmentDictionary[environmentName] = ThreatEnvironmentProperties(environmentName,self.lhoodCtrl.GetValue(),self.assetList.dimensions(),self.attackerList.dimensions(),syProperties,pRationale)
    return self.theEnvironmentDictionary.values() 
class VulnerabilityEnvironmentPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,armid.VULNERABILITY_PANELENVIRONMENT_ID)
    self.dbProxy = dp
    self.theVulId = None
    self.theEnvironmentDictionary = {}
    self.theSelectedIdx = -1

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentBox = wx.StaticBox(self)
    environmentListSizer = wx.StaticBoxSizer(environmentBox,wx.HORIZONTAL)
    mainSizer.Add(environmentListSizer,0,wx.EXPAND)
    self.environmentList = EnvironmentListCtrl(self,armid.VULNERABILITYENVIRONMENT_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)

    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    sevBox = wx.StaticBox(self)
    sevSizer = wx.StaticBoxSizer(sevBox,wx.HORIZONTAL)
    environmentDimSizer.Add(sevSizer,0,wx.EXPAND)
    sevSizer.Add(wx.StaticText(self,-1,'Severity'))
    sevList = ['Negligible','Marginal','Critical','Catastrophic']
    self.sevCtrl = wx.ComboBox(self,armid.VULNERABILITYENVIRONMENT_COMBOSEVERITY_ID,choices=sevList,size=wx.DefaultSize,style=wx.CB_READONLY)
    sevSizer.Add(self.sevCtrl,1,wx.EXPAND) 

    aSizer = wx.BoxSizer(wx.HORIZONTAL)
    environmentDimSizer.Add(aSizer,1,wx.EXPAND)
    self.assetList = DimensionListCtrl(self,armid.VULNERABILITYENVIRONMENT_LISTASSETS_ID,wx.DefaultSize,'Asset','asset',self.dbProxy)
    assetBox = wx.StaticBox(self)
    assetSizer = wx.StaticBoxSizer(assetBox,wx.HORIZONTAL)
    assetSizer.Add(self.assetList,1,wx.EXPAND)
    aSizer.Add(assetSizer,1,wx.EXPAND)

    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)


  def loadControls(self,vulnerability):
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
    self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
    self.theVulId = vulnerability.id()
# We load the environment name control before anything else.  Weird stuff happens if we don't do this.  Don't ask me why!!!
    environmentNames = []
    if (len(vulnerability.environmentProperties()) > 0):
      for cp in vulnerability.environmentProperties():
        environmentNames.append(cp.name())
      self.environmentList.load(environmentNames)
      for cp in vulnerability.environmentProperties():
        environmentName = cp.name()
        self.theEnvironmentDictionary[environmentName] = cp
      environmentName = environmentNames[0]
      p = self.theEnvironmentDictionary[environmentName]
      self.sevCtrl.SetStringSelection(p.severity())
      self.assetList.setEnvironment(environmentName)
      self.assetList.load(p.assets()) 
      self.environmentList.Select(0)

    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
    self.theSelectedIdx = 0

  def OnEnvironmentSelected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    p = self.theEnvironmentDictionary[environmentName]
    self.sevCtrl.SetStringSelection(p.severity())
    self.assetList.setEnvironment(environmentName)
    self.assetList.load(p.assets()) 
      
  

  def OnEnvironmentDeselected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = VulnerabilityEnvironmentProperties(environmentName,self.sevCtrl.GetValue(),self.assetList.dimensions())
    self.sevCtrl.SetValue('')
    self.assetList.setEnvironment('')
    self.assetList.DeleteAllItems() 
    self.theSelectedIdx = -1

  def OnAddEnvironment(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = VulnerabilityEnvironmentProperties(environmentName,'',[])
    self.environmentList.Select(self.theSelectedIdx)
    self.assetList.setEnvironment(environmentName)
    inheritedEnv = self.environmentList.inheritedEnvironment()
    if (inheritedEnv != '' and self.theVulId != None):
      p = self.dbProxy.inheritedVulnerabilityProperties(self.theVulId,inheritedEnv)
      self.theEnvironmentDictionary[environmentName] = p
      self.sevCtrl.SetStringSelection(p.severity())
      self.assetList.setEnvironment(environmentName)
      self.assetList.load(p.assets()) 

  def OnDeleteEnvironment(self,evt):
    selectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(selectedIdx)
    del self.theEnvironmentDictionary[environmentName]
    self.theSelectedIdx = -1

  def environmentProperties(self):
    if (self.theSelectedIdx != -1):
      environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
      self.theEnvironmentDictionary[environmentName] = VulnerabilityEnvironmentProperties(environmentName,self.sevCtrl.GetValue(),self.assetList.dimensions())
    return self.theEnvironmentDictionary.values() 
示例#35
0
class EnvironmentPropertiesPanel(wx.Panel):
  def __init__(self,parent,dp):
    wx.Panel.__init__(self,parent,armid.ENVIRONMENT_PANELENVIRONMENTPROPERTIES_ID)
    self.theEnvironmentPanel= parent

    mainSizer = wx.BoxSizer(wx.VERTICAL)

    environmentBox = wx.StaticBox(self,-1,)
    environmentFrameSizer = wx.StaticBoxSizer(environmentBox,wx.VERTICAL)
    mainSizer.Add(environmentFrameSizer,1,wx.EXPAND)
    self.environmentList = DimensionListCtrl(self,armid.ENVIRONMENT_LISTENVIRONMENTS_ID,wx.DefaultSize,'Environment','environment',dp,'Adding one or more environments indicates that this is a composite environment')
    environmentFrameSizer.Add(self.environmentList,1,wx.EXPAND)

    propertiesBox = wx.StaticBox(self,-1,'Duplication properties')
    propertiesFrameSizer = wx.StaticBoxSizer(propertiesBox,wx.VERTICAL)
    mainSizer.Add(propertiesFrameSizer,1,wx.EXPAND)
    propertiesSizer = wx.FlexGridSizer(rows = 2, cols = 3)
    propertiesFrameSizer.Add(propertiesSizer,1,wx.EXPAND)
    propertiesSizer.Add(wx.StaticText(self,-1,'Override'))
    self.overrideRadio = wx.RadioButton(self,armid.ENVIRONMENT_RADIOOVERRIDE_ID,style=wx.RB_GROUP)
    self.overrideRadio.SetToolTip(wx.ToolTip('If an artifact exists in multiple environments, choose the artifact\'s value for the overriding environment.'))
    propertiesSizer.Add(self.overrideRadio)
    self.overrideCombo = wx.ComboBox(self,armid.ENVIRONMENT_COMBOOVERRIDE_ID,'',choices=[],style=wx.CB_READONLY | wx.CB_DROPDOWN)
    propertiesSizer.Add(self.overrideCombo,0,wx.EXPAND)
    propertiesSizer.Add(wx.StaticText(self,-1,'Maximise'))
    self.maxRadio = wx.RadioButton(self,armid.ENVIRONMENT_RADIOMAXIMISE_ID)
    self.maxRadio.SetToolTip(wx.ToolTip('If an artifact exists in multiple environments, choose the artifact\'s maximal values.'))
    propertiesSizer.Add(self.maxRadio)
    propertiesSizer.AddGrowableCol(2)
    self.SetSizer(mainSizer)
    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.onEnvironmentAdded)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.onEnvironmentDeleted)
    self.overrideRadio.Bind(wx.EVT_RADIOBUTTON,self.onOverrideClick)
    self.maxRadio.Bind(wx.EVT_RADIOBUTTON,self.onMaximiseClick)
    self.overrideRadio.Disable()
    self.overrideCombo.Disable()
    self.maxRadio.Disable()

  def load(self,environment):
    environments = environment.environments()
    if (len(environments) > 0):
      self.environmentList.load(environments)
      if (environment.duplicateProperty() == 'Maximise'):
        self.maxRadio.Enable()
        self.maxRadio.SetValue(True)
        self.overrideCombo.Disable()
      else:
        self.overrideRadio.Enable()
        self.overrideCombo.Enable()
        self.overrideRadio.SetValue(True)
        self.overrideCombo.SetStringSelection(environment.overridingEnvironment())

  def onOverrideClick(self,evt):
    if (self.overrideRadio.GetValue() == True):
      self.overrideCombo.Enable()
    else: 
      self.overrideCombo.Disable()

  def onMaximiseClick(self,evt):
    if (self.maxRadio.GetValue() == True):
      self.overrideCombo.Disable()
    else: 
      self.overrideCombo.Enable()

  def onEnvironmentAdded(self,evt):
    currentEnvironmentSelection = ''
    if (self.overrideCombo.GetCount() > 0):
      currentEnvironmentSelection =  self.overrideCombo.GetStringSelection() 
    newItem = self.environmentList.GetItemText(evt.GetIndex())
    if (self.overrideCombo.FindString(newItem) == wx.NOT_FOUND):
      self.overrideCombo.Append(newItem)
    if (len(currentEnvironmentSelection) > 0):
      self.overrideCombo.SetStringSelection(currentEnvironmentSelection)
    self.overrideRadio.Enable()
    self.overrideCombo.Enable()
    self.maxRadio.Enable()
    evt.Skip()

  def onEnvironmentDeleted(self,evt):
    currentEnvironmentSelection = ''
    if (self.overrideCombo.GetCount() > 0):
      currentEnvironmentSelection =  self.overrideCombo.GetStringSelection() 
    deletedItem = self.environmentList.GetItemText(evt.GetIndex())
    self.overrideCombo.Delete(self.overrideCombo.FindString(deletedItem))

    environmentCount = self.overrideCombo.GetCount()
    if ((deletedItem == currentEnvironmentSelection) or (environmentCount == 0)):
      self.overrideCombo.SetValue('')
    else:
      self.overrideCombo.SetStringSelection(currentEnvironmentSelection)

    if (environmentCount == 0):
      self.overrideRadio.Disable()
      self.overrideCombo.Disable()
      self.maxRadio.Disable()
    evt.Skip()


  def environments(self):
    return self.environmentList.dimensions()

  def duplicateProperty(self):
    if (self.maxRadio.GetValue() == True):
      return 'Maximise'
    else: 
      return 'Override'
  
  def overridingEnvironment(self):
    if (self.maxRadio.GetValue() == True):
      return ''
    else:
      return self.overrideCombo.GetValue()
 def __init__(self,parent,dp,personaList):
   DimensionListCtrl.__init__(self,parent,COUNTERMEASURE_LISTROLES_ID,wx.DefaultSize,'Role','role',dp,listStyle=wx.LC_REPORT | wx.LC_SINGLE_SEL)
   self.thePersonaList = personaList
class VulnerabilityEnvironmentPanel(wx.Panel):
    def __init__(self, parent, dp):
        wx.Panel.__init__(self, parent,
                          armid.VULNERABILITY_PANELENVIRONMENT_ID)
        self.dbProxy = dp
        self.theVulId = None
        self.theEnvironmentDictionary = {}
        self.theSelectedIdx = -1

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentBox = wx.StaticBox(self)
        environmentListSizer = wx.StaticBoxSizer(environmentBox, wx.HORIZONTAL)
        mainSizer.Add(environmentListSizer, 0, wx.EXPAND)
        self.environmentList = EnvironmentListCtrl(
            self, armid.VULNERABILITYENVIRONMENT_LISTENVIRONMENTS_ID,
            self.dbProxy)
        environmentListSizer.Add(self.environmentList, 1, wx.EXPAND)

        environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(environmentDimSizer, 1, wx.EXPAND)

        sevBox = wx.StaticBox(self)
        sevSizer = wx.StaticBoxSizer(sevBox, wx.HORIZONTAL)
        environmentDimSizer.Add(sevSizer, 0, wx.EXPAND)
        sevSizer.Add(wx.StaticText(self, -1, 'Severity'))
        sevList = ['Negligible', 'Marginal', 'Critical', 'Catastrophic']
        self.sevCtrl = wx.ComboBox(
            self,
            armid.VULNERABILITYENVIRONMENT_COMBOSEVERITY_ID,
            choices=sevList,
            size=wx.DefaultSize,
            style=wx.CB_READONLY)
        sevSizer.Add(self.sevCtrl, 1, wx.EXPAND)

        aSizer = wx.BoxSizer(wx.HORIZONTAL)
        environmentDimSizer.Add(aSizer, 1, wx.EXPAND)
        self.assetList = DimensionListCtrl(
            self, armid.VULNERABILITYENVIRONMENT_LISTASSETS_ID, wx.DefaultSize,
            'Asset', 'asset', self.dbProxy)
        assetBox = wx.StaticBox(self)
        assetSizer = wx.StaticBoxSizer(assetBox, wx.HORIZONTAL)
        assetSizer.Add(self.assetList, 1, wx.EXPAND)
        aSizer.Add(assetSizer, 1, wx.EXPAND)

        self.SetSizer(mainSizer)
        self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,
                                  self.OnAddEnvironment)
        self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,
                                  self.OnDeleteEnvironment)

    def loadControls(self, vulnerability):
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_SELECTED)
        self.environmentList.Unbind(wx.EVT_LIST_ITEM_DESELECTED)
        self.theVulId = vulnerability.id()
        # We load the environment name control before anything else.  Weird stuff happens if we don't do this.  Don't ask me why!!!
        environmentNames = []
        if (len(vulnerability.environmentProperties()) > 0):
            for cp in vulnerability.environmentProperties():
                environmentNames.append(cp.name())
            self.environmentList.load(environmentNames)
            for cp in vulnerability.environmentProperties():
                environmentName = cp.name()
                self.theEnvironmentDictionary[environmentName] = cp
            environmentName = environmentNames[0]
            p = self.theEnvironmentDictionary[environmentName]
            self.sevCtrl.SetStringSelection(p.severity())
            self.assetList.setEnvironment(environmentName)
            self.assetList.load(p.assets())
            self.environmentList.Select(0)

        self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,
                                  self.OnEnvironmentSelected)
        self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                                  self.OnEnvironmentDeselected)
        self.theSelectedIdx = 0

    def OnEnvironmentSelected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        p = self.theEnvironmentDictionary[environmentName]
        self.sevCtrl.SetStringSelection(p.severity())
        self.assetList.setEnvironment(environmentName)
        self.assetList.load(p.assets())

    def OnEnvironmentDeselected(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = VulnerabilityEnvironmentProperties(
                environmentName, self.sevCtrl.GetValue(),
                self.assetList.dimensions())
        self.sevCtrl.SetValue('')
        self.assetList.setEnvironment('')
        self.assetList.DeleteAllItems()
        self.theSelectedIdx = -1

    def OnAddEnvironment(self, evt):
        self.theSelectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
        self.theEnvironmentDictionary[
            environmentName] = VulnerabilityEnvironmentProperties(
                environmentName, '', [])
        self.environmentList.Select(self.theSelectedIdx)
        self.assetList.setEnvironment(environmentName)
        inheritedEnv = self.environmentList.inheritedEnvironment()
        if (inheritedEnv != '' and self.theVulId != None):
            p = self.dbProxy.inheritedVulnerabilityProperties(
                self.theVulId, inheritedEnv)
            self.theEnvironmentDictionary[environmentName] = p
            self.sevCtrl.SetStringSelection(p.severity())
            self.assetList.setEnvironment(environmentName)
            self.assetList.load(p.assets())

    def OnDeleteEnvironment(self, evt):
        selectedIdx = evt.GetIndex()
        environmentName = self.environmentList.GetItemText(selectedIdx)
        del self.theEnvironmentDictionary[environmentName]
        self.theSelectedIdx = -1

    def environmentProperties(self):
        if (self.theSelectedIdx != -1):
            environmentName = self.environmentList.GetItemText(
                self.theSelectedIdx)
            self.theEnvironmentDictionary[
                environmentName] = VulnerabilityEnvironmentProperties(
                    environmentName, self.sevCtrl.GetValue(),
                    self.assetList.dimensions())
        return self.theEnvironmentDictionary.values()
示例#38
0
 def setEnvironment(self,environmentName):
   DimensionListCtrl.setEnvironment(self,environmentName)