コード例 #1
0
 def convert_props(self, real_props=None, fake_props=None):
     new_props = []
     if real_props is not None:
         if len(real_props) > 0:
             for real_prop in real_props:
                 assert isinstance(real_prop, PersonaEnvironmentProperties)
                 del real_prop.theCodes
                 new_props.append(real_prop)
     elif fake_props is not None:
         if len(fake_props) > 0:
             for fake_prop in fake_props:
                 check_required_keys(
                     fake_prop, PersonaEnvironmentPropertiesModel.required)
                 new_prop = PersonaEnvironmentProperties(
                     environmentName=fake_prop['theEnvironmentName'],
                     direct=fake_prop['theDirectFlag'],
                     description=fake_prop['theNarrative'],
                     roles=fake_prop['theRoles'],
                     pCodes=[])
                 new_props.append(new_prop)
     else:
         self.close()
         raise MissingParameterHTTPError(
             param_names=['real_props', 'fake_props'])
     return new_props
コード例 #2
0
ファイル: test_PersonaAPI.py プロジェクト: we45/cairis
    def prepare_new_persona(self):
        new_persona_props = [
            PersonaEnvironmentProperties(
                environmentName=self.existing_environment_name,
                direct=self.existing_direct_flag,
                description=self.existing_environment_narrative,
                roles=self.existing_role_names)
        ]

        new_persona = Persona(personaId=-1,
                              personaName='Terry',
                              pActivities='Some acivities',
                              pAttitudes='Some attitudes',
                              pAptitudes='Some aptitudes',
                              pMotivations='Some motivations',
                              pSkills='Some skills',
                              pIntrinsic='Nothing stipulated',
                              pContextual='Nothing stipulated',
                              image='',
                              isAssumption=False,
                              pType='Primary',
                              tags=['test', 'test123'],
                              environmentProperties=[],
                              pCodes=[])
        new_persona.theEnvironmentProperties = new_persona_props

        new_persona.theEnvironmentDictionary = {}

        delattr(new_persona, 'theEnvironmentDictionary')

        return new_persona
コード例 #3
0
 def endElement(self,name):
   if name == 'persona':
     p = PersonaParameters(self.theName,unescape(self.theActivities),unescape(self.theAttitudes),unescape(self.theAptitudes),unescape(self.theMotivations),unescape(self.theSkills),unescape(self.theIntrinsic),unescape(self.theContextual),self.theImage,self.isAssumptionPersona,self.theType,self.theTags,self.theEnvironmentProperties,{})
     self.thePersonas.append(p)
     self.resetPersonaAttributes()
   elif name == 'persona_environment':
     p = PersonaEnvironmentProperties(self.theEnvironmentName,self.isDirect,unescape(self.theNarrative),self.theRoles,{'narrative':{}})
     self.theEnvironmentProperties.append(p)
     self.resetPersonaEnvironmentAttributes()
   elif name == 'external_document':
     p = ExternalDocumentParameters(self.theName,self.theVersion,self.theDate,self.theAuthors,unescape(self.theDescription))
     self.theExternalDocuments.append(p)
     self.resetExternalDocumentAttributes()
   elif name == 'document_reference':
     p = DocumentReferenceParameters(self.theName,self.theDocument,self.theContributor,unescape(self.theExcerpt))
     self.theDocumentReferences.append(p)
     self.resetDocumentReferenceAttributes()
   elif name == 'persona_characteristic':
     p = PersonaCharacteristicParameters(self.thePersona,self.theModalQualifier,self.theBvName,unescape(self.theDefinition),self.theGrounds,self.theWarrants,[],self.theRebuttals)
     self.thePersonaCharacteristics.append(p)
     self.resetPersonaCharacteristicAttributes()
   elif name == 'task':
     p = TaskParameters(unescape(self.theName),unescape(self.theCode),unescape(self.theObjective),self.isAssumptionTask,self.theAuthor,self.theTags,self.theEnvironmentProperties)
     self.theTasks.append(p)
     self.resetTaskAttributes()
   elif name == 'task_environment':
     p = TaskEnvironmentProperties(unescape(self.theEnvironmentName),unescape(self.theDependencies),self.theTaskPersonas,self.theConcerns,self.theConcernAssociations,unescape(self.theNarrative),unescape(self.theConsequences),unescape(self.theBenefits),[],{'narrative':{},'consequences':{},'benefits':{}})
     self.theEnvironmentProperties.append(p)
     self.resetTaskEnvironmentAttributes()
   elif name == 'activities':
     self.inActivities = 0
   elif name == 'attitudes':
     self.inAttitudes = 0
   elif name == 'aptitudes':
     self.inAptitudes = 0
   elif name == 'motivations':
     self.inMotivations = 0
   elif name == 'skills':
     self.inSkills = 0
   elif name == 'intrinsic':
     self.inIntrinsic = 0
   elif name == 'contextual':
     self.inContextual = 0
   elif name == 'narrative':
     self.inNarrative = 0
   elif name == 'excerpt':
     self.inExcerpt = 0
   elif name == 'description':
     self.inDescription = 0
   elif name == 'definition':
     self.inDefinition = 0
   elif name == 'dependencies':
     self.inDependencies = 0
   elif name == 'objective':
     self.inObjective = 0
   elif name == 'benefits':
     self.inBenefits = 0
   elif name == 'consequences':
     self.inConsequences = 0
