Exemplo n.º 1
0
def extractPackage(session_id = None, ignoreValidityCheck = 0, dbProxy = None):
  buf = io.BytesIO()
  zf = zipfile.ZipFile(buf,'w',zipfile.ZIP_DEFLATED)
  zf.writestr('model.xml',extractModel(session_id,ignoreValidityCheck,dbProxy))

  proxy = dbProxy
  if (proxy == None):
    b = Borg()
    proxy = b.get_dbproxy(session_id)
  apNames = proxy.getDimensionNames('component_view','')
  for apName in apNames:
    apBuf = proxy.architecturalPatternToXml(apName)
    zf.writestr(apName + '.xml',apBuf)

  spNames = proxy.getDimensionNames('securitypattern','')
  if (len(spNames) > 0):
    spBuf = proxy.securityPatternsToXml()
    zf.writestr('security_patterns.xml',spBuf)

  for imgName,imgContent in proxy.getImages():
    zf.writestr(imgName,b64decode(imgContent))
  zf.close()
  return buf.getvalue()
Exemplo n.º 2
0
  def testCountermeasure(self):

    icep = CountermeasureEnvironmentProperties(self.iCountermeasures[0]["theEnvironmentProperties"][0][0],[self.iCountermeasures[0]["theEnvironmentProperties"][0][2]],[Target(self.iCountermeasures[0]["theEnvironmentProperties"][0][3],self.iCountermeasures[0]["theEnvironmentProperties"][0][4],"None")],[0,0,0,0,0,0,0,0],['None','None','None','None','None','None','None','None'],self.iCountermeasures[0]["theEnvironmentProperties"][0][1],[self.iCountermeasures[0]["theEnvironmentProperties"][0][5]])
    icm = CountermeasureParameters(self.iCountermeasures[0]["theName"],self.iCountermeasures[0]["theDescription"],self.iCountermeasures[0]["theType"],[],[icep])

    b = Borg()
    b.dbProxy.addCountermeasure(icm)
    ocms = b.dbProxy.getCountermeasures()
    ocm = ocms[self.iCountermeasures[0]["theName"]]
    self.assertEqual(icm.name(), ocm.name())
    self.assertEqual(icm.type(),ocm.type())
    self.assertEqual(icm.description(),ocm.description())

    icm.theName = 'Updated countermeasure'
    icm.setId(ocm.id())
    b.dbProxy.updateCountermeasure(icm)
    ocms = b.dbProxy.getCountermeasures()
    ocm = ocms['Updated countermeasure']
    self.assertEqual('Updated countermeasure', ocm.name())
    self.assertEqual(icm.type(),ocm.type())
    self.assertEqual(icm.description(),ocm.description())

    b.dbProxy.deleteCountermeasure(ocm.id())
Exemplo n.º 3
0
def importDirectoryFile(importFile, isOverwrite=1, session_id=None):
    try:
        parser = xml.sax.make_parser()
        handler = DirectoryContentHandler()
        parser.setContentHandler(handler)
        parser.setEntityResolver(handler)
        parser.parse(importFile)
        vulDir, threatDir = handler.directories()
        vdSize = len(vulDir)
        tdSize = len(threatDir)
        b = Borg()
        db_proxy = b.get_dbproxy(session_id)
        if (vdSize > 0):
            db_proxy.addVulnerabilityDirectory(vulDir, isOverwrite)
        if (tdSize > 0):
            db_proxy.addThreatDirectory(threatDir, isOverwrite)
        msgStr = 'Imported ' + str(
            vdSize) + ' template vulnerabilities and ' + str(
                tdSize) + ' template threats.'
        return msgStr
    except xml.sax.SAXException as e:
        raise ARMException("Error parsing" + importFile + ": " +
                           e.getMessage())
Exemplo n.º 4
0
 def __init__(self,
              tlinks,
              environmentName,
              dp,
              modelLayout,
              fontName=None,
              fontSize=None,
              isTagged=False,
              rankDir='TB'):
     self.theTraceLinks = tlinks
     self.theEnvironmentName = environmentName
     self.dbProxy = dp
     self.theEnvironmentObject = self.dbProxy.dimensionObject(
         self.theEnvironmentName, 'environment')
     self.theGraph = pydot.Dot()
     b = Borg()
     self.fontSize = fontSize or b.fontSize
     self.fontName = fontName or b.fontName
     self.theGraphName = b.tmpDir + '/pydotout.dot'
     self.theRenderer = modelLayout
     self.theGraph.set_graph_defaults(rankdir=rankDir)
     self.theNodeLookup = {}
     self.isTagged = isTagged
Exemplo n.º 5
0
    def __init__(self,
                 associations,
                 envName,
                 db_proxy=None,
                 font_name=None,
                 font_size=None):
        self.theAssociations = associations
        self.theEnvironmentName = envName
        self.fontName = font_name
        self.fontSize = font_size
        self.dbProxy = db_proxy

        b = Borg()

        if font_size is None or font_name is None:
            self.fontName = b.fontName
            self.fontSize = b.fontSize

        self.theGraph = pydot.Dot()
        self.theGraph.set_graph_defaults(rankdir='LR')
        self.theGraphName = b.tmpDir + '/' + 'dfd.dot'
        self.theClusters = {}
        self.tbDict = {}
