def prepare_new_threat(self): new_security_attrs = [ SecurityAttribute( name='Confidentiality', value='High', rationale='As a test' ), SecurityAttribute( name='Availability', value='Medium', rationale='Another test' ) ] new_threat_props = [ ThreatEnvironmentProperties( environmentName=self.existing_environment_name_1, lhood='Incredible', assets=self.existing_asset_names, attackers=self.existing_attackers_names, syProperties=new_security_attrs, pRationale=[] ), ThreatEnvironmentProperties( environmentName=self.existing_environment_name_2, lhood='Improbable', assets=self.existing_asset_names, attackers=self.existing_attackers_names, syProperties=new_security_attrs, pRationale=[] ) ] new_threat = Threat( threatId=-1, threatName='Test threat', threatType=self.existing_threat_type, threatMethod='', tags=[], cProps=[] ) new_threat.theEnvironmentProperties = new_threat_props new_threat.theEnvironmentDictionary = {} new_threat.likelihoodLookup = {} new_threat.theThreatPropertyDictionary = {} delattr(new_threat, 'theEnvironmentDictionary') delattr(new_threat, 'likelihoodLookup') delattr(new_threat, 'theThreatPropertyDictionary') return new_threat
def convert_props(self, real_props=None, fake_props=None): new_props = [] if real_props is not None: if len(real_props) > 0: assert isinstance(real_props[0], ThreatEnvironmentProperties) for real_prop in real_props: assert isinstance(real_prop, ThreatEnvironmentProperties) assert len(real_prop.theProperties) == len( real_prop.theRationale) new_attrs = [] for idx in range(0, len(real_prop.theProperties)): attr_name = self.rev_attr_dict.get(idx) attr_value = self.prop_dict[ real_prop.theProperties[idx]] attr_rationale = real_prop.theRationale[idx] new_attr = SecurityAttribute(attr_name, attr_value, attr_rationale) new_attrs.append(new_attr) real_prop.theProperties = new_attrs del real_prop.theRationale new_props.append(real_prop) return new_props elif fake_props is not None: if len(fake_props) > 0: check_required_keys(fake_props[0], ThreatEnvironmentPropertiesModel.required) for fake_prop in fake_props: check_required_keys( fake_prop, ThreatEnvironmentPropertiesModel.required) new_ndprops = array([0] * 8).astype(numpy.core.int32) new_ratios = ['None'] * 8 for idx in range(0, len(fake_prop['theProperties'])): new_attr = fake_prop['theProperties'][idx] check_required_keys(new_attr, SecurityAttribute.required) attr_id = self.attr_dict.get(new_attr['name'], -1) if -1 < attr_id < len(self.attr_dict): attr_value = self.rev_prop_dict[new_attr['value']] attr_rationale = new_attr['rationale'] new_ndprops[attr_id] = attr_value new_ratios[attr_id] = attr_rationale fake_prop['theProperties'] = new_ndprops fake_prop['theRationale'] = new_ratios new_prop = ThreatEnvironmentProperties( environmentName=fake_prop['theEnvironmentName'], lhood=fake_prop['theLikelihood'], assets=fake_prop['theAssets'], attackers=fake_prop['theAttackers'], pRationale=fake_prop['theRationale'], syProperties=fake_prop['theProperties']) new_props.append(new_prop) return new_props else: self.close() raise MissingParameterHTTPError( param_names=['real_props', 'fake_props'])
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, CountermeasureEnvironmentProperties) ctList = [] for ctc in real_prop.personas(): ctList.append(CountermeasureTaskCharacteristics(ctc[0],ctc[1],ctc[2],ctc[3],ctc[4],ctc[5])) real_prop.thePersonas = ctList assert len(real_prop.theProperties) == len(real_prop.theRationale) new_attrs = [] for idx in range(0, len(real_prop.theProperties)): attr_name = self.rev_attr_dict.get(idx) attr_value = self.prop_dict[real_prop.theProperties[idx]] attr_rationale = real_prop.theRationale[idx] new_attr = SecurityAttribute(attr_name, attr_value, attr_rationale) new_attrs.append(new_attr) real_prop.theProperties = new_attrs new_targets = [] for idx in range(0, len(real_prop.theTargets)): tName = real_prop.theTargets[idx].name() tEff = real_prop.theTargets[idx].effectiveness() tRat = real_prop.theTargets[idx].rationale() new_targets.append(CountermeasureTarget(tName,tEff,tRat)) real_prop.theTargets = new_targets new_props.append(real_prop) return new_props elif fake_props is not None: if len(fake_props) > 0: for fake_prop in fake_props: check_required_keys(fake_prop, CountermeasureEnvironmentPropertiesModel.required) ctList = [] for ctc in fake_prop['thePersonas']: ctList.append([ctc['theTask'],ctc['thePersona'],ctc['theDuration'],ctc['theFrequency'],ctc['theDemands'],ctc['theGoalConflict']]) fake_prop['thePersonas'] = ctList new_ndprops = array([0]*8).astype(numpy.core.int32) new_ratios = ['None']*8 for idx in range(0, len(fake_prop['theProperties'])): new_attr = fake_prop['theProperties'][idx] check_required_keys(new_attr, SecurityAttribute.required) attr_id = self.attr_dict.get(new_attr['name'], -1) if -1 < attr_id < len(self.attr_dict): attr_value = self.rev_prop_dict[new_attr['value']] attr_rationale = new_attr['rationale'] new_ndprops[attr_id] = attr_value new_ratios[attr_id] = attr_rationale fake_prop['theProperties'] = new_ndprops fake_prop['theRationale'] = new_ratios new_targets = [] for idx in range(0, len(fake_prop['theTargets'])): tName = fake_prop['theTargets'][idx]['theName'] tEff = fake_prop['theTargets'][idx]['theEffectiveness'] tRat = fake_prop['theTargets'][idx]['theRationale'] new_targets.append(CountermeasureTarget(tName,tEff,tRat)) fake_prop['theTargets'] = new_targets check_required_keys(fake_prop, CountermeasureEnvironmentPropertiesModel.required) new_prop = CountermeasureEnvironmentProperties( environmentName=fake_prop['theEnvironmentName'], requirements=fake_prop['theRequirements'], targets=fake_prop['theTargets'], properties=fake_prop['theProperties'], rationale=fake_prop['theRationale'], cost=fake_prop['theCost'], roles=fake_prop['theRoles'], personas=fake_prop['thePersonas'] ) new_props.append(new_prop) return new_props else: self.close() raise MissingParameterHTTPError(param_names=['real_props', 'fake_props'])