Beispiel #1
0
    def create_aut_env(self):  # Spaeter on Button Click z.B.
        ''' this method creates the simulation'''               
        
        api_log_path = os.path.join(os.path.dirname(__file__), "../logs/api.log")
        api.show_logging(logging.INFO, api_log_path, True)
        my_env = api.create_environment(2500)
        
        ecu_spec = SimpleECUSpec([], 200, 200)
        ecu_group_1 = api.set_ecus(my_env, 10, 'SecureECU', ecu_spec)
        
        ecu_spec = SimpleECUSpec(['SEC 1'], 200, 200)
        ecu_spec.set_ecu_setting('t_ecu_auth_trigger_process', 100)
        ecu_spec.set_ecu_setting('t_ecu_auth_trigger_intervall', 1000)
        
        sec_mod_group = api.set_ecus(my_env, 1, 'SecLwAuthSecurityModule', ecu_spec)
        
        bus_spec = SimpleBusSpec(['CAN_0'])
        bus_group = api.set_busses(my_env, 1, 'StdCANBus', bus_spec)
        api.connect_bus_by_obj(my_env, 'CAN_0', ecu_group_1 + sec_mod_group)
        
        api.register_ecu_groups_to_secmod(my_env, sec_mod_group[0].ecu_id, [ecu_group_1])
        
        certeros = api.create_cert_manager()
        for ecu in APICore()._ecu_list_from_groups([[ecu_group_1]]):  # UNINTENDED HACK
            api.generate_valid_ecu_cert_cfg(certeros, ecu.ecu_id, CAEnum.CA_L313, 'SEC 1', 0, float('inf'))
        api.generate_valid_sec_mod_cert_cfg(certeros, 'SEC 1', CAEnum.CA_L313, 0, float('inf'))
        api.apply_certification(my_env, certeros)
        
        
        stream_1 = MessageStream(my_env.get_env(), 'SecureECU_0', ['SecureECU_1', 'SecureECU_4', 'SecureECU_5'], 13, float('inf'), 0, float('inf'))
        stream_2 = MessageStream(my_env.get_env(), 'SecureECU_1', ['SecureECU_3', 'SecureECU_2', 'SecureECU_5'], 12, float('inf'), 0, float('inf'))
        stream_3 = MessageStream(my_env.get_env(), 'SecureECU_0', ['SecureECU_4', 'SecureECU_1', 'SecureECU_5'], 222, float('inf'), 0, float('inf'))
        stream_4 = MessageStream(my_env.get_env(), 'SecureECU_3', ['SecureECU_0', 'SecureECU_1', 'SecureECU_5'], 11, float('inf'), 0, float('inf'))
        stream_5 = MessageStream(my_env.get_env(), 'SecureECU_4', ['SecureECU_2', 'SecureECU_1', 'SecureECU_3'], 500, float('inf'), 0, float('inf'))
        api.add_allowed_stream(my_env, 'SEC 1', stream_1)
        api.add_allowed_stream(my_env, 'SEC 1', stream_2)
        api.add_allowed_stream(my_env, 'SEC 1', stream_3)
        api.add_allowed_stream(my_env, 'SEC 1', stream_4)
        api.add_allowed_stream(my_env, 'SEC 1', stream_5)
        
        t_set = TimingFunctionSet()
        ecu_func_set = StdSecurLwSecModTimingFunctions(main_library_tag='CyaSSL')
        t_set.set_mapping_from_function_set('SEC 1', ecu_func_set)
        api.apply_timing_functions_set(my_env, 'SEC 1', t_set)
          
        t_set2 = TimingFunctionSet() 
        ecu_func_set = StdSecurECUTimingFunctions(main_library_tag='CyaSSL')
        
        for ecu in APICore()._ecu_list_from_groups([[ecu_group_1]]):  # UNINTENDED HACK
            t_set2.set_mapping_from_function_set(ecu.ecu_id, ecu_func_set) 
            api.apply_timing_functions_set(my_env, ecu.ecu_id, t_set2)

        api.connect_monitor(my_env, self.monitor, 50)
        api.build_simulation(my_env)
        
        ''' start this in a new thread'''
        sim = SimulationThread(self, my_env)
        sim.start()