Exemplo n.º 6
0
def importSynopses(charSyns, refSyns, stepSyns, refConts, ucConts, session_id):
    b = Borg()
    db_proxy = b.get_dbproxy(session_id)
    for cs in charSyns:
        db_proxy.addCharacteristicSynopsis(cs)
    for rs in refSyns:
        db_proxy.addReferenceSynopsis(rs)
    for ucName, envName, stepNo, synName, aType, aName in stepSyns:
        db_proxy.addStepSynopsis(ucName, envName, stepNo, synName, aType,
                                 aName)
    db_proxy.conn.commit()
    for rc in refConts:
        db_proxy.addReferenceContribution(rc)
    for uc in ucConts:
        db_proxy.addUseCaseContribution(uc)

    msgStr = 'Imported ' + str(
        len(charSyns)) + ' characteristic synopses, ' + str(
            len(refSyns)) + ' reference synopses, ' + str(
                len(stepSyns)) + ' step synopses, ' + str(
                    len(refConts)) + ' reference contributions, and ' + str(
                        len(ucConts)) + ' use case contributions.'
    return msgStr
Exemplo n.º 7
0
  def __init__(self,parent):
    wx.Panel.__init__(self,parent,RISKSCATTER_ID)
    b = Borg()
    self.dbProxy = b.dbProxy
    self.dpi = 100
    self.fig = Figure((5.0, 4.0), dpi=self.dpi)
    self.canvas = FigCanvas(self, -1, self.fig)
    self.axes = self.fig.add_subplot(111,xlabel='Severity',ylabel='Likelihood',autoscale_on=False)
    self.axes.set_xticklabels(['Marginal','Critical','Catastrophic'])
    self.axes.set_yticks([0,1,2,3,4,5])
    self.toolbar = NavigationToolbar(self.canvas)

    envs = self.dbProxy.getDimensionNames('environment')
    self.envCombo = wx.ComboBox(self,RISKSCATTER_COMBOENVIRONMENT_ID,envs[0],choices=envs,size=(300,-1),style=wx.CB_DROPDOWN)
    self.envCombo.Bind(wx.EVT_COMBOBOX,self.onEnvironmentChange)
    
    self.vbox = wx.BoxSizer(wx.VERTICAL)
    self.vbox.Add(self.toolbar, 0, wx.EXPAND)
    self.vbox.Add(self.envCombo,0, wx.EXPAND)
    self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
    self.SetSizer(self.vbox)
    self.vbox.Fit(self)
    self.drawScatter(envs[0])
Exemplo n.º 8
0
  def __init__(self,associations,envName,kaosModelType = 'goal',goalName = '', db_proxy=None, font_name=None, font_size=None):
    self.theAssociations = associations
    self.theEnvironmentName = envName
    self.theGoalName = goalName
    self.dbProxy = db_proxy
    self.fontName = font_name
    self.fontSize = font_size

    b = Borg()
    if db_proxy is None: 
      self.dbProxy = b.dbProxy

    if font_size is None or font_name is None:
      self.fontName = b.fontName
      self.fontSize = b.fontSize

    self.theGraph = pydot.Dot()
    self.theKaosModel = kaosModelType
    if (self.theKaosModel == 'task'):
      self.theGraph.set_graph_defaults(rankdir='LR')
    else:
      self.theGraph.set_graph_defaults(rankdir='BT')
    self.theGraphName = b.tmpDir + '/' + self.theKaosModel + '.dot'
Exemplo n.º 9
0
 def onSituate(self, evt):
     tAsset = self.theParentDialog.objts[self.theParentDialog.selectedLabel]
     taId = tAsset.id()
     taName = tAsset.name()
     try:
         b = Borg()
         dbProxy = b.dbProxy
         envs = dbProxy.getEnvironmentNames()
         cDlg = DimensionNameDialog(self, 'environment', envs, 'Select')
         if (cDlg.ShowModal() == DIMNAME_BUTTONACTION_ID):
             sitEnvs = cDlg.dimensionNames()
             assetId = dbProxy.addAsset(
                 cairis.core.AssetParametersFactory.buildFromTemplate(
                     taName, sitEnvs))
             # NB: we don't add anything to asset_template_asset, as we only use this table when the derived asset is part of a situated pattern
             cDlg.Destroy()
     except ARMException, errorText:
         dlg = wx.MessageDialog(self, str(errorText),
                                'Situate template asset',
                                wx.OK | wx.ICON_ERROR)
         dlg.ShowModal()
         dlg.Destroy()
         return