コード例 #4
0
ファイル: test_Task.py プロジェクト: gkmacc/cairis
    def setUp(self):
        call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/tasks.json')
        d = json.load(f)
        f.close()
        self.iEnvironments = d['environments']
        iep1 = EnvironmentParameters(self.iEnvironments[0]["theName"],
                                     self.iEnvironments[0]["theShortCode"],
                                     self.iEnvironments[0]["theDescription"])
        b = Borg()
        b.dbProxy.addEnvironment(iep1)
        self.theEnvironments = b.dbProxy.getEnvironments()

        self.iRoles = d['roles']
        irp = RoleParameters(self.iRoles[0]["theName"],
                             self.iRoles[0]["theType"],
                             self.iRoles[0]["theShortCode"],
                             self.iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(irp)
        self.theRoles = b.dbProxy.getRoles()
        self.iPersonas = d['personas']
        ipp = PersonaParameters(
            self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
            self.iPersonas[0]["theAttitudes"],
            self.iPersonas[0]["theAptitudes"],
            self.iPersonas[0]["theMotivations"],
            self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
            self.iPersonas[0]["theContextual"], "", "0",
            self.iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                                  [0]["theDirectFlag"] == "True"),
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theNarrative"], self.iPersonas[0]
                    ["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b.dbProxy.addPersona(ipp)
        self.thePersonas = b.dbProxy.getPersonas()

        self.iAssets = d['assets']
        iaeps = [
            AssetEnvironmentProperties(
                self.iAssets[0]["theEnvironmentProperties"][0][0],
                self.iAssets[0]["theEnvironmentProperties"][0][1],
                self.iAssets[0]["theEnvironmentProperties"][0][2])
        ]
        iap = AssetParameters(self.iAssets[0]["theName"],
                              self.iAssets[0]["theShortCode"],
                              self.iAssets[0]["theDescription"],
                              self.iAssets[0]["theSignificance"],
                              self.iAssets[0]["theType"], "0", "N/A", [], [],
                              iaeps)
        b = Borg()
        b.dbProxy.addAsset(iap)
        self.theAssets = b.dbProxy.getAssets()

        self.iTasks = d['tasks']
コード例 #5
0
 def environmentProperties(self):
     if (self.theSelectedIdx != -1):
         environmentName = self.environmentList.GetItemText(
             self.theSelectedIdx)
         envCodebook = {'narrative': self.descriptionCtrl.codes()}
         self.theEnvironmentDictionary[
             environmentName] = PersonaEnvironmentProperties(
                 environmentName, str(self.directCtrl.GetValue()),
                 self.descriptionCtrl.GetValue(),
                 self.roleList.dimensions(), envCodebook)
     return self.theEnvironmentDictionary.values()
コード例 #6
0
 def OnAddEnvironment(self,evt):
   self.theSelectedIdx = evt.GetIndex()
   environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
   self.theEnvironmentDictionary[environmentName] = PersonaEnvironmentProperties(environmentName)
   self.environmentList.Select(self.theSelectedIdx)
   self.directCtrl.SetValue(False)
   self.descriptionCtrl.Set(self.thePersonaName,'Environment Narrative','')
   self.descriptionCtrl.setCodes({})
   self.roleList.setEnvironment(environmentName)
   self.roleList.DeleteAllItems() 
   self.directCtrl.Enable()
   self.descriptionCtrl.Enable()
   self.roleList.Enable() 
コード例 #7
0
  def OnEnvironmentDeselected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    envCodebook = {'narrative':self.descriptionCtrl.codes()}
    self.theEnvironmentDictionary[environmentName] = PersonaEnvironmentProperties(environmentName,str(self.directCtrl.GetValue()),self.descriptionCtrl.GetValue(),self.roleList.dimensions())

    self.directCtrl.SetValue(False)
    self.descriptionCtrl.Set(self.thePersonaName,'Environment Narrative','')
    self.descriptionCtrl.setCodes({})
    self.roleList.setEnvironment('')
    self.roleList.DeleteAllItems() 
    self.theSelectedIdx = -1
    self.directCtrl.Disable()
    self.descriptionCtrl.Disable()
    self.roleList.Disable() 
コード例 #8
0
 def setUp(self):
     call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
     cairis.core.BorgFactory.initialise()
     f = open(os.environ['CAIRIS_SRC'] + '/test/processes.json')
     d = json.load(f)
     f.close()
     iCodes = d['codes']
     i = CodeParameters(iCodes[0]["theName"], iCodes[0]["theType"],
                        iCodes[0]["theDescription"],
                        iCodes[0]["theInclusionCriteria"],
                        iCodes[0]["theExample"])
     b = Borg()
     b.dbProxy.addCode(i)
     i = CodeParameters(iCodes[1]["theName"], iCodes[1]["theType"],
                        iCodes[1]["theDescription"],
                        iCodes[1]["theInclusionCriteria"],
                        iCodes[1]["theExample"])
     b.dbProxy.addCode(i)
     iEnvironments = d['environments']
     iep1 = EnvironmentParameters(iEnvironments[0]["theName"],
                                  iEnvironments[0]["theShortCode"],
                                  iEnvironments[0]["theDescription"])
     b.dbProxy.addEnvironment(iep1)
     iRoles = d['roles']
     irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"],
                          iRoles[0]["theShortCode"],
                          iRoles[0]["theDescription"], [])
     b.dbProxy.addRole(irp)
     iPersonas = d['personas']
     ipp = PersonaParameters(
         iPersonas[0]["theName"], iPersonas[0]["theActivities"],
         iPersonas[0]["theAttitudes"], iPersonas[0]["theAptitudes"],
         iPersonas[0]["theMotivations"], iPersonas[0]["theSkills"],
         iPersonas[0]["theIntrinsic"], iPersonas[0]["theContextual"], "",
         "0", iPersonas[0]["thePersonaType"], [], [
             PersonaEnvironmentProperties(
                 iPersonas[0]["theEnvironmentProperties"][0]["theName"],
                 (iPersonas[0]["theEnvironmentProperties"][0]
                  ["theDirectFlag"] == "True"), iPersonas[0]
                 ["theEnvironmentProperties"][0]["theNarrative"],
                 iPersonas[0]["theEnvironmentProperties"][0]["theRole"])
         ], [])
     b.dbProxy.addPersona(ipp)
     self.iCN = d['code_networks']
コード例 #9
0
ファイル: test_Response.py プロジェクト: gkmacc/cairis
    def setUp(self):
        call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/responses.json')
        d = json.load(f)
        f.close()
        self.ienvs = d['environments']
        self.iep1 = EnvironmentParameters(self.ienvs[0]["theName"],
                                          self.ienvs[0]["theShortCode"],
                                          self.ienvs[0]["theDescription"])
        b = Borg()
        b.dbProxy.addEnvironment(self.iep1)
        self.oenvs = b.dbProxy.getEnvironments()
        self.iRoles = d['roles']
        self.irp = RoleParameters(self.iRoles[0]["theName"],
                                  self.iRoles[0]["theType"],
                                  self.iRoles[0]["theShortCode"],
                                  self.iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(self.irp)
        self.oRoles = b.dbProxy.getRoles()
        self.iPersonas = d['personas']
        self.ipp = PersonaParameters(
            self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
            self.iPersonas[0]["theAttitudes"],
            self.iPersonas[0]["theAptitudes"],
            self.iPersonas[0]["theMotivations"],
            self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
            self.iPersonas[0]["theContextual"], "", "0",
            self.iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                                  [0]["theDirectFlag"] == "True"),
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theNarrative"], self.iPersonas[0]
                    ["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b.dbProxy.addPersona(self.ipp)
        self.opp = b.dbProxy.getPersonas()
        self.iExternalDocuments = d['external_documents']
        self.iec1 = ExternalDocumentParameters(
            self.iExternalDocuments[0]["theName"],
            self.iExternalDocuments[0]["theVersion"],
            self.iExternalDocuments[0]["thePublicationDate"],
            self.iExternalDocuments[0]["theAuthors"],
            self.iExternalDocuments[0]["theDescription"])
        self.iec2 = ExternalDocumentParameters(
            self.iExternalDocuments[1]["theName"],
            self.iExternalDocuments[1]["theVersion"],
            self.iExternalDocuments[1]["thePublicationDate"],
            self.iExternalDocuments[1]["theAuthors"],
            self.iExternalDocuments[1]["theDescription"])
        b.dbProxy.addExternalDocument(self.iec1)
        b.dbProxy.addExternalDocument(self.iec2)
        self.oecs = b.dbProxy.getExternalDocuments()
        self.iDocumentReferences = d['document_references']
        self.idr1 = DocumentReferenceParameters(
            self.iDocumentReferences[0]["theName"],
            self.iDocumentReferences[0]["theDocName"],
            self.iDocumentReferences[0]["theContributor"],
            self.iDocumentReferences[0]["theExcerpt"])
        self.idr2 = DocumentReferenceParameters(
            self.iDocumentReferences[1]["theName"],
            self.iDocumentReferences[1]["theDocName"],
            self.iDocumentReferences[1]["theContributor"],
            self.iDocumentReferences[1]["theExcerpt"])
        b.dbProxy.addDocumentReference(self.idr1)
        b.dbProxy.addDocumentReference(self.idr2)
        self.odrs = b.dbProxy.getDocumentReferences()
        self.iPersonaCharacteristics = d['persona_characteristics']
        self.ipc1 = PersonaCharacteristicParameters(
            self.iPersonaCharacteristics[0]["thePersonaName"],
            self.iPersonaCharacteristics[0]["theModQual"],
            self.iPersonaCharacteristics[0]["theVariable"],
            self.iPersonaCharacteristics[0]["theCharacteristic"],
            [(self.iPersonaCharacteristics[0]["ground"], '', 'document')],
            [(self.iPersonaCharacteristics[0]["warrant"], '', 'document')], [],
            [])
        b.dbProxy.addPersonaCharacteristic(self.ipc1)
        self.opcs = b.dbProxy.getPersonaCharacteristics()
        self.iAttackers = d['attackers']
        self.iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"])
        ]
        self.iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                       self.iAttackers[0]["theDescription"],
                                       self.iAttackers[0]["theImage"], [],
                                       self.iatkeps)
        b.dbProxy.addAttacker(self.iatk)
        self.oAttackers = b.dbProxy.getAttackers()
        self.iVtypes = d['valuetypes']
        self.ivt1 = ValueTypeParameters(self.iVtypes[0]["theName"],
                                        self.iVtypes[0]["theDescription"],
                                        self.iVtypes[0]["theType"])
        self.ivt2 = ValueTypeParameters(self.iVtypes[1]["theName"],
                                        self.iVtypes[1]["theDescription"],
                                        self.iVtypes[1]["theType"])
        b.dbProxy.addValueType(self.ivt1)
        b.dbProxy.addValueType(self.ivt2)
        self.ovtt = b.dbProxy.getValueTypes('threat_type')
        self.ovtv = b.dbProxy.getValueTypes('vulnerability_type')
        self.iassets = d['assets']
        self.iaeps1 = [
            AssetEnvironmentProperties(
                self.iassets[0]["theEnvironmentProperties"][0][0],
                self.iassets[0]["theEnvironmentProperties"][0][1],
                self.iassets[0]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps2 = [
            AssetEnvironmentProperties(
                self.iassets[1]["theEnvironmentProperties"][0][0],
                self.iassets[1]["theEnvironmentProperties"][0][1],
                self.iassets[1]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps3 = [
            AssetEnvironmentProperties(
                self.iassets[2]["theEnvironmentProperties"][0][0],
                self.iassets[2]["theEnvironmentProperties"][0][1],
                self.iassets[2]["theEnvironmentProperties"][0][2])
        ]
        self.iap1 = AssetParameters(self.iassets[0]["theName"],
                                    self.iassets[0]["theShortCode"],
                                    self.iassets[0]["theDescription"],
                                    self.iassets[0]["theSignificance"],
                                    self.iassets[0]["theType"], "0", "N/A", [],
                                    [], self.iaeps1)
        self.iap2 = AssetParameters(self.iassets[1]["theName"],
                                    self.iassets[1]["theShortCode"],
                                    self.iassets[1]["theDescription"],
                                    self.iassets[1]["theSignificance"],
                                    self.iassets[1]["theType"], "0", "N/A", [],
                                    [], self.iaeps2)
        self.iap3 = AssetParameters(self.iassets[2]["theName"],
                                    self.iassets[2]["theShortCode"],
                                    self.iassets[2]["theDescription"],
                                    self.iassets[2]["theSignificance"],
                                    self.iassets[2]["theType"], "0", "N/A", [],
                                    [], self.iaeps3)
        b.dbProxy.addAsset(self.iap1)
        b.dbProxy.addAsset(self.iap2)
        b.dbProxy.addAsset(self.iap3)
        self.oap = b.dbProxy.getAssets()
        self.iThreats = d['threats']
        self.iteps = [
            ThreatEnvironmentProperties(
                self.iThreats[0]["theEnvironmentProperties"][0]["theName"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theLikelihood"],
                self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theAttackers"], self.iThreats[0]["theEnvironmentProperties"]
                [0]["theProperties"][0][1], self.iThreats[0]
                ["theEnvironmentProperties"][0]["theProperties"][0][1])
        ]
        self.itps = ThreatParameters(self.iThreats[0]["theName"],
                                     self.iThreats[0]["theType"],
                                     self.iThreats[0]["theMethod"], [],
                                     self.iteps)
        b.dbProxy.addThreat(self.itps)
        self.otps = b.dbProxy.getThreats()
        self.iVuln = d['vulnerabilities']
        self.iveps = [
            VulnerabilityEnvironmentProperties(
                self.iVuln[0]["theEnvironmentProperties"][0]["theName"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theAssets"])
        ]
        self.ivp = VulnerabilityParameters(self.iVuln[0]["theName"],
                                           self.iVuln[0]["theDescription"],
                                           self.iVuln[0]["theType"], [],
                                           self.iveps)
        b.dbProxy.addVulnerability(self.ivp)
        self.ovp = b.dbProxy.getVulnerabilities()
        self.imc = d['misuseCase']
        self.iRisks = d['risks']

        imcep = [
            MisuseCaseEnvironmentProperties(
                self.imc[0]["theEnvironmentProperties"][0]["theName"],
                self.imc[0]["theEnvironmentProperties"][0]["theDescription"])
        ]
        imcp = MisuseCase(int(0), self.imc[0]["theName"], imcep,
                          self.imc[0]["theRisk"])
        irp = RiskParameters(self.iRisks[0]["theName"],
                             self.iRisks[0]["threatName"],
                             self.iRisks[0]["vulName"], imcp, [])
        b.dbProxy.addRisk(irp)
        oRisks = b.dbProxy.getRisks()
        self.r = oRisks[self.iRisks[0]["theName"]]
        self.iResponses = d['responses']
コード例 #10
0
    def testPersona(self):
        ipp = PersonaParameters(
            self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
            self.iPersonas[0]["theAttitudes"],
            self.iPersonas[0]["theAptitudes"],
            self.iPersonas[0]["theMotivations"],
            self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
            self.iPersonas[0]["theContextual"], "", "0",
            self.iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                                  [0]["theDirectFlag"] == "True"),
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theNarrative"], self.iPersonas[0]
                    ["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b = Borg()
        b.dbProxy.addPersona(ipp)

        thePersonas = b.dbProxy.getPersonas()
        op = thePersonas[self.iPersonas[0]["theName"]]
        self.assertEqual(ipp.name(), op.name())
        self.assertEqual(ipp.activities(), op.activities())
        self.assertEqual(ipp.attitudes(), op.attitudes())
        self.assertEqual(ipp.aptitudes(), op.aptitudes())
        self.assertEqual(ipp.motivations(), op.motivations())
        self.assertEqual(ipp.skills(), op.skills())
        self.assertEqual(ipp.intrinsic(), op.intrinsic())
        self.assertEqual(ipp.contextual(), op.contextual())

        self.assertEqual(
            self.iPersonas[0]["theEnvironmentProperties"][0]["theDirectFlag"],
            op.environmentProperties()[0].directFlag())
        self.assertEqual(
            self.iPersonas[0]["theEnvironmentProperties"][0]["theNarrative"],
            op.environmentProperties()[0].narrative())
        self.assertEqual(
            self.iPersonas[0]["theEnvironmentProperties"][0]["theRole"],
            op.environmentProperties()[0].roles())

        iec1 = ExternalDocumentParameters(
            self.iExternalDocuments[0]["theName"],
            self.iExternalDocuments[0]["theVersion"],
            self.iExternalDocuments[0]["thePublicationDate"],
            self.iExternalDocuments[0]["theAuthors"],
            self.iExternalDocuments[0]["theDescription"])
        iec2 = ExternalDocumentParameters(
            self.iExternalDocuments[1]["theName"],
            self.iExternalDocuments[1]["theVersion"],
            self.iExternalDocuments[1]["thePublicationDate"],
            self.iExternalDocuments[1]["theAuthors"],
            self.iExternalDocuments[1]["theDescription"])
        b.dbProxy.addExternalDocument(iec1)
        b.dbProxy.addExternalDocument(iec2)
        oecs = b.dbProxy.getExternalDocuments()
        oec1 = oecs[self.iExternalDocuments[0]["theName"]]
        oec2 = oecs[self.iExternalDocuments[1]["theName"]]

        self.assertEqual(self.iExternalDocuments[0]["theName"], oec1.name())
        self.assertEqual(self.iExternalDocuments[0]["theVersion"],
                         oec1.version())
        self.assertEqual(self.iExternalDocuments[0]["thePublicationDate"],
                         oec1.date())
        self.assertEqual(self.iExternalDocuments[0]["theAuthors"],
                         oec1.authors())
        self.assertEqual(self.iExternalDocuments[0]["theDescription"],
                         oec1.description())
        self.assertEqual(self.iExternalDocuments[1]["theName"], oec2.name())
        self.assertEqual(self.iExternalDocuments[1]["theVersion"],
                         oec2.version())
        self.assertEqual(self.iExternalDocuments[1]["thePublicationDate"],
                         oec2.date())
        self.assertEqual(self.iExternalDocuments[1]["theAuthors"],
                         oec2.authors())
        self.assertEqual(self.iExternalDocuments[1]["theDescription"],
                         oec2.description())

        idr1 = DocumentReferenceParameters(
            self.iDocumentReferences[0]["theName"],
            self.iDocumentReferences[0]["theDocName"],
            self.iDocumentReferences[0]["theContributor"],
            self.iDocumentReferences[0]["theExcerpt"])
        idr2 = DocumentReferenceParameters(
            self.iDocumentReferences[1]["theName"],
            self.iDocumentReferences[1]["theDocName"],
            self.iDocumentReferences[1]["theContributor"],
            self.iDocumentReferences[1]["theExcerpt"])
        idr3 = DocumentReferenceParameters(
            self.iDocumentReferences[2]["theName"],
            self.iDocumentReferences[2]["theDocName"],
            self.iDocumentReferences[2]["theContributor"],
            self.iDocumentReferences[2]["theExcerpt"])

        b.dbProxy.addDocumentReference(idr1)
        b.dbProxy.addDocumentReference(idr2)
        b.dbProxy.addDocumentReference(idr3)

        odrs = b.dbProxy.getDocumentReferences()
        odr1 = odrs[self.iDocumentReferences[0]["theName"]]
        odr2 = odrs[self.iDocumentReferences[1]["theName"]]
        odr3 = odrs[self.iDocumentReferences[2]["theName"]]

        self.assertEqual(self.iDocumentReferences[0]["theName"], odr1.name())
        self.assertEqual(self.iDocumentReferences[0]["theDocName"],
                         odr1.document())
        self.assertEqual(self.iDocumentReferences[0]["theContributor"],
                         odr1.contributor())
        self.assertEqual(self.iDocumentReferences[0]["theExcerpt"],
                         odr1.excerpt())
        self.assertEqual(self.iDocumentReferences[1]["theName"], odr2.name())
        self.assertEqual(self.iDocumentReferences[1]["theDocName"],
                         odr2.document())
        self.assertEqual(self.iDocumentReferences[1]["theContributor"],
                         odr2.contributor())
        self.assertEqual(self.iDocumentReferences[1]["theExcerpt"],
                         odr2.excerpt())
        self.assertEqual(self.iDocumentReferences[2]["theName"], odr3.name())
        self.assertEqual(self.iDocumentReferences[2]["theDocName"],
                         odr3.document())
        self.assertEqual(self.iDocumentReferences[2]["theContributor"],
                         odr3.contributor())
        self.assertEqual(self.iDocumentReferences[2]["theExcerpt"],
                         odr3.excerpt())

        ipc1 = PersonaCharacteristicParameters(
            self.iPersonaCharacteristics[0]["thePersonaName"],
            self.iPersonaCharacteristics[0]["theModQual"],
            self.iPersonaCharacteristics[0]["theVariable"],
            self.iPersonaCharacteristics[0]["theCharacteristic"],
            [(self.iPersonaCharacteristics[0]["ground"], '', 'document')],
            [(self.iPersonaCharacteristics[0]["warrant"], '', 'document')], [],
            [(self.iPersonaCharacteristics[0]["rebuttal"], '', 'document')])

        b.dbProxy.addPersonaCharacteristic(ipc1)
        opcs = b.dbProxy.getPersonaCharacteristics()
        opc1 = opcs[self.iPersonaCharacteristics[0]["thePersonaName"] + '/' +
                    self.iPersonaCharacteristics[0]["theVariable"] + '/' +
                    self.iPersonaCharacteristics[0]["theCharacteristic"]]

        self.assertEqual(self.iPersonaCharacteristics[0]["thePersonaName"],
                         opc1.persona())
        self.assertEqual(self.iPersonaCharacteristics[0]["theModQual"],
                         opc1.qualifier())
        self.assertEqual(self.iPersonaCharacteristics[0]["theVariable"],
                         opc1.behaviouralVariable())
        self.assertEqual(self.iPersonaCharacteristics[0]["theCharacteristic"],
                         opc1.characteristic())
        self.assertEqual(self.iPersonaCharacteristics[0]["ground"],
                         opc1.grounds()[0][0])
        self.assertEqual(self.iPersonaCharacteristics[0]["warrant"],
                         opc1.warrant()[0][0])
        self.assertEqual(self.iPersonaCharacteristics[0]["rebuttal"],
                         opc1.rebuttal()[0][0])

        b.dbProxy.deletePersonaCharacteristic(opc1.id())

        b.dbProxy.deleteDocumentReference(odr1.id())
        b.dbProxy.deleteDocumentReference(odr2.id())
        b.dbProxy.deleteDocumentReference(odr3.id())

        b.dbProxy.deleteExternalDocument(oec1.id())
        b.dbProxy.deleteExternalDocument(oec2.id())
        b.dbProxy.deletePersona(op.id())
コード例 #11
0
 def endElement(self, name):
     if name == 'persona':
         p = PersonaParameters(self.theName, self.theActivities,
                               self.theAttitudes, self.theAptitudes,
                               self.theMotivations, self.theSkills,
                               self.theIntrinsic, self.theContextual,
                               self.theImage, self.isAssumptionPersona,
                               self.theType, self.theTags,
                               self.theEnvironmentProperties, {})
         self.thePersonas.append(p)
         self.resetPersonaAttributes()
     elif name == 'persona_environment':
         p = PersonaEnvironmentProperties(self.theEnvironmentName,
                                          self.isDirect, self.theNarrative,
                                          self.theRoles, {'narrative': {}})
         self.theEnvironmentProperties.append(p)
         self.resetPersonaEnvironmentAttributes()
     elif name == 'external_document':
         p = ExternalDocumentParameters(self.theName, self.theVersion,
                                        self.theDate, self.theAuthors,
                                        self.theDescription)
         self.theExternalDocuments.append(p)
         self.resetExternalDocumentAttributes()
     elif name == 'document_reference':
         p = DocumentReferenceParameters(self.theName, self.theDocument,
                                         self.theContributor,
                                         self.theExcerpt)
         self.theDocumentReferences.append(p)
         self.resetDocumentReferenceAttributes()
     elif name == 'concept_reference':
         p = ConceptReferenceParameters(self.theName, self.theConcept,
                                        self.theObject, self.theDescription)
         self.theConceptReferences.append(p)
         self.resetConceptReferenceAttributes()
     elif name == 'persona_characteristic':
         p = PersonaCharacteristicParameters(
             self.thePersona, self.theModalQualifier, self.theBvName,
             self.theDefinition, self.theGrounds, self.theWarrants, [],
             self.theRebuttals)
         self.thePersonaCharacteristics.append(p)
         self.resetPersonaCharacteristicAttributes()
     elif name == 'task_characteristic':
         p = TaskCharacteristicParameters(self.theTask,
                                          self.theModalQualifier,
                                          self.theDefinition,
                                          self.theGrounds, self.theWarrants,
                                          [], self.theRebuttals)
         self.theTaskCharacteristics.append(p)
         self.resetTaskCharacteristicAttributes()
     elif name == 'task':
         p = TaskParameters(self.theName, self.theCode, self.theObjective,
                            self.isAssumptionTask, self.theAuthor,
                            self.theTags, self.theEnvironmentProperties)
         self.theTasks.append(p)
         self.resetTaskAttributes()
     elif name == 'task_environment':
         p = TaskEnvironmentProperties(
             self.theEnvironmentName, self.theDependencies,
             self.theTaskPersonas, self.theConcerns,
             self.theConcernAssociations, self.theNarrative,
             self.theConsequences, self.theBenefits, {
                 'narrative': {},
                 'consequences': {},
                 'benefits': {}
             })
         self.theEnvironmentProperties.append(p)
         self.resetTaskEnvironmentAttributes()
     elif name == 'exception':
         self.theCurrentStep.addException(
             (self.theExcName, self.theExcType, self.theExcValue,
              self.theExcCat, self.theDefinition))
     elif name == 'step':
         self.theCurrentStep.setTags(self.theTags)
         self.theSteps.append(self.theCurrentStep)
         self.theCurrentStep = None
     elif name == 'usecase_environment':
         p = UseCaseEnvironmentProperties(self.theEnvironmentName,
                                          self.thePreconditions,
                                          self.theSteps,
                                          self.thePostconditions)
         self.theEnvironmentProperties.append(p)
         self.resetUseCaseEnvironmentAttributes()
     elif name == 'usecase':
         p = UseCaseParameters(self.theName, self.theAuthor, self.theCode,
                               self.theActors, self.theDescription,
                               self.theTags, self.theEnvironmentProperties)
         self.theUseCases.append(p)
         self.resetUseCaseAttributes()
     elif name == 'activities':
         self.inActivities = 0
     elif name == 'attitudes':
         self.inAttitudes = 0
     elif name == 'aptitudes':
         self.inAptitudes = 0
     elif name == 'motivations':
         self.inMotivations = 0
     elif name == 'skills':
         self.inSkills = 0
     elif name == 'intrinsic':
         self.inIntrinsic = 0
     elif name == 'contextual':
         self.inContextual = 0
     elif name == 'narrative':
         self.inNarrative = 0
     elif name == 'excerpt':
         self.inExcerpt = 0
     elif name == 'description':
         self.inDescription = 0
     elif name == 'definition':
         self.inDefinition = 0
     elif name == 'dependencies':
         self.inDependencies = 0
     elif name == 'objective':
         self.inObjective = 0
     elif name == 'preconditions':
         self.inPreconditions = 0
     elif name == 'postconditions':
         self.inPostconditions = 0
     elif name == 'benefits':
         self.inBenefits = 0
     elif name == 'consequences':
         self.inConsequences = 0
コード例 #12
0
ファイル: test_Countermeasure.py プロジェクト: gkmacc/cairis
    def setUp(self):
        call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/countermeasures.json')
        d = json.load(f)
        f.close()
        self.ienvs = d['environments']
        self.iep1 = EnvironmentParameters(self.ienvs[0]["theName"],
                                          self.ienvs[0]["theShortCode"],
                                          self.ienvs[0]["theDescription"])
        b = Borg()
        b.dbProxy.addEnvironment(self.iep1)
        self.oenvs = b.dbProxy.getEnvironments()
        self.iRoles = d['roles']
        self.irp = RoleParameters(self.iRoles[0]["theName"],
                                  self.iRoles[0]["theType"],
                                  self.iRoles[0]["theShortCode"],
                                  self.iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(self.irp)
        self.oRoles = b.dbProxy.getRoles()
        self.iPersonas = d['personas']
        self.ipp = PersonaParameters(
            self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
            self.iPersonas[0]["theAttitudes"],
            self.iPersonas[0]["theAptitudes"],
            self.iPersonas[0]["theMotivations"],
            self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
            self.iPersonas[0]["theContextual"], "", "0",
            self.iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                                  [0]["theDirectFlag"] == "True"),
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theNarrative"], self.iPersonas[0]
                    ["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b.dbProxy.addPersona(self.ipp)
        self.opp = b.dbProxy.getPersonas()
        self.iExternalDocuments = d['external_documents']
        self.iec1 = ExternalDocumentParameters(
            self.iExternalDocuments[0]["theName"],
            self.iExternalDocuments[0]["theVersion"],
            self.iExternalDocuments[0]["thePublicationDate"],
            self.iExternalDocuments[0]["theAuthors"],
            self.iExternalDocuments[0]["theDescription"])
        self.iec2 = ExternalDocumentParameters(
            self.iExternalDocuments[1]["theName"],
            self.iExternalDocuments[1]["theVersion"],
            self.iExternalDocuments[1]["thePublicationDate"],
            self.iExternalDocuments[1]["theAuthors"],
            self.iExternalDocuments[1]["theDescription"])
        b.dbProxy.addExternalDocument(self.iec1)
        b.dbProxy.addExternalDocument(self.iec2)
        self.oecs = b.dbProxy.getExternalDocuments()
        self.iDocumentReferences = d['document_references']
        self.idr1 = DocumentReferenceParameters(
            self.iDocumentReferences[0]["theName"],
            self.iDocumentReferences[0]["theDocName"],
            self.iDocumentReferences[0]["theContributor"],
            self.iDocumentReferences[0]["theExcerpt"])
        self.idr2 = DocumentReferenceParameters(
            self.iDocumentReferences[1]["theName"],
            self.iDocumentReferences[1]["theDocName"],
            self.iDocumentReferences[1]["theContributor"],
            self.iDocumentReferences[1]["theExcerpt"])
        b.dbProxy.addDocumentReference(self.idr1)
        b.dbProxy.addDocumentReference(self.idr2)
        self.odrs = b.dbProxy.getDocumentReferences()
        self.iPersonaCharacteristics = d['persona_characteristics']
        self.ipc1 = PersonaCharacteristicParameters(
            self.iPersonaCharacteristics[0]["thePersonaName"],
            self.iPersonaCharacteristics[0]["theModQual"],
            self.iPersonaCharacteristics[0]["theVariable"],
            self.iPersonaCharacteristics[0]["theCharacteristic"],
            [(self.iPersonaCharacteristics[0]["ground"], '', 'document')],
            [(self.iPersonaCharacteristics[0]["warrant"], '', 'document')], [],
            [])
        b.dbProxy.addPersonaCharacteristic(self.ipc1)
        self.opcs = b.dbProxy.getPersonaCharacteristics()
        self.iAttackers = d['attackers']
        self.iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"])
        ]
        self.iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                       self.iAttackers[0]["theDescription"],
                                       self.iAttackers[0]["theImage"], [],
                                       self.iatkeps)
        b.dbProxy.addAttacker(self.iatk)
        self.oAttackers = b.dbProxy.getAttackers()
        self.iVtypes = d['valuetypes']
        self.ivt1 = ValueTypeParameters(self.iVtypes[0]["theName"],
                                        self.iVtypes[0]["theDescription"],
                                        self.iVtypes[0]["theType"])
        self.ivt2 = ValueTypeParameters(self.iVtypes[1]["theName"],
                                        self.iVtypes[1]["theDescription"],
                                        self.iVtypes[1]["theType"])
        b.dbProxy.addValueType(self.ivt1)
        b.dbProxy.addValueType(self.ivt2)
        self.ovtt = b.dbProxy.getValueTypes('threat_type')
        self.ovtv = b.dbProxy.getValueTypes('vulnerability_type')
        self.iassets = d['assets']
        self.iaeps1 = [
            AssetEnvironmentProperties(
                self.iassets[0]["theEnvironmentProperties"][0][0],
                self.iassets[0]["theEnvironmentProperties"][0][1],
                self.iassets[0]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps2 = [
            AssetEnvironmentProperties(
                self.iassets[1]["theEnvironmentProperties"][0][0],
                self.iassets[1]["theEnvironmentProperties"][0][1],
                self.iassets[1]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps3 = [
            AssetEnvironmentProperties(
                self.iassets[2]["theEnvironmentProperties"][0][0],
                self.iassets[2]["theEnvironmentProperties"][0][1],
                self.iassets[2]["theEnvironmentProperties"][0][2])
        ]
        self.iap1 = AssetParameters(self.iassets[0]["theName"],
                                    self.iassets[0]["theShortCode"],
                                    self.iassets[0]["theDescription"],
                                    self.iassets[0]["theSignificance"],
                                    self.iassets[0]["theType"], "0", "N/A", [],
                                    [], self.iaeps1)
        self.iap2 = AssetParameters(self.iassets[1]["theName"],
                                    self.iassets[1]["theShortCode"],
                                    self.iassets[1]["theDescription"],
                                    self.iassets[1]["theSignificance"],
                                    self.iassets[1]["theType"], "0", "N/A", [],
                                    [], self.iaeps2)
        self.iap3 = AssetParameters(self.iassets[2]["theName"],
                                    self.iassets[2]["theShortCode"],
                                    self.iassets[2]["theDescription"],
                                    self.iassets[2]["theSignificance"],
                                    self.iassets[2]["theType"], "0", "N/A", [],
                                    [], self.iaeps3)
        b.dbProxy.addAsset(self.iap1)
        b.dbProxy.addAsset(self.iap2)
        b.dbProxy.addAsset(self.iap3)
        self.oap = b.dbProxy.getAssets()
        self.iThreats = d['threats']
        self.iteps = [
            ThreatEnvironmentProperties(
                self.iThreats[0]["theEnvironmentProperties"][0]["theName"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theLikelihood"],
                self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theAttackers"], self.iThreats[0]["theEnvironmentProperties"]
                [0]["theProperties"][0][1], self.iThreats[0]
                ["theEnvironmentProperties"][0]["theProperties"][0][1])
        ]
        self.itps = ThreatParameters(self.iThreats[0]["theName"],
                                     self.iThreats[0]["theType"],
                                     self.iThreats[0]["theMethod"], [],
                                     self.iteps)
        b.dbProxy.addThreat(self.itps)
        self.otps = b.dbProxy.getThreats()
        self.iVuln = d['vulnerabilities']
        self.iveps = [
            VulnerabilityEnvironmentProperties(
                self.iVuln[0]["theEnvironmentProperties"][0]["theName"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theAssets"])
        ]
        self.ivp = VulnerabilityParameters(self.iVuln[0]["theName"],
                                           self.iVuln[0]["theDescription"],
                                           self.iVuln[0]["theType"], [],
                                           self.iveps)
        b.dbProxy.addVulnerability(self.ivp)
        self.ovp = b.dbProxy.getVulnerabilities()
        self.imc = d['misuseCase']
        self.iRisks = d['risks']

        imcep = [
            MisuseCaseEnvironmentProperties(
                self.imc[0]["theEnvironmentProperties"][0]["theName"],
                self.imc[0]["theEnvironmentProperties"][0]["theDescription"])
        ]
        imcp = MisuseCase(int(0), self.imc[0]["theName"], imcep,
                          self.imc[0]["theRisk"])
        irp = RiskParameters(self.iRisks[0]["theName"],
                             self.iRisks[0]["threatName"],
                             self.iRisks[0]["vulName"], imcp, [])
        b.dbProxy.addRisk(irp)
        oRisks = b.dbProxy.getRisks()
        self.r = oRisks[self.iRisks[0]["theName"]]
        self.iResponses = d['responses']
        iar1Name = self.iResponses[0]["theType"] + " " + self.iResponses[0][
            "theRisk"]
        iaep1 = AcceptEnvironmentProperties(
            self.iResponses[0]["theEnvironmentProperties"][0],
            self.iResponses[0]["theEnvironmentProperties"][1],
            self.iResponses[0]["theEnvironmentProperties"][2])
        iar1 = ResponseParameters(iar1Name, self.iResponses[0]["theRisk"], [],
                                  [iaep1], self.iResponses[0]["theType"])

        iar2Name = self.iResponses[1]["theType"] + " " + self.iResponses[1][
            "theRisk"]
        iaep2 = MitigateEnvironmentProperties(
            self.iResponses[1]["theEnvironmentProperties"],
            self.iResponses[1]["theType"])
        iar2 = ResponseParameters(iar2Name, self.iResponses[1]["theRisk"], [],
                                  [iaep2], self.iResponses[1]["theType"])

        b.dbProxy.addResponse(iar1)
        b.dbProxy.addResponse(iar2)

        self.ors = b.dbProxy.getResponses()
        self.oar1 = self.ors[iar1Name]
        self.oar2 = self.ors[iar2Name]

        rgp = cairis.core.GoalFactory.build(self.oar2)
        riskParameters = rgp[0]
        riskGoalId = b.dbProxy.addGoal(riskParameters)
        b.dbProxy.addTrace('response_goal', self.oar2.id(), riskGoalId)
        if (rgp > 1):
            threatParameters = rgp[1]
            vulnerabilityParameters = rgp[2]
            b.dbProxy.addGoal(vulnerabilityParameters)
            b.dbProxy.addGoal(threatParameters)
        b.dbProxy.relabelGoals(iaep2.name())

        oGoals = b.dbProxy.getGoals()
        self.rg = oGoals['Deter' + self.oar2.risk()]
        self.vg = oGoals[vulnerabilityParameters.name()]
        self.tg = oGoals[threatParameters.name()]

        ogops = b.dbProxy.getGoalAssociations()
        self.ogop1 = ogops[iaep2.name() + '/' + riskParameters.name() + '/' +
                           threatParameters.name() + '/or']
        self.ogop2 = ogops[iaep2.name() + '/' + riskParameters.name() + '/' +
                           vulnerabilityParameters.name() + '/or']

        self.reqId = b.dbProxy.newId()
        self.irequirements = d['requirements']
        self.ireq = cairis.core.RequirementFactory.build(
            self.reqId, self.irequirements[0]["theLabel"],
            self.irequirements[0]["theName"],
            self.irequirements[0]["theDescription"],
            self.irequirements[0]["thePriority"],
            self.irequirements[0]["theRationale"],
            self.irequirements[0]["theFitCriterion"],
            self.irequirements[0]["theOriginator"],
            self.irequirements[0]["theType"],
            self.irequirements[0]["theReference"], 1)
        b.dbProxy.addRequirement(self.ireq,
                                 self.irequirements[0]["theReference"], True)
        oreqs = b.dbProxy.getRequirements()
        self.oreq = oreqs[self.ireq.description()]

        iga = GoalAssociationParameters(iaep2.name(),
                                        self.vg.name(), 'goal', 'and',
                                        self.oreq.name(), 'requirement', 0,
                                        'None')
        b.dbProxy.addGoalAssociation(iga)
        ogops = b.dbProxy.getGoalAssociations()
        self.ogop3 = ogops[iaep2.name() + '/' + self.vg.name() + '/' +
                           self.oreq.name() + '/and']

        self.iCountermeasures = d['countermeasures']
コード例 #13
0
ファイル: test_Countermeasure.py プロジェクト: we45/cairis
  def setUp(self):
    call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
    cairis.core.BorgFactory.initialise()
    f = open(os.environ['CAIRIS_SRC'] + '/test/countermeasures.json')
    d = json.load(f)
    f.close()
    ienvs = d['environments']
    iep1 = EnvironmentParameters(ienvs[0]["theName"],ienvs[0]["theShortCode"],ienvs[0]["theDescription"])
    b = Borg()
    b.dbProxy.addEnvironment(iep1)
    iRoles = d['roles']
    irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"], iRoles[0]["theShortCode"], iRoles[0]["theDescription"],[])
    b.dbProxy.addRole(irp)
    iPersonas = d['personas']
    ipp = PersonaParameters(iPersonas[0]["theName"],iPersonas[0]["theActivities"],iPersonas[0]["theAttitudes"],iPersonas[0]["theAptitudes"],iPersonas[0]["theMotivations"],iPersonas[0]["theSkills"],iPersonas[0]["theIntrinsic"],iPersonas[0]["theContextual"],"","0",iPersonas[0]["thePersonaType"],[],[PersonaEnvironmentProperties(iPersonas[0]["theEnvironmentProperties"][0]["theName"],(iPersonas[0]["theEnvironmentProperties"][0]["theDirectFlag"] == "True"),iPersonas[0]["theEnvironmentProperties"][0]["theNarrative"],iPersonas[0]["theEnvironmentProperties"][0]["theRole"])],[])
    b.dbProxy.addPersona(ipp)
    iAttackers = d['attackers']
    iatkeps = [AttackerEnvironmentProperties(iAttackers[0]["theEnvironmentProperties"][0]["theName"],iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],iAttackers[0]["theEnvironmentProperties"][0]["theMotives"],iAttackers[0]["theEnvironmentProperties"][0]["theCapabilities"])]
    iatk = AttackerParameters(iAttackers[0]["theName"], iAttackers[0]["theDescription"], iAttackers[0]["theImage"],[],iatkeps)
    b.dbProxy.addAttacker(iatk)
    iVtypes = d['valuetypes']
    ivt1 = ValueTypeParameters(iVtypes[0]["theName"], iVtypes[0]["theDescription"], iVtypes[0]["theType"])
    ivt2 = ValueTypeParameters(iVtypes[1]["theName"], iVtypes[1]["theDescription"], iVtypes[1]["theType"])
    b.dbProxy.addValueType(ivt1)
    b.dbProxy.addValueType(ivt2)
    iassets = d['assets']
    iaeps1 = [AssetEnvironmentProperties(iassets[0]["theEnvironmentProperties"][0][0],iassets[0]["theEnvironmentProperties"][0][1],iassets[0]["theEnvironmentProperties"][0][2])]
    iaeps2 = [AssetEnvironmentProperties(iassets[1]["theEnvironmentProperties"][0][0],iassets[1]["theEnvironmentProperties"][0][1],iassets[1]["theEnvironmentProperties"][0][2])]
    iaeps3 = [AssetEnvironmentProperties(iassets[2]["theEnvironmentProperties"][0][0],iassets[2]["theEnvironmentProperties"][0][1],iassets[2]["theEnvironmentProperties"][0][2])]
    iap1 = AssetParameters(iassets[0]["theName"],iassets[0]["theShortCode"],iassets[0]["theDescription"],iassets[0]["theSignificance"],iassets[0]["theType"],"0","N/A",[],[],iaeps1)
    iap2 = AssetParameters(iassets[1]["theName"],iassets[1]["theShortCode"],iassets[1]["theDescription"],iassets[1]["theSignificance"],iassets[1]["theType"],"0","N/A",[],[],iaeps2)
    iap3 = AssetParameters(iassets[2]["theName"],iassets[2]["theShortCode"],iassets[2]["theDescription"],iassets[2]["theSignificance"],iassets[2]["theType"],"0","N/A",[],[],iaeps3)
    b.dbProxy.addAsset(iap1)
    b.dbProxy.addAsset(iap2)
    b.dbProxy.addAsset(iap3)
    iThreats = d['threats']
    iteps = [ThreatEnvironmentProperties(iThreats[0]["theEnvironmentProperties"][0]["theName"],iThreats[0]["theEnvironmentProperties"][0]["theLikelihood"],iThreats[0]["theEnvironmentProperties"][0]["theAssets"],iThreats[0]["theEnvironmentProperties"][0]["theAttackers"],iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1],iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1])]
    itps = ThreatParameters(iThreats[0]["theName"],iThreats[0]["theType"],iThreats[0]["theMethod"],[],iteps)
    b.dbProxy.addThreat(itps)
    iVuln = d['vulnerabilities']
    iveps = [VulnerabilityEnvironmentProperties(iVuln[0]["theEnvironmentProperties"][0]["theName"],iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],iVuln[0]["theEnvironmentProperties"][0]["theAssets"])]
    ivp = VulnerabilityParameters(iVuln[0]["theName"],iVuln[0]["theDescription"],iVuln[0]["theType"], [], iveps)
    b.dbProxy.addVulnerability(ivp)
    imc = d['misuseCase']
    iRisks = d['risks']
    imcep = [MisuseCaseEnvironmentProperties(imc[0]["theEnvironmentProperties"][0]["theName"],imc[0]["theEnvironmentProperties"][0]["theDescription"])]
    imcp = MisuseCase(int(0), imc[0]["theName"], imcep,imc[0]["theRisk"])
    irp = RiskParameters(iRisks[0]["theName"],iRisks[0]["threatName"],iRisks[0]["vulName"], imcp,[])
    b.dbProxy.addRisk(irp)
    iResponses = d['responses']
    iar1Name = iResponses[0]["theType"] + " " + iResponses[0]["theRisk"] 
    iaep1 = AcceptEnvironmentProperties(iResponses[0]["theEnvironmentProperties"][0],iResponses[0]["theEnvironmentProperties"][1],iResponses[0]["theEnvironmentProperties"][2])
    iar1 = ResponseParameters(iar1Name,iResponses[0]["theRisk"],[],[iaep1], iResponses[0]["theType"])

    iar2Name = iResponses[1]["theType"] + " " + iResponses[1]["theRisk"] 
    iaep2 = MitigateEnvironmentProperties(iResponses[1]["theEnvironmentProperties"],iResponses[1]["theType"])
    iar2 = ResponseParameters(iar2Name,iResponses[1]["theRisk"],[],[iaep2], iResponses[1]["theType"])

    b.dbProxy.addResponse(iar1)
    b.dbProxy.addResponse(iar2)

    ors = b.dbProxy.getResponses()
    oar1 = ors[iar1Name]
    oar2 = ors[iar2Name]

    rgp = cairis.core.GoalFactory.build(oar2)
    riskParameters = rgp[0]
    riskGoalId = b.dbProxy.addGoal(riskParameters)
    b.dbProxy.addTrace('response_goal',oar2.id(),riskGoalId)
    if (len(rgp) > 1):
      threatParameters = rgp[1]
      vulnerabilityParameters = rgp[2]
      b.dbProxy.addGoal(vulnerabilityParameters)
      b.dbProxy.addGoal(threatParameters)
    b.dbProxy.relabelGoals(iaep2.name())

    oGoals = b.dbProxy.getGoals()
    rg = oGoals['Deter' + oar2.risk()]
    vg = oGoals[vulnerabilityParameters.name()]
    tg = oGoals[threatParameters.name()]

    reqId = b.dbProxy.newId()
    irequirements = d['requirements']
    ireq = cairis.core.RequirementFactory.build(reqId,irequirements[0]["theLabel"],irequirements[0]["theName"],irequirements[0]["theDescription"],irequirements[0]["thePriority"],irequirements[0]["theRationale"],irequirements[0]["theFitCriterion"],irequirements[0]["theOriginator"],irequirements[0]["theType"],irequirements[0]["theReference"],1)
    b.dbProxy.addRequirement(ireq,irequirements[0]["theReference"],True)

    oreqs = b.dbProxy.getRequirements()
    oreq = oreqs[ireq.description()]

    iga = GoalAssociationParameters(iaep2.name(),vg.name(),'goal','and',oreq.name(),'requirement',0,'None')
    b.dbProxy.addGoalAssociation(iga)
    ogops = b.dbProxy.getGoalAssociations()
    self.ogop3 = ogops[iaep2.name() + '/' + vg.name() + '/' + oreq.name() + '/and']
    self.iCountermeasures = d['countermeasures']
コード例 #14
0
 def setUp(self):
     call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
     cairis.core.BorgFactory.initialise()
     f = open(os.environ['CAIRIS_SRC'] + '/test/attackers.json')
     d = json.load(f)
     f.close()
     self.ienvs = d['environments']
     self.iep = EnvironmentParameters(self.ienvs[0]["theName"],
                                      self.ienvs[0]["theShortCode"],
                                      self.ienvs[0]["theDescription"])
     b = Borg()
     b.dbProxy.addEnvironment(self.iep)
     self.oenvs = b.dbProxy.getEnvironments()
     self.iRoles = d['roles']
     self.irp = RoleParameters(self.iRoles[0]["theName"],
                               self.iRoles[0]["theType"],
                               self.iRoles[0]["theShortCode"],
                               self.iRoles[0]["theDescription"], [])
     b.dbProxy.addRole(self.irp)
     self.oRoles = b.dbProxy.getRoles()
     self.iPersonas = d['personas']
     self.ipp = PersonaParameters(
         self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
         self.iPersonas[0]["theAttitudes"],
         self.iPersonas[0]["theAptitudes"],
         self.iPersonas[0]["theMotivations"],
         self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
         self.iPersonas[0]["theContextual"], "", "0",
         self.iPersonas[0]["thePersonaType"], [], [
             PersonaEnvironmentProperties(
                 self.iPersonas[0]["theEnvironmentProperties"][0]
                 ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                               [0]["theDirectFlag"] == "True"),
                 self.iPersonas[0]["theEnvironmentProperties"][0]
                 ["theNarrative"], self.iPersonas[0]
                 ["theEnvironmentProperties"][0]["theRole"])
         ], [])
     b.dbProxy.addPersona(self.ipp)
     self.opp = b.dbProxy.getPersonas()
     self.iExternalDocuments = d['external_documents']
     self.iec1 = ExternalDocumentParameters(
         self.iExternalDocuments[0]["theName"],
         self.iExternalDocuments[0]["theVersion"],
         self.iExternalDocuments[0]["thePublicationDate"],
         self.iExternalDocuments[0]["theAuthors"],
         self.iExternalDocuments[0]["theDescription"])
     self.iec2 = ExternalDocumentParameters(
         self.iExternalDocuments[1]["theName"],
         self.iExternalDocuments[1]["theVersion"],
         self.iExternalDocuments[1]["thePublicationDate"],
         self.iExternalDocuments[1]["theAuthors"],
         self.iExternalDocuments[1]["theDescription"])
     b.dbProxy.addExternalDocument(self.iec1)
     b.dbProxy.addExternalDocument(self.iec2)
     self.oecs = b.dbProxy.getExternalDocuments()
     self.iDocumentReferences = d['document_references']
     self.idr1 = DocumentReferenceParameters(
         self.iDocumentReferences[0]["theName"],
         self.iDocumentReferences[0]["theDocName"],
         self.iDocumentReferences[0]["theContributor"],
         self.iDocumentReferences[0]["theExcerpt"])
     self.idr2 = DocumentReferenceParameters(
         self.iDocumentReferences[1]["theName"],
         self.iDocumentReferences[1]["theDocName"],
         self.iDocumentReferences[1]["theContributor"],
         self.iDocumentReferences[1]["theExcerpt"])
     b.dbProxy.addDocumentReference(self.idr1)
     b.dbProxy.addDocumentReference(self.idr2)
     self.odrs = b.dbProxy.getDocumentReferences()
     self.iPersonaCharacteristics = d['persona_characteristics']
     self.ipc1 = PersonaCharacteristicParameters(
         self.iPersonaCharacteristics[0]["thePersonaName"],
         self.iPersonaCharacteristics[0]["theModQual"],
         self.iPersonaCharacteristics[0]["theVariable"],
         self.iPersonaCharacteristics[0]["theCharacteristic"],
         [(self.iPersonaCharacteristics[0]["ground"], '', 'document')],
         [(self.iPersonaCharacteristics[0]["warrant"], '', 'document')], [],
         [])
     b.dbProxy.addPersonaCharacteristic(self.ipc1)
     self.opcs = b.dbProxy.getPersonaCharacteristics()
     self.iAttackers = d['attackers']
コード例 #15
0
    def setUp(self):
        call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/processes.json')
        d = json.load(f)
        f.close()

        b = Borg()
        iIntDocs = d['internaldocuments']
        i = InternalDocumentParameters(iIntDocs[0]["theName"],
                                       iIntDocs[0]["theDescription"],
                                       iIntDocs[0]["theContent"], [], [])
        b.dbProxy.addInternalDocument(i)

        iCodes = d['codes']
        i = CodeParameters(iCodes[0]["theName"], iCodes[0]["theType"],
                           iCodes[0]["theDescription"],
                           iCodes[0]["theInclusionCriteria"],
                           iCodes[0]["theExample"])
        b.dbProxy.addCode(i)
        i = CodeParameters(iCodes[1]["theName"], iCodes[1]["theType"],
                           iCodes[1]["theDescription"],
                           iCodes[1]["theInclusionCriteria"],
                           iCodes[1]["theExample"])
        b.dbProxy.addCode(i)
        iQs = d['quotations']
        i = (iQs[0]["theType"], iQs[0]["theCode"], iQs[0]["theArtifactType"],
             iQs[0]["theArtifactName"], iQs[0]["theEnvironment"],
             iQs[0]["theSection"], iQs[0]["theStartIdx"], iQs[0]["theEndIdx"],
             iQs[0]["theLabel"], iQs[0]["theSynopsis"])
        b.dbProxy.addQuotation(i)
        i = (iQs[2]['theType'], iQs[2]["theCode"], iQs[2]["theArtifactType"],
             iQs[2]["theArtifactName"], iQs[2]["theEnvironment"],
             iQs[2]["theSection"], iQs[2]["theStartIdx"], iQs[2]["theEndIdx"],
             iQs[2]["theLabel"], iQs[2]["theSynopsis"])
        b.dbProxy.addQuotation(i)
        iEnvironments = d['environments']
        iep1 = EnvironmentParameters(iEnvironments[0]["theName"],
                                     iEnvironments[0]["theShortCode"],
                                     iEnvironments[0]["theDescription"])
        b.dbProxy.addEnvironment(iep1)
        iRoles = d['roles']
        irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"],
                             iRoles[0]["theShortCode"],
                             iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(irp)
        iPersonas = d['personas']
        ipp = PersonaParameters(
            iPersonas[0]["theName"], iPersonas[0]["theActivities"],
            iPersonas[0]["theAttitudes"], iPersonas[0]["theAptitudes"],
            iPersonas[0]["theMotivations"], iPersonas[0]["theSkills"],
            iPersonas[0]["theIntrinsic"], iPersonas[0]["theContextual"], "",
            "0", iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    iPersonas[0]["theEnvironmentProperties"][0]["theName"],
                    (iPersonas[0]["theEnvironmentProperties"][0]
                     ["theDirectFlag"] == "True"), iPersonas[0]
                    ["theEnvironmentProperties"][0]["theNarrative"],
                    iPersonas[0]["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b.dbProxy.addPersona(ipp)
        self.iCN = d['code_networks']
        b.dbProxy.addCodeRelationship(self.iCN[0]["thePersonaName"],
                                      self.iCN[0]["theFromCode"],
                                      self.iCN[0]["theToCode"],
                                      self.iCN[0]["theRshipType"])