<s> from mixbox import idgen <EOL> from mixbox . cache import Cached <EOL> from cybox . core import Observable , Observables <EOL> import stix <EOL> import stix . utils as utils <EOL> import stix . utils . parser as parser <EOL> from stix . utils . deprecated import deprecated <EOL> from stix . campaign import Campaign <EOL> from stix . coa import CourseOfAction <EOL> from stix . exploit_target import ExploitTarget <EOL> from stix . indicator import Indicator <EOL> from stix . incident import Incident <EOL> from stix . threat_actor import ThreatActor <EOL> from stix . ttp import TTP <EOL> from stix . report import Report <EOL> from stix . common . related import RelatedPackages <EOL> from . stix_header import STIXHeader <EOL> from . ttps import TTPs <EOL> from . import ( Campaigns , CoursesOfAction , ExploitTargets , Incidents , <EOL> Indicators , ThreatActors , Reports ) <EOL> import stix . bindings . stix_core as stix_core_binding <EOL> class STIXPackage ( Cached , stix . Entity ) : <EOL> """<STR_LIT>""" <EOL> _binding = stix_core_binding <EOL> _binding_class = _binding . STIXType <EOL> _namespace = '<STR_LIT>' <EOL> _version = "<STR_LIT>" <EOL> _ALL_VERSIONS = ( "<STR_LIT:1.0>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def __init__ ( self , id_ = None , idref = None , timestamp = None , stix_header = None , <EOL> courses_of_action = None , exploit_targets = None , indicators = None , <EOL> observables = None , incidents = None , threat_actors = None , <EOL> ttps = None , campaigns = None , related_packages = None , <EOL> reports = None ) : <EOL> self . id_ = id_ or idgen . create_id ( "<STR_LIT>" ) <EOL> self . idref = idref <EOL> self . _version = STIXPackage . _version <EOL> self . stix_header = stix_header <EOL> self . campaigns = campaigns <EOL> self . courses_of_action = courses_of_action <EOL> self . exploit_targets = exploit_targets <EOL> self . observables = observables <EOL> self . indicators = indicators <EOL> self . incidents = incidents <EOL> self . threat_actors = threat_actors <EOL> self . ttps = ttps <EOL> self . related_packages = related_packages <EOL> self . reports = reports <EOL> self . timestamp = timestamp <EOL> @ property <EOL> def id_ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _id <EOL> @ id_ . setter <EOL> def id_ ( self , value ) : <EOL> if not value : <EOL> self . _id = None <EOL> else : <EOL> self . _id = value <EOL> self . idref = None <EOL> @ property <EOL> def idref ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _idref <EOL> @ idref . setter <EOL> def idref ( self , value ) : <EOL> deprecated ( value ) <EOL> if not value : <EOL> self . _idref = None <EOL> else : <EOL> self . _idref = value <EOL> self . id_ = None <EOL> @ property <EOL> def timestamp ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _timestamp <EOL> @ timestamp . setter <EOL> def timestamp ( self , value ) : <EOL> deprecated ( value ) <EOL> self . _timestamp = utils . dates . parse_value ( value ) <EOL> @ property <EOL> def version ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _version <EOL> @ property <EOL> def stix_header ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _stix_header <EOL> @ stix_header . setter <EOL> def stix_header ( self , value ) : <EOL> self . _set_var ( STIXHeader , try_cast = False , stix_header = value ) <EOL> @ property <EOL> def indicators ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _indicators <EOL> @ indicators . setter <EOL> def indicators ( self , value ) : <EOL> self . _indicators = Indicators ( value ) <EOL> def add_indicator ( self , indicator ) : <EOL> """<STR_LIT>""" <EOL> self . indicators . append ( indicator ) <EOL> @ property <EOL> def campaigns ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _campaigns <EOL> @ campaigns . setter <EOL> def campaigns ( self , value ) : <EOL> self . _campaigns = Campaigns ( value ) <EOL> def add_campaign ( self , campaign ) : <EOL> """<STR_LIT>""" <EOL> self . campaigns . append ( campaign ) <EOL> @ property <EOL> def observables ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _observables <EOL> @ observables . setter <EOL> def observables ( self , value ) : <EOL> self . _set_var ( Observables , observables = value ) <EOL> def add_observable ( self , observable ) : <EOL> """<STR_LIT>""" <EOL> if not self . observables : <EOL> self . observables = Observables ( observables = observable ) <EOL> else : <EOL> self . observables . add ( observable ) <EOL> @ property <EOL> def incidents ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _incidents <EOL> @ incidents . setter <EOL> def incidents ( self , value ) : <EOL> self . _incidents = Incidents ( value ) <EOL> def add_incident ( self , incident ) : <EOL> """<STR_LIT>""" <EOL> self . incidents . append ( incident ) <EOL> @ property <EOL> def threat_actors ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _threat_actors <EOL> @ threat_actors . setter <EOL> def threat_actors ( self , value ) : <EOL> self . _threat_actors = ThreatActors ( value ) <EOL> def add_threat_actor ( self , threat_actor ) : <EOL> """<STR_LIT>""" <EOL> self . _threat_actors . append ( threat_actor ) <EOL> @ property <EOL> def courses_of_action ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _courses_of_action <EOL> @ courses_of_action . setter <EOL> def courses_of_action ( self , value ) : <EOL> self . _courses_of_action = CoursesOfAction ( value ) <EOL> def add_course_of_action ( self , course_of_action ) : <EOL> """<STR_LIT>""" <EOL> self . _courses_of_action . append ( course_of_action ) <EOL> @ property <EOL> def exploit_targets ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _exploit_targets <EOL> @ exploit_targets . setter <EOL> def exploit_targets ( self , value ) : <EOL> self . _exploit_targets = ExploitTargets ( value ) <EOL> def add_exploit_target ( self , exploit_target ) : <EOL> """<STR_LIT>""" <EOL> self . _exploit_targets . append ( exploit_target ) <EOL> @ property <EOL> def ttps ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _ttps <EOL> @ ttps . setter <EOL> def ttps ( self , value ) : <EOL> if isinstance ( value , TTPs ) : <EOL> self . _ttps = value <EOL> else : <EOL> self . _ttps = TTPs ( value ) <EOL> def add_ttp ( self , ttp ) : <EOL> """<STR_LIT>""" <EOL> self . ttps . append ( ttp ) <EOL> @ property <EOL> def reports ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _reports <EOL> @ reports . setter <EOL> def reports ( self , value ) : <EOL> self . _reports = Reports ( value ) <EOL> def add_report ( self , report ) : <EOL> """<STR_LIT>""" <EOL> self . reports . append ( report ) <EOL> @ property <EOL> def related_packages ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _related_packages <EOL> @ related_packages . setter <EOL> def related_packages ( self , value ) : <EOL> if isinstance ( value , RelatedPackages ) : <EOL> self . _related_packages = value <EOL> else : <EOL> self . _related_packages = RelatedPackages ( value ) <EOL> def add_related_package ( self , related_package ) : <EOL> """<STR_LIT>""" <EOL> self . related_packages . append ( related_package ) <EOL> def add ( self , entity ) : <EOL> """<STR_LIT>""" <EOL> if utils . is_cybox ( entity ) : <EOL> self . add_observable ( entity ) <EOL> return <EOL> tlo_adds = { <EOL> Campaign : self . add_campaign , <EOL> CourseOfAction : self . add_course_of_action , <EOL> ExploitTarget : self . add_exploit_target , <EOL> Incident : self . add_incident , <EOL> Indicator : self . add_indicator , <EOL> ThreatActor : self . add_threat_actor , <EOL> TTP : self . add_threat_actor , <EOL> Report : self . add_report , <EOL> Observable : self . add_observable , <EOL> } <EOL> try : <EOL> add = tlo_adds [ entity . __class__ ] <EOL> add ( entity ) <EOL> except KeyError : <EOL> error = "<STR_LIT>" <EOL> error = error . format ( type ( entity ) ) <EOL> raise TypeError ( error ) <EOL> def to_obj ( self , return_obj = None , ns_info = None ) : <EOL> super ( STIXPackage , self ) . to_obj ( return_obj = return_obj , ns_info = ns_info ) <EOL> if not return_obj : <EOL> return_obj = self . _binding_class ( ) <EOL> return_obj . id = self . id_ <EOL> return_obj . idref = self . idref <EOL> return_obj . version = STIXPackage . _version <EOL> return_obj . timestamp = utils . dates . serialize_value ( self . timestamp ) <EOL> if self . stix_header : <EOL> return_obj . STIX_Header = self . stix_header . to_obj ( ns_info = ns_info ) <EOL> if self . campaigns : <EOL> return_obj . Campaigns = self . campaigns . to_obj ( ns_info = ns_info ) <EOL> if self . courses_of_action : <EOL> return_obj . Courses_Of_Action = self . courses_of_action . to_obj ( ns_info = ns_info ) <EOL> if self . exploit_targets : <EOL> return_obj . Exploit_Targets = self . exploit_targets . to_obj ( ns_info = ns_info ) <EOL> if self . indicators : <EOL> return_obj . Indicators = self . indicators . to_obj ( ns_info = ns_info ) <EOL> if self . observables : <EOL> return_obj . Observables = self . observables . to_obj ( ns_info = ns_info ) <EOL> if self . incidents : <EOL> return_obj . Incidents = self . incidents . to_obj ( ns_info = ns_info ) <EOL> if self . threat_actors : <EOL> return_obj . Threat_Actors = self . threat_actors . to_obj ( ns_info = ns_info ) <EOL> if self . ttps : <EOL> return_obj . TTPs = self . ttps . to_obj ( ns_info = ns_info ) <EOL> if self . related_packages : <EOL> return_obj . Related_Packages = self . related_packages . to_obj ( ns_info = ns_info ) <EOL> if self . reports : <EOL> return_obj . Reports = self . reports . to_obj ( ns_info = ns_info ) <EOL> return return_obj <EOL> def to_dict ( self ) : <EOL> d = utils . to_dict ( self ) <EOL> if '<STR_LIT:version>' in d : <EOL> d [ '<STR_LIT:version>' ] = STIXPackage . _version <EOL> return d <EOL> @ classmethod <EOL> def from_obj ( cls , obj , return_obj = None ) : <EOL> if not return_obj : <EOL> return_obj = cls ( ) <EOL> return_obj . id_ = obj . id <EOL> return_obj . idref = obj . idref <EOL> return_obj . timestamp = obj . timestamp <EOL> return_obj . stix_header = STIXHeader . from_obj ( obj . STIX_Header ) <EOL> return_obj . campaigns = Campaigns . from_obj ( obj . Campaigns ) <EOL> return_obj . courses_of_action = CoursesOfAction . from_obj ( obj . Courses_Of_Action ) <EOL> return_obj . exploit_targets = ExploitTargets . from_obj ( obj . Exploit_Targets ) <EOL> return_obj . indicators = Indicators . from_obj ( obj . Indicators ) <EOL> return_obj . observables = Observables . from_obj ( obj . Observables ) <EOL> return_obj . incidents = Incidents . from_obj ( obj . Incidents ) <EOL> return_obj . threat_actors = ThreatActors . from_obj ( obj . Threat_Actors ) <EOL> return_obj . ttps = TTPs . from_obj ( obj . TTPs ) <EOL> return_obj . related_packages = RelatedPackages . from_obj ( obj . Related_Packages ) <EOL> return_obj . reports = Reports . from_obj ( obj . Reports ) <EOL> if obj . version : <EOL> return_obj . _version = obj . version <EOL> return return_obj <EOL> @ classmethod <EOL> def from_dict ( cls , dict_repr , return_obj = None ) : <EOL> if not return_obj : <EOL> return_obj = cls ( ) <EOL> get = dict_repr . get <EOL> return_obj . id_ = get ( '<STR_LIT:id>' ) <EOL> return_obj . idref = get ( '<STR_LIT>' ) <EOL> return_obj . timestamp = get ( '<STR_LIT>' ) <EOL> return_obj . _version = get ( '<STR_LIT:version>' , cls . _version ) <EOL> return_obj . stix_header = STIXHeader . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . campaigns = Campaigns . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . courses_of_action = CoursesOfAction . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . exploit_targets = ExploitTargets . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . indicators = Indicators . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . observables = Observables . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . incidents = Incidents . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . threat_actors = ThreatActors . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . ttps = TTPs . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . related_packages = RelatedPackages . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return_obj . reports = Reports . from_dict ( get ( '<STR_LIT>' ) ) <EOL> return return_obj <EOL> @ classmethod <EOL> def from_xml ( cls , xml_file , encoding = None ) : <EOL> """<STR_LIT>""" <EOL> entity_parser = parser . EntityParser ( ) <EOL> return entity_parser . parse_xml ( xml_file , encoding = encoding ) </s>