Exemplo n.º 10
0
    def testValueType(self):
        ivt1 = ValueTypeParameters(self.iVtypes[0]["theName"],
                                   self.iVtypes[0]["theDescription"],
                                   self.iVtypes[0]["theType"])
        ivt2 = ValueTypeParameters(self.iVtypes[1]["theName"],
                                   self.iVtypes[1]["theDescription"],
                                   self.iVtypes[1]["theType"])
        b = Borg()
        b.dbProxy.addValueType(ivt1)
        b.dbProxy.addValueType(ivt2)
        oVVtypes = b.dbProxy.getValueTypes('vulnerability_type')
        ovt1 = oVVtypes[ivt1.id()]
        self.assertEqual(ivt1.name(), ovt1.name())
        self.assertEqual(ivt1.description(), ovt1.description())
        self.assertEqual(ivt1.type(), ovt1.type())
        oVTtypes = b.dbProxy.getValueTypes('threat_type')
        ovt2 = oVTtypes[ivt2.id()]
        self.assertEqual(ivt2.name(), ovt2.name())
        self.assertEqual(ivt2.description(), ovt2.description())
        self.assertEqual(ivt2.type(), ovt2.type())

        b.dbProxy.deleteVulnerabilityType(ovt1.id())
        b.dbProxy.deleteThreatType(ovt2.id())
Exemplo n.º 11
0
  def __init__(self,parent):
    wx.Panel.__init__(self,parent,USECASE_PANELENVIRONMENT_ID)
    b = Borg()
    self.dbProxy = b.dbProxy
    self.theUseCaseId = None
    self.theUseCaseName = ''
    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,USECASE_LISTENVIRONMENTS_ID,self.dbProxy)
    environmentListSizer.Add(self.environmentList,1,wx.EXPAND)
    environmentDimSizer = wx.BoxSizer(wx.VERTICAL)
    mainSizer.Add(environmentDimSizer,1,wx.EXPAND)

    nbBox = wx.StaticBox(self,-1)
    nbBoxSizer = wx.StaticBoxSizer(nbBox,wx.VERTICAL)
    environmentDimSizer.Add(nbBoxSizer,1,wx.EXPAND)
    self.notebook = UseCaseEnvironmentNotebook(self,self.dbProxy)
    nbBoxSizer.Add(self.notebook,1,wx.EXPAND)

    self.preCondCtrl = self.notebook.FindWindowById(USECASE_TEXTPRECONDITION_ID)
    self.postCondCtrl = self.notebook.FindWindowById(USECASE_TEXTPOSTCONDITION_ID)
    self.stepsCtrl = self.notebook.FindWindowById(USECASE_PANELFLOW_ID)

    self.SetSizer(mainSizer)

    self.environmentList.Bind(wx.EVT_LIST_INSERT_ITEM,self.OnAddEnvironment)
    self.environmentList.Bind(wx.EVT_LIST_DELETE_ITEM,self.OnDeleteEnvironment)
    self.preCondCtrl.Disable()
    self.stepsCtrl.Disable() 
    self.postCondCtrl.Disable() 
    self.environmentList.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnEnvironmentSelected)
    self.environmentList.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnEnvironmentDeselected)
Exemplo n.º 12
0
    def __init__(self, parent):
        wx.Dialog.__init__(self,
                           parent,
                           DOMAINENTRY_ID,
                           'Add domain interface',
                           style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX
                           | wx.THICK_FRAME | wx.RESIZE_BORDER,
                           size=(300, 300))
        b = Borg()
        self.dbProxy = b.dbProxy
        self.theDomain = ''
        self.theConnectionDomain = ''
        self.thePhenomena = ''
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        domList = self.dbProxy.getDimensionNames('domain')
        mainSizer.Add(
            WidgetFactory.buildComboSizerList(self, 'Domain', (87, 30),
                                              DOMAINENTRY_COMBODOMAIN_ID,
                                              domList), 0, wx.EXPAND)
        mainSizer.Add(
            WidgetFactory.buildTextSizer(self, 'Phenomena', (87, 30),
                                         DOMAINENTRY_TEXTPHENOMENA_ID), 0,
            wx.EXPAND)
        cdList = [''] + domList
        mainSizer.Add(
            WidgetFactory.buildComboSizerList(
                self, 'Connection Domain', (87, 30),
                DOMAINENTRY_COMBOCONNECTIONDOMAIN_ID, cdList), 0, wx.EXPAND)
        mainSizer.Add(wx.StaticText(self, -1), 1, wx.EXPAND)
        mainSizer.Add(
            WidgetFactory.buildAddCancelButtonSizer(
                self, DOMAINENTRY_BUTTONCOMMIT_ID), 0, wx.ALIGN_CENTER)
        self.SetSizer(mainSizer)

        wx.EVT_BUTTON(self, DOMAINENTRY_BUTTONCOMMIT_ID, self.onCommit)
        self.commitLabel = 'Add'