Beispiel #2
0
 def push_constellation(self, ecu_groups, busses, bus_connections):
     ''' this method receives the initial constellation of the 
         environment and publishes it to the handlers 
     
         Input:  ecu_groups        list        list of lists: [[ecu_list, ecu_spec],[ecu_list, ecu_spec],...]
                 busses            list        list of lists: [[bus_list, ecu_spec],[bus_list, ecu_spec],...]
                 bus_connections   list        list of lists [[bus_id, ecu_id], [bus_id, ecu_id],...]
         Output: -
     '''        
     # set eventline handlers
     for ecu in ecu_groups: 
         try:
             General().register_eventline_tags(ecu[0][0].ecuSW.comm_mod._tags)
         except:
             pass
     
     # push the constellation
     push_list = [MonitorInput([ecu_groups, busses, bus_connections], MonitorTags.CONSELLATION_INFORMATION, \
                         None, 0, None, None, None, None, None, None)]
     self._input_handler.publish(push_list, RefList())        
         
     # push initial ecu ids
     
     push_list = MonitorInput(APICore()._ecu_list_from_groups(ecu_groups), MonitorTags.ECU_ID_LIST, \
                         None, 0, None, None, None, None, None, None)
     self._input_handler.publish(push_list, RefList())   
Beispiel #3
0
def create_environment(app_lifetime):
    ''' create the automotive environment specification
        that is used to generate a valid environment
        
        Input:  app_lifetime:       float
        Output: -        
    '''
    return APICore().create_environment(app_lifetime)
Beispiel #4
0
def register_bus_classes(class_path):
    ''' all AbstractBus classes that are present in the folder
        class_path will be createable within the environment
            
        Input:  class_path:      string
        Output: -     
    '''
    APICore().register_bus_classes(class_path)
Beispiel #5
0
def apply_certification(env, cert_mgr):
    ''' applies the certification specified in the 
        certificate manager object to the environment 
        
        Input:  env:                 AutomotiveEnvironmentSpec:     specification of the Environment
                cert_manager:        CertificateManager:            entity that holds the certificates for all parties
        Output: -
        '''
    APICore().apply_certification(env, cert_mgr)
Beispiel #6
0
def save_env_spec(env, filepath):
    ''' saves the environment to a file. Currently not 
        working
        
        Input:  env:                 AutomotiveEnvironmentSpec:     specification of the Environment
                filepath:            string:                        path to the file to be saved
        Output: -
    '''
    APICore().save_env_spec(env, filepath)
Beispiel #7
0
    def update_gui(self, monitor_input_list):

        
        # receive the ecu ids: show only the once selected then
        try: 
            if isinstance(monitor_input_list[0], str): return
            
            constellation = monitor_input_list[0].data
            ecu_groups = constellation[0]
            self._ecu_ids = [e.ecu_id for e in APICore()._ecu_list_from_groups(ecu_groups)]
            
            self._add_items_ecu_ids(self._ecu_ids)   
            return         
        except: 
            pass
        try:
            monitor_input_list.sort(key=lambda x: x[0], reverse=False)
        except:
            pass
            
        # receive simple inputs
        for monitor_input in monitor_input_list:
#             if self._already_there(monitor_input): continue

            # read information
            ecu_id = monitor_input[1]
            tag = eval(monitor_input[3])            
            message_id = monitor_input[4]
            stream_id = message_id  # monitor_input[7]
            
            if stream_id in [-1, 0]: 
                continue      
            
            
            if tag in self._sent_tags: 
                add_tag = 'sender'
            elif tag in self._received_tags: 
                add_tag = 'receiver'
            else: 
                continue
            
            if not General().four_dict_exists(self._bin, ecu_id, stream_id, add_tag):
                General().add_to_four_dict(self._bin, ecu_id, stream_id, add_tag, 1)
            else:
                self._bin[ecu_id][stream_id][add_tag] += 1
                
                
            # workaround tesla
            if tag == MonitorTags.CP_SEND_SYNC_RESPONSE_MESSAGE:
                if not General().four_dict_exists(self._bin, ecu_id, can_registration.CAN_TESLA_TIME_SYNC, "receiver"):
                    General().add_to_four_dict(self._bin, ecu_id, can_registration.CAN_TESLA_TIME_SYNC, "receiver", 1)
                else:
                    self._bin[ecu_id][can_registration.CAN_TESLA_TIME_SYNC]["receiver"] += 1
            
            
        # show updated
        self._plot_bin()