Exemplo n.º 13
0
def addTestData():
    f = open(os.environ['CAIRIS_SRC'] + '/test/templategoals.json')
    d = json.load(f)
    f.close()
    iAccessRights = d['access_rights']
    iSurfaceTypes = d['surface_type']
    iTemplateAssets = d['template_assets']
    iTemplateGoals = d['template_goals']
    cairis.core.BorgFactory.initialise()
    b = Borg()
    iar1 = ValueTypeParameters(iAccessRights[0]["theName"],
                               iAccessRights[0]["theDescription"],
                               'access_right', '',
                               iAccessRights[0]["theValue"],
                               iAccessRights[0]["theRationale"])
    ist1 = ValueTypeParameters(iSurfaceTypes[0]["theName"],
                               iSurfaceTypes[0]["theDescription"],
                               'surface_type', '',
                               iSurfaceTypes[0]["theValue"],
                               iSurfaceTypes[0]["theRationale"])
    b.dbProxy.addValueType(iar1)
    b.dbProxy.addValueType(ist1)
    spValues = [(0, 'None'), (0, 'None'), (0, 'None'), (0, 'None'),
                (0, 'None'), (0, 'None'), (0, 'None'), (0, 'None')]
    iTap = TemplateAssetParameters(
        iTemplateAssets[0]["theName"], iTemplateAssets[0]["theShortCode"],
        iTemplateAssets[0]["theDescription"],
        iTemplateAssets[0]["theSignificance"], iTemplateAssets[0]["theType"],
        iTemplateAssets[0]["theSurfaceType"],
        iTemplateAssets[0]["theAccessRight"], spValues, [], [])
    b.dbProxy.addTemplateAsset(iTap)
    iTag1 = TemplateGoalParameters(iTemplateGoals[0]["theName"],
                                   iTemplateGoals[0]["theDefinition"],
                                   iTemplateGoals[0]["theRationale"],
                                   iTemplateGoals[0]["theConcerns"],
                                   iTemplateGoals[0]["theResponsibilities"])
    b.dbProxy.addTemplateGoal(iTag1)
Exemplo n.º 14
0
def get_fonts(session_id=None):
    """
  Validates that the fonts to output the SVG models are properly set up
  :param session_id: The session ID provided by the user
  :return: The font name, font size and AP font name
  :rtype : str,str,str
  :raise CairisHTTPError: Raises a CairisHTTPError when the database could not be properly set up
  """
    if session_id is not None:
        b = Borg()
        settings = b.get_settings(session_id)
        fontName = settings.get('fontName', None)
        fontSize = settings.get('fontSize', None)
        apFontName = settings.get('apFontSize', None)

        if fontName is None or fontSize is None or apFontName is None:
            raise CairisHTTPError(
                status_code=BAD_REQUEST,
                message=
                'The method is not callable without setting up the project settings.'
            )
        elif isinstance(fontName, string_types) and isinstance(
                fontSize, string_types) and isinstance(apFontName,
                                                       string_types):
            return fontName, fontSize, apFontName
        else:
            raise CairisHTTPError(
                status_code=BAD_REQUEST,
                message=
                'The database connection was not properly set up. Please try to reset the connection.'
            )
    else:
        raise CairisHTTPError(
            status_code=BAD_REQUEST,
            message=
            'The method is not callable without setting up the project settings.'
        )
Exemplo n.º 15
0
    def setUp(self):
        call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/templaterequirements.json')
        d = json.load(f)
        f.close()
        self.iAccessRights = d['access_rights']
        iar1 = ValueTypeParameters(self.iAccessRights[0]["theName"],
                                   self.iAccessRights[0]["theDescription"],
                                   'access_right', '',
                                   self.iAccessRights[0]["theValue"],
                                   self.iAccessRights[0]["theRationale"])
        self.iSurfaceTypes = d['surface_types']
        ist1 = ValueTypeParameters(self.iSurfaceTypes[0]["theName"],
                                   self.iSurfaceTypes[0]["theDescription"],
                                   'surface_type', '',
                                   self.iSurfaceTypes[0]["theValue"],
                                   self.iSurfaceTypes[0]["theRationale"])
        b = Borg()
        b.dbProxy.addValueType(iar1)
        b.dbProxy.addValueType(ist1)
        self.iTemplateAssets = d['template_assets']
        spValues = [(0, 'None'), (0, 'None'), (0, 'None'), (0, 'None'),
                    (0, 'None'), (0, 'None'), (0, 'None'), (0, 'None')]
        iTap = TemplateAssetParameters(
            self.iTemplateAssets[0]["theName"],
            self.iTemplateAssets[0]["theShortCode"],
            self.iTemplateAssets[0]["theDescription"],
            self.iTemplateAssets[0]["theSignificance"],
            self.iTemplateAssets[0]["theType"],
            self.iTemplateAssets[0]["theSurfaceType"],
            self.iTemplateAssets[0]["theAccessRight"], spValues, [], [])
        b.dbProxy.addTemplateAsset(iTap)
        oTaps = b.dbProxy.getTemplateAssets()
        self.oTap = oTaps[self.iTemplateAssets[0]["theName"]]

        self.iTemplateReqs = d["template_requirements"]
Exemplo n.º 16
0
    def __init__(self, parent, isTask, taskComboShown):
        wx.Panel.__init__(self, parent)
        topSizer = wx.BoxSizer(wx.VERTICAL)

        if (isTask and taskComboShown):
            b = Borg()
            self.dbProxy = b.dbProxy
            tasks = self.dbProxy.getDimensionNames('task')
            tBox = wx.StaticBox(self, -1, 'Task')
            tBoxSizer = wx.StaticBoxSizer(tBox, wx.VERTICAL)
            topSizer.Add(tBoxSizer, 0, wx.EXPAND)
            self.taskCtrl = wx.ComboBox(self,
                                        TASKCHARACTERISTIC_COMBOTASK_ID,
                                        '',
                                        choices=tasks,
                                        size=wx.DefaultSize,
                                        style=wx.CB_READONLY)
            tBoxSizer.Add(self.taskCtrl, 0, wx.EXPAND)

        qBox = wx.StaticBox(self, -1, 'Modal Qualifier')
        qBoxSizer = wx.StaticBoxSizer(qBox, wx.VERTICAL)
        topSizer.Add(qBoxSizer, 0, wx.EXPAND)
        self.qualifierCtrl = wx.TextCtrl(
            self, PERSONACHARACTERISTIC_TEXTQUALIFIER_ID, '')
        qBoxSizer.Add(self.qualifierCtrl, 0, wx.EXPAND)

        defBox = wx.StaticBox(self, -1, 'Definition')
        defBoxSizer = wx.StaticBoxSizer(defBox, wx.VERTICAL)
        topSizer.Add(defBoxSizer, 1, wx.EXPAND)
        self.definitionCtrl = wx.TextCtrl(
            self,
            PERSONACHARACTERISTIC_TEXTCHARACTERISTIC_ID,
            '',
            style=wx.TE_MULTILINE)
        defBoxSizer.Add(self.definitionCtrl, 1, wx.EXPAND)

        self.SetSizer(topSizer)
Exemplo n.º 17
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, REFERENCESYNOPSIS_ID)
        b = Borg()
        self.dbProxy = b.dbProxy
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(
            self.buildTextSizer('Reference', (87, 30),
                                REFERENCESYNOPSIS_TEXTREFNAME_ID), 0,
            wx.EXPAND)
        mainSizer.Add(
            self.buildTextSizer('Synopsis', (87, 30),
                                REFERENCESYNOPSIS_TEXTSYNOPSIS_ID), 0,
            wx.EXPAND)
        dimTypes = self.dbProxy.getDimensionNames('trace_dimension')
        mainSizer.Add(
            self.buildComboSizerList('Dimension', (87, 30),
                                     REFERENCESYNOPSIS_COMBODIMENSION_ID,
                                     dimTypes), 0, wx.EXPAND)

        actorSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(actorSizer, 0, wx.EXPAND)
        actorSizer.Add(
            self.buildComboSizerList('Actor Type', (87, 30),
                                     REFERENCESYNOPSIS_COMBOACTORTYPE_ID,
                                     ['asset', 'persona', 'component']), 1,
            wx.EXPAND)
        actorSizer.Add(
            self.buildComboSizerList('Actor', (87, 30),
                                     REFERENCESYNOPSIS_COMBOACTORNAME_ID,
                                     ['']), 1, wx.EXPAND)
        mainSizer.Add(wx.StaticText(self, -1, ''), 1, wx.EXPAND)
        mainSizer.Add(
            self.buildCommitButtonSizer(REFERENCESYNOPSIS_BUTTONCOMMIT_ID,
                                        True), 0, wx.ALIGN_CENTER)
        self.SetSizer(mainSizer)
        wx.EVT_COMBOBOX(self, REFERENCESYNOPSIS_COMBOACTORTYPE_ID,
                        self.onActorType)
Exemplo n.º 18
0
def set_dbproxy(dbUser, userName):
    b = Borg()
    dbName = dbUser + '_default'
    dbPasswd = ''

    db_proxy = MySQLDatabaseProxy(user=dbUser, passwd=dbPasswd, db=dbName)
    pSettings = db_proxy.getProjectSettings()

    id = b.init_settings()
    db_proxy.close()
    session['session_id'] = id
    b.settings[id]['dbProxy'] = db_proxy
    b.settings[id]['dbUser'] = dbUser
    b.settings[id]['userName'] = userName
    b.settings[id]['dbPasswd'] = dbPasswd
    b.settings[id]['dbHost'] = b.dbHost
    b.settings[id]['dbPort'] = b.dbPort
    b.settings[id]['dbName'] = dbName
    b.settings[id]['rPasswd'] = b.rPasswd
    b.settings[id]['fontSize'] = pSettings['Font Size']
    b.settings[id]['apFontSize'] = pSettings['AP Font Size']
    b.settings[id]['fontName'] = pSettings['Font Name']
    b.settings[id]['jsonPrettyPrint'] = False
    return b.settings[id]
Exemplo n.º 19
0
 def setUp(self):
     call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
     cairis.core.BorgFactory.initialise()
     f = open(os.environ['CAIRIS_SRC'] + '/test/templategoals.json')
     d = json.load(f)
     f.close()
     iAccessRights = d['access_rights']
     iar1 = ValueTypeParameters(iAccessRights[0]["theName"],
                                iAccessRights[0]["theDescription"],
                                'access_right', '',
                                iAccessRights[0]["theValue"],
                                iAccessRights[0]["theRationale"])
     iSurfaceTypes = d['surface_type']
     ist1 = ValueTypeParameters(iSurfaceTypes[0]["theName"],
                                iSurfaceTypes[0]["theDescription"],
                                'surface_type', '',
                                iSurfaceTypes[0]["theValue"],
                                iSurfaceTypes[0]["theRationale"])
     b = Borg()
     b.dbProxy.addValueType(iar1)
     b.dbProxy.addValueType(ist1)
     iTemplateAssets = d['template_assets']
     spValues = [0, 0, 0, 0, 0, 0, 0, 0]
     srValues = [
         'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None'
     ]
     iTap = TemplateAssetParameters(iTemplateAssets[0]["theName"],
                                    iTemplateAssets[0]["theShortCode"],
                                    iTemplateAssets[0]["theDescription"],
                                    iTemplateAssets[0]["theSignificance"],
                                    iTemplateAssets[0]["theType"],
                                    iTemplateAssets[0]["theSurfaceType"],
                                    iTemplateAssets[0]["theAccessRight"],
                                    spValues, srValues, [], [])
     b.dbProxy.addTemplateAsset(iTap)
     self.iTemplateGoals = d['template_goals']