Beispiel #8
0
def ecu_list_from_groups(ecu_groups):
    ''' returns all AbstractECU objects that are specified in the 
        ecu_groups as list
    
        Input:  ecu_groups:         list                [ ecu_group_1, ecu_group_2,...]  with ecu_group_i = [ecu_list_1, ecu_list_2,...], 
                                                                                        with ecu_list_i = [abstract_ecu_1, abstract_ecu_2,...]     
        Output: ecu_list            list                list of AbstractECUs
    '''    
    return APICore().ecu_list_from_groups(ecu_groups)
Beispiel #9
0
def run_simulation(env):
    ''' this method starts the actual environment by first creating a 
        simulation parameter and then starting the environment from 
        that created parameter

        Input:  env:           AutomotiveEnvironmentSpec:     specification of the Environment
        Output: - 
    '''
    return APICore().run_simulation(env)
Beispiel #10
0
def create_cert_manager(ca_hierarchy=CAHierarchy()):
    ''' 
        creates a certificate manager object from 
        a CAHierarchy object 
        
        Input:  ca_hierarchy:                  CAHierarchy:            Hierarchy of Certification Authorities
        Output: cert_manage                    CertificateManager      entity that holds the certificates for all parties
    '''  
    return APICore().cert_manager(ca_hierarchy)
Beispiel #11
0
def open_simulation_stop_button(env):
    ''' starts a seperate thread that opens a stop button that 
        can be used to interrupt the simulation without closing the GUI
        and finishing the automotive Environment and simpy Process
        
        Input:    env:            AutomotiveEnvironmentSpec: specification of the Environment
        Output:     -
            '''
    APICore().open_simulation_stop_button(env)
Beispiel #12
0
def set_stream(env, new_stream):
    ''' sets streams for the TLS implementation specifying the receivers for 
        a message with a certain message id
        
        Input:  env:                   AutomotiveEnvironmentSpec: specification of the Environment
                new_stream:            MessageStream
        Output: -
    '''
    APICore().set_stream(env, new_stream)
Beispiel #13
0
def build_simulation(env):
    ''' 
        all specification that has been passed to the
        AutomotiveEnvironmentSpec object env will be build 
        in this stage
        
        Input:  env:                 AutomotiveEnvironmentSpec:     specification of the Environment
        Output: -
    '''    
    APICore().build_sim_param(env)
Beispiel #14
0
def load_env_spec(filepath):
    ''' loads the environment that was created from 
        a file. Currently not working
        
        Input:  filepath:                  string                         path to the file to be loaded
        Output: my_env:                    AutomotiveEnvironmentSpec:     specification of the Environment 
    ''' 
    return APICore().load_env_spec(filepath)

    
Beispiel #15
0
def autoset_gateway_filters(env, sec_id):
    ''' depending on the allowed streams this method
        sets a filter to each gateway, so that only 
        allowed streams defined in the ecu with sec_id 
        are forwarded
        Input:  env:                   AutomotiveEnvironmentSpec:  specification of the Environment
                sec_id:                string:                     Id of security module
        Output: -
    '''
    APICore().autoset_gateway_filters(env, sec_id)
Beispiel #16
0
def apply_timing_functions_set(env, comp_id, timing_function_set):
    ''' Applies a set of timing variables to the environment and the 
        component with id comp_id
        
        Input:  env:                 AutomotiveEnvironmentSpec:      specification of the Environment
                comp_id:             string:                         id of the component
                timing_function_set: TimingFunctionSet:              Set of associations between timing variables and methods
        Output: -
        '''
    APICore().apply_timing_functions_set(env, comp_id, timing_function_set)