Exemplo n.º 20
0
    def testTraces(self):
        b = Borg()

        fromDims = b.dbProxy.getTraceDimensions('requirement', 1)
        self.assertEqual(len(fromDims), 6)
        toDims = b.dbProxy.getTraceDimensions('requirement', 0)
        self.assertEqual(len(toDims), 2)

        reqId = b.dbProxy.getDimensionId('Dataset policy', 'requirement')
        vulId = b.dbProxy.getDimensionId('Certificate ubiquity',
                                         'vulnerability')
        b.dbProxy.addTrace('requirement_vulnerability', reqId, vulId)

        traces = b.dbProxy.removableTraces('Psychosis')
        self.assertEqual(len(traces), 1)
        self.assertEqual(traces[0][0], 'requirement')
        self.assertEqual(traces[0][1], 'Dataset policy')
        self.assertEqual(traces[0][2], 'vulnerability')
        self.assertEqual(traces[0][3], 'Certificate ubiquity')

        b.dbProxy.deleteTrace('requirement', 'Dataset policy', 'vulnerability',
                              'Certificate ubiquity')
        traces = b.dbProxy.removableTraces('Psychosis')
        self.assertEqual(len(traces), 0)
Exemplo n.º 21
0
 def onCommit(self, evt):
     commitLabel = self.commitVerb + ' asset'
     nameCtrl = self.FindWindowById(ASSET_TEXTNAME_ID)
     tagCtrl = self.FindWindowById(ASSET_TAGS_ID)
     shortCodeCtrl = self.FindWindowById(ASSET_TEXTSHORTCODE_ID)
     descriptionCtrl = self.FindWindowById(ASSET_TEXTDESCRIPTION_ID)
     sigCtrl = self.FindWindowById(ASSET_TEXTSIGNIFICANCE_ID)
     typeCtrl = self.FindWindowById(ASSET_COMBOTYPE_ID)
     criticalCtrl = self.FindWindowById(ASSET_CHECKCRITICAL_ID)
     criticalRationaleCtrl = self.FindWindowById(
         ASSET_TEXTCRITICALRATIONALE_ID)
     interfacesCtrl = self.FindWindowById(ASSET_PAGEINTERFACE_ID)
     environmentCtrl = self.FindWindowById(ASSET_PANELENVIRONMENT_ID)
     self.theAssetName = nameCtrl.GetValue()
     if (self.commitVerb == 'Add'):
         b = Borg()
         try:
             b.dbProxy.nameCheck(self.theAssetName, 'asset')
         except ARMException, errorText:
             dlg = wx.MessageDialog(self, str(errorText), 'Add asset',
                                    wx.OK | wx.ICON_ERROR)
             dlg.ShowModal()
             dlg.Destroy()
             return
Exemplo n.º 22
0
 def __init__(self, parent, parameters):
     wx.Dialog.__init__(self,
                        parent,
                        CLASSASSOCIATION_ID,
                        'Asset association',
                        style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX
                        | wx.THICK_FRAME | wx.RESIZE_BORDER,
                        size=(400, 600))
     b = Borg()
     self.dbProxy = b.dbProxy
     self.theClassAssociationId = -1
     self.theEnvironmentName = ''
     self.theHeadAsset = ''
     self.theHeadNav = 0
     self.theHeadType = ''
     self.theHeadMultiplicity = ''
     self.theHeadRole = ''
     self.theTailRole = ''
     self.theTailMultiplicity = ''
     self.theTailType = ''
     self.theTailNav = 0
     self.theTailAsset = ''
     self.buildControls(parameters)
     self.commitVerb = 'Add'
Exemplo n.º 23
0
 def onViewAssets(self, evt):
     cName = self.GetItemText(self.theSelectedIdx)
     dialog = None
     try:
         b = Borg()
         modelAssocs = b.dbProxy.componentAssetModel(cName)
         if (len(modelAssocs) > 0):
             associations = AssetModel(modelAssocs.values(), '')
             dialog = CanonicalModelViewer('', 'class')
             dialog.ShowModal(associations)
         else:
             errorTxt = 'No asset associations defined'
             dlg = wx.MessageDialog(self, errorTxt, 'View Component Assets',
                                    wx.OK | wx.ICON_EXCLAMATION)
             dlg.ShowModal()
             dlg.Destroy()
     except ARMException, errorText:
         if (dialog != None):
             dialog.destroy()
         dlg = wx.MessageDialog(self, str(errorText),
                                'View Component Assets',
                                wx.OK | wx.ICON_ERROR)
         dlg.ShowModal()
         dlg.Destroy()
Exemplo n.º 24
0
 def onSelectGenerateFromTemplate(self, evt):
     countermeasure = self.theParentDialog.objts[
         self.theParentDialog.selectedLabel]
     cmId = countermeasure.id()
     try:
         b = Borg()
         dbProxy = b.dbProxy
         templateAssets = dbProxy.getDimensionNames('template_asset')
         cDlg = DimensionNameDialog(self, 'template_asset', templateAssets,
                                    'Select')
         if (cDlg.ShowModal() == DIMNAME_BUTTONACTION_ID):
             templateAssetName = cDlg.dimensionName()
             assetId = dbProxy.addAsset(
                 cairis.core.AssetParametersFactory.buildFromTemplate(
                     templateAssetName, countermeasure.environments()))
             dbProxy.addTrace('countermeasure_asset', cmId, assetId)
             cDlg.Destroy()
     except ARMException, errorText:
         dlg = wx.MessageDialog(self, str(errorText),
                                'Generate countermeasure asset',
                                wx.OK | wx.ICON_ERROR)
         dlg.ShowModal()
         dlg.Destroy()
         return
Exemplo n.º 25
0
def importModelFile(importFile,isOverwrite = 1,session_id = None):
  try:
    b = Borg()
    db_proxy = b.dbProxy
    if (session_id != None):
      db_proxy = b.get_dbproxy(session_id)

    modelTxt = ''
    if isOverwrite == 1:
      db_proxy.clearDatabase(session_id)
      modelTxt += importTVTypeFile(importFile,isOverwrite,session_id = session_id) + '  '
    modelTxt += importDomainValuesFile(importFile,session_id) + ' '
    modelTxt += importProjectFile(importFile,session_id) + ' '
    modelTxt += importRiskAnalysisFile(importFile,session_id) + ' '
    modelTxt += importUsabilityFile(importFile,session_id) + ' '
    modelTxt += importRequirementsFile(importFile,session_id) + ' '
    modelTxt += importAssociationsFile(importFile,session_id) + ' '
    modelTxt += importSynopsesFile(importFile,session_id) + ' '
    modelTxt += importMisusabilityFile(importFile,session_id) + ' '
    modelTxt += importDataflowsFile(importFile,session_id) + ' '
    modelTxt += importLocationsFile(importFile,session_id)
    return modelTxt
  except xml.sax.SAXException as e:
    raise ARMException("Error parsing" + importFile + ": " + e.getMessage())
Exemplo n.º 26
0
 def setUp(self):
   call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
   cairis.core.BorgFactory.initialise()
   f = open(os.environ['CAIRIS_SRC'] + '/test/vulnerabilities.json')
   d = json.load(f)
   f.close()
   b = Borg()
   iVtypes = d['valuetypes']
   ivt1 = ValueTypeParameters(iVtypes[0]["theName"], iVtypes[0]["theDescription"], iVtypes[0]["theValueType"])
   ivt2 = ValueTypeParameters(iVtypes[1]["theName"], iVtypes[1]["theDescription"], iVtypes[1]["theValueType"])
   b.dbProxy.addValueType(ivt1)
   b.dbProxy.addValueType(ivt2)
   ienvs = d['environments']
   iep1 = EnvironmentParameters(ienvs[0]["theName"],ienvs[0]["theShortCode"],ienvs[0]["theDescription"])
   iep2 = EnvironmentParameters(ienvs[1]["theName"],ienvs[1]["theShortCode"],ienvs[1]["theDescription"])
   iep3 = EnvironmentParameters(ienvs[2]["theName"],ienvs[2]["theShortCode"],ienvs[2]["theDescription"])
   b.dbProxy.addEnvironment(iep1)
   b.dbProxy.addEnvironment(iep2)
   b.dbProxy.addEnvironment(iep3)
   iassets = d['assets']
   iaeps = [AssetEnvironmentProperties(iassets[0]["theEnvironmentProperties"][0][0],iassets[0]["theEnvironmentProperties"][0][1],iassets[0]["theEnvironmentProperties"][0][2])]
   iap = AssetParameters(iassets[0]["theName"],iassets[0]["theShortCode"],iassets[0]["theDescription"],iassets[0]["theSignificance"],iassets[0]["theType"],"0","N/A",[],[],iaeps)
   b.dbProxy.addAsset(iap)
   self.iVuln = d['vulnerabilities']
Exemplo n.º 27
0
def importMisusability(crParameterSet,tcParameterSet,session_id):
  b = Borg()
  db_proxy = b.get_dbproxy(session_id)
  crCount = 0
  for crParameters in crParameterSet:
    objtId = db_proxy.existingObject(crParameters.name(),'concept_reference')
    if objtId == -1:
      db_proxy.addConceptReference(crParameters)
    else:
      crParameters.setId(objtId)
      db_proxy.updateConceptReference(crParameters)
    crCount += 1

  tcCount = 0
  for tcParameters in tcParameterSet:
    objtId = db_proxy.existingObject(tcParameters.task(),'task_characteristic')
    if objtId == -1:
      db_proxy.addTaskCharacteristic(tcParameters)
    else:
      tcParameters.setId(objtId)
      db_proxy.updateTaskCharacterisric(tcParameters)
    tcCount += 1
  msgStr = 'Imported ' + str(crCount) + ' concept references, and ' + str(tcCount) + ' task characteristics.'
  return msgStr