Beispiel #17
0
def add_allowed_stream(env, sec_mod_id, new_stream):
    ''' adds defined streams to the environment
        1. sets sterams in security module
        2. sets hw filter with allowed streams in each ecu transceiver
    
        Input:  env:                 AutomotiveEnvironmentSpec:     specification of the Environment
                sec_mod_id:          string:                        id of security module
                new_stream:          MessageStream                  Stream that is allowed in this environment
        Output: -
    '''
    APICore().add_allowed_stream(env, sec_mod_id, new_stream)
Beispiel #18
0
def register_ecu_groups_to_secmod(env, sec_mod_id, ecu_groups):
    ''' in order for the security module to know about the ecus existence
        it is necessary to connect the ECU to the security module 
        
        Input:  env:               AutomotiveEnvironmentSpec:            specification of the Environment
                sec_mod_id:        string                                id of the security module
                ecu_groups:        list                                  list of ecu object lists: [[ecu_obj_1, ecu_obj_2, ...], [ecu_obj_12, ecu_obj_13, ...], ...]
        
        Output: -
    '''
    APICore().register_ecu_groups_to_secmod(env, sec_mod_id, ecu_groups)
Beispiel #19
0
    def update_gui(self, monitor_input_list):

        
        # receive the ecu ids
        try: 
            if isinstance(monitor_input_list[0], str): return
            
            constellation = monitor_input_list[0].data
            ecu_groups = constellation[0]
            ecu_ids = [e.ecu_id for e in APICore()._ecu_list_from_groups(ecu_groups)]
            self._add_items_ecu_ids(ecu_ids)   
            return         
        except: 
            pass
        
        monitor_input_list.sort(key=lambda x: x[0], reverse=False)

        # receive simple inputs
        for monitor_input in monitor_input_list:
            # read information
            time = monitor_input[0]
            ecu_id = monitor_input[1]
            associated_id = monitor_input[2]
            tag = eval(monitor_input[3])
            message_id = monitor_input[4]
            message = monitor_input[5]
            message_size = monitor_input[6]
            stream_id = monitor_input[7]
            unique_id = monitor_input[8]
            input_data = monitor_input[9]
            description = self._external_core.cp_string(tag, associated_id, stream_id, message)
            
            # get textedit
            text_edit = self.widget_text[ecu_id]
#             current_text = text_edit.toPlainText()
            
            # create new text
            part_append = ""
                        
            if self._information_checked['Time']: part_append += "\n\nTime: \t%s" % time
            if self._information_checked['Associated Id']: part_append += "\nAssociated Id: \t%s" % associated_id
            if self._information_checked['Monitor Tag']: part_append += "\nMonitor Tag: \t%s" % tag
            if self._information_checked['Message Id']: part_append += "\nMessage Id: \t%s" % message_id
            if self._information_checked['Message']: part_append += "\nMessage: \t%s" % message
            if self._information_checked['Size']: part_append += "\nSize: \t%s" % message_size
            if self._information_checked['Stream Id']: part_append += "\nStream Id: \t%s" % stream_id
            if self._information_checked['Monitor Data']: part_append += "\nMonitor Data: \t%s" % input_data
            if self._information_checked['Description']: part_append += "\nDescription: \t%s" % description

            # add new part
            text_edit.append(part_append)
#             current_text += part_append
#             text_edit.setText(current_text)
            text_edit.verticalScrollBar().setValue(text_edit.verticalScrollBar().maximum());
Beispiel #20
0
def set_ecus(env, nr_elements, ecu_type_id, ecu_spec):
    ''' adds a certain number of ecus of a certain type with settings 
        defined in ecu_spec to the environment. 
        
        Input:  env:                 AutomotiveEnvironmentSpec:         specification of the Environment
                nr_elements:         int                                number of ECUs to be added
                ecu_type_id          string                             class name of the AbstractECU to be created as string
                ecu_spec             AbstractECUSpec                    AbstractECUSpec that specifies the settings for this group of ECUs
        Output: ecu_group            List of AbstractECU objects        instances of created ECUs
    '''
    return APICore().set_ecus(env, nr_elements, ecu_type_id, ecu_spec)    
Beispiel #21
0
def connect_result_reader(env, my_moni, reader):
    ''' in order to be able to read out results from the simulation 
        an instance of ResultReader has to be created and connected to
        the monitor    
        
        Input:  env:               AutomotiveEnvironmentSpec:          specification of the Environment
                monitor:           Monitor                             monitor object that obtains information from environment
                reader:            ResultReader                        result reader that will get the monitor values relevant for him forwarded
        Output: -     
    '''
    APICore().connect_result_reader(env, my_moni, reader)
Beispiel #22
0
def connect_bus_by_obj(env, bus_id, lst_add_obj):
    ''' 
        adds all ECU objects in lst_add_obj to
        the elements that will be connected to the 
        Bus with Bus ID bus_id    
        
        Input:  env:               AutomotiveEnvironmentSpec:         specification of the Environment
                bus_id:            string                             id of the bus to be connected
                new_obj_list:      list of AbstractECU objects        list of AbstractECU objects
        Output: -
    '''   
    APICore().connect_bus_obj(env, bus_id, lst_add_obj)    
Beispiel #23
0
def connect_bus_by_id(env, bus_id, lst_add_ids):
    ''' 
        adds all ECUs with ids in lst_add_ids to
        the elements that will be connected to the 
        Bus with Bus ID bus_id    
        
        Input:  env:               AutomotiveEnvironmentSpec:          specification of the Environment
                bus_id:            string:                             id of the bus to be connected
                lst_add_ids:       list of strings                     list of ids of AbstractECU instances that will be connected to the bus
        Output: -
    '''  
    APICore().connect_bus(env, bus_id, lst_add_ids)    
Beispiel #24
0
def generate_valid_sec_mod_cert_cfg(cert_mgr, sec_mod_id, ca_id, ecu_id_list, valid_from, valid_till):
    '''all ECUs that are given in the ecu_id_list will get a valid list of root certificates
        to be able to verify the Security modules authenticity
        
        Input:  cert_manager:      CertificateManager        entity that holds the certificates for all parties
                ca_id:             string/CAEnum             Id of the Certification Authority that authorizes this certificate
                sec_mod_id:        string                    id of the security module
                ecu_id_list:       list of string            list of ecu ids 
                valid_from:        number                    certificate validity start time
                valid_till:        number                    certificate validity end time
        Output: -        
    '''
    return APICore().generate_valid_sec_mod_cert_cfg(cert_mgr, ca_id, sec_mod_id, ecu_id_list, valid_from, valid_till)
Beispiel #25
0
def connect_monitor(env, monitor, t_period):
    ''' connects a monitor to the environment. All ECUs and 
        Busses that are monitorable are then added to it. 
        All elements that have subscribed to the monitor will get the 
        information once in the time interval t_period. Then the monitor
        publishes all gathered information.
        
        Input:  env:                AutomotiveEnvironmentSpec:         specification of the Environment
                monitor:            Monitor                            monitor object that obtains information from environment
                t_period:           float                              sampling time in which the monitor will request information from the environment
        Output: -
    '''   
    APICore().connect_monitor(env, monitor, t_period)
Beispiel #26
0
def gateway_filter_sending_bus(gateway_group, can_dict):
    ''' Sets a fixed filter to the gateway. The can_dict contains
        CAN IDs as keys and a list of allowed message ids as values. 
        Thus all allowed messages will be forwarded and the remaining once
        will be blocked
        e.g. api.gateway_filter_sending_bus(gateway_group_1, {'CAN_0':[2,3,4], 'CAN_1':[2, 5,6,7]})  
             this filter would act as follows. If a message with either 2 arrives
             on any port of the gateway it will be forwarded to CAN_0 and CAN_1. If 3,4 arrives on 
             any port it will be forwarded to CAN_0 only. etc 
        Input:  gateway_group:   list of Gateway objects
                can_dict:        dictionary: key: can id value: list of message ids
        Output: -   
        '''
    APICore().gateway_filter_sending_bus(gateway_group, can_dict)
Beispiel #27
0
def generate_valid_ecu_cert_cfg(cert_mgr, ecu_id, ca_id, sec_mod_id, valid_from, valid_till):
    ''' the security module with id sec_mod_id gets a valid root certificate list 
        for the ECU with id ecu_id
        So the Security Module can verify the ECU's authenticity
        
        Input:  cert_manager:      CertificateManager      entity that holds the certificates for all parties
                ecu_id:            string
                ca_id:             string/CAEnum
                sec_mod_id:        string
                valid_from:        number
                valid_till:        number
        Output: -        
    '''
    return APICore().generate_valid_ecu_cert_cfg(cert_mgr, ecu_id, ca_id, sec_mod_id, valid_from, valid_till)
Beispiel #28
0
def set_busses(env, nr_elements, bus_type_id, bus_spec):
    ''' given the bus_type that has to be generated and the bus_spec
        object that is necessary to create the object this method sets
        number nr_elements Busses of that type into the environment
            
        Input:  env:                AutomotiveEnvironmentSpec
                nr_elements:        int
                bus_type_id:        string
                bus_spec:           BusSpec (depending on the generated bus)
        
        Output: list of AbstractBus Objects
    
    '''
    
    return APICore().set_busses(env, nr_elements, bus_type_id, bus_spec)
Beispiel #29
0
def gateway_filter_bus(gateway_group, can_dict):
    ''' Sets a fixed filter to the gateway. The can_dict contains
        CAN IDs as keys and a list of allowed message ids as values. 
        Thus all allowed messages will be forwarded and the remaining once
        will be blocked
        e.g. api.gateway_filter_bus(gateway_group_1, {'CAN_0':[2,3,4], 'CAN_1':[5,6,7]})  
             this filter would act as follows. If a message with either 2,3,4 arrives
             through CAN_0 to the gateway it will be forwarded. Any other message arriving
             on that bus will be discarded. Analogously messages 5,6,7 arriving over CAN_1
             will be forwarded and others not
        Input:  gateway_group:   list of Gateway objects
                can_dict:        dictionary: key: can id value: list of message ids
        Output: -   
    '''
    APICore().gateway_filter_bus(gateway_group, can_dict)
Beispiel #30
0
    def _extract_settings(self, component):

        settings_dict = {}

        settings_dict['comp_id'] = str(APICore()._id_from_component(component))

        try:
            settings_dict['jitter'] = str(component._jitter)
        except:
            pass

        try:
            settings_dict['set authenticated'] = str(component._authenticated)
        except:
            pass

        try:
            settings_dict['buffer size: receive '] = str(
                component.ecuHW.controller.max_receive_size)
        except:
            pass

        try:
            settings_dict['buffer size: transmit'] = str(
                component.ecuHW.controller.max_transmit_size)
        except:
            pass

        try:
            settings_dict['HW: transceiver'] = str(
                component.ecuHW.transceiver.__class__.__name__)
        except:
            pass

        try:
            settings_dict['HW: controller'] = str(
                component.ecuHW.controller.__class__.__name__)
        except:
            pass

        try:
            settings_dict['HW: microcontroller'] = str(
                component.ecuHW.mic_controller.__class__.__name__)
        except:
            pass

        try:
            settings_dict['layer: communication module'] = str(
                component.ecuSW.comm_mod.__class__.__name__)
        except:
            pass

        try:
            settings_dict['layer: application'] = str(
                component.ecuSW.app_lay.__class__.__name__)
        except:
            pass

        try:
            settings_dict['layer: transport'] = str(
                component.ecuSW.comm_mod.transp_lay.__class__.__name__)
        except:
            pass

        try:
            settings_dict['layer: data link'] = str(
                component.ecuSW.comm_mod.datalink_lay.__class__.__name__)
        except:
            pass

        try:
            settings_dict['layer: physical'] = str(
                component.ecuSW.comm_mod.physical_lay.__class__.__name__)
        except:
            pass

        for set_key in component.settings:
            set_value = APICore()._get_setting_val(component, set_key)
            settings_dict[set_key] = str(set_value)

        return settings_dict