Exemplo n.º 28
0
 def __init__(self, parent, reqList, setTargets, envName):
     wx.Dialog.__init__(self,
                        parent,
                        PROPERTY_ID,
                        'Add Target',
                        style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX
                        | wx.THICK_FRAME | wx.RESIZE_BORDER,
                        size=(400, 250))
     b = Borg()
     self.dbProxy = b.dbProxy
     self.theTarget = ''
     self.theEffectiveness = ''
     self.theRationale = ''
     self.commitLabel = 'Add'
     mainSizer = wx.BoxSizer(wx.VERTICAL)
     self.theTargetDictionary = self.dbProxy.targetNames(reqList, envName)
     defaultTargets = set(self.theTargetDictionary.keys())
     targetList = list(defaultTargets.difference(setTargets))
     mainSizer.Add(
         WidgetFactory.buildComboSizerList(self, 'Target', (87, 30),
                                           TARGET_COMBOTARGET_ID,
                                           targetList), 0, wx.EXPAND)
     mainSizer.Add(
         WidgetFactory.buildComboSizerList(
             self, 'Effectiveness', (87, 30), TARGET_COMBOEFFECTIVENESS_ID,
             ['None', 'Low', 'Medium', 'High']), 0, wx.EXPAND)
     mainSizer.Add(
         WidgetFactory.buildMLTextSizer(self, 'Rationale', (87, 60),
                                        TARGET_TEXTRATIONALE_ID), 1,
         wx.EXPAND)
     mainSizer.Add(
         WidgetFactory.buildAddCancelButtonSizer(self,
                                                 TARGET_BUTTONCOMMIT_ID), 0,
         wx.ALIGN_CENTER)
     self.SetSizer(mainSizer)
     wx.EVT_BUTTON(self, TARGET_BUTTONCOMMIT_ID, self.onCommit)
Exemplo n.º 29
0
  def __init__(self,parent,winId = COMPONENTVIEW_LISTCONNECTORS_ID):
    wx.ListCtrl.__init__(self,parent,winId,size=wx.DefaultSize,style=wx.LC_REPORT)
    b = Borg()
    self.dbProxy = b.dbProxy
    self.theViewName = ''
    self.InsertColumn(0,'Connector')
    self.SetColumnWidth(0,100)
    self.InsertColumn(1,'From')
    self.SetColumnWidth(1,100)
    self.InsertColumn(2,'Role')
    self.SetColumnWidth(2,100)
    self.InsertColumn(3,'Interface')
    self.SetColumnWidth(3,100)
    self.InsertColumn(4,'To')
    self.SetColumnWidth(4,100)
    self.InsertColumn(5,'Interface')
    self.SetColumnWidth(5,100)
    self.InsertColumn(6,'Role')
    self.SetColumnWidth(6,100)
    self.InsertColumn(7,'Asset')
    self.SetColumnWidth(7,100)
    self.InsertColumn(8,'Protocol')
    self.SetColumnWidth(8,100)
    self.InsertColumn(9,'Access Right')
    self.SetColumnWidth(9,100)
    self.theSelectedIdx = -1
    self.theDimMenu = wx.Menu()
    self.theDimMenu.Append(AA_MENUADD_ID,'Add')
    self.theDimMenu.Append(AA_MENUDELETE_ID,'Delete')
    self.Bind(wx.EVT_RIGHT_DOWN,self.OnRightDown)
    wx.EVT_MENU(self.theDimMenu,AA_MENUADD_ID,self.onAddConnector)
    wx.EVT_MENU(self.theDimMenu,AA_MENUDELETE_ID,self.onDeleteConnector)

    self.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnItemSelected)
    self.Bind(wx.EVT_LIST_ITEM_DESELECTED,self.OnItemDeselected)
    self.Bind(wx.EVT_LIST_ITEM_ACTIVATED,self.onConnectorActivated)
Exemplo n.º 30
0
    def onSelectGenerate(self, evt):
        objt = self.theParentDialog.objts[self.theParentDialog.selectedLabel]
        #    objtId = objt.id()
        try:
            b = Borg()
            dbProxy = b.dbProxy
            domains = dbProxy.getDimensionNames('domain', False)
            cDlg = DimensionNameDialog(self, 'domain', domains, 'Select')
            if (cDlg.ShowModal() == DIMNAME_BUTTONACTION_ID):
                domainName = cDlg.dimensionName()
                GoalRequirementFactory.build(
                    objt, domainName, self.theParentDialog.theMainWindow)


# Change domain in panel
# Add requirement
# add goalrequirement_goalassociation
        except ARMException, errorText:
            dlg = wx.MessageDialog(self, str(errorText),
                                   'Generate goal requirement',
                                   wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return