def c_t_tls_hand_dec_client_keyex_msg(self, pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option): ''' time to decrypt the inner registration message -> So this is a private decryption with the sec module private key (after this was public encrypted) ''' try: # extract infos L().log(701, pub_dec_alg, pub_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(pub_dec_alg) al_mode = EnumTrafor().to_value(pub_dec_alg_option) key_len = EnumTrafor().to_value(pub_dec_keylen) # DB Lookup if pub_dec_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_dec_client_keyex_msg'], mode='DECRYPTION', \ param_len=key_len, alg=algorithm, data_size=size_to_dec, description='t_tls_hand_dec_client_keyex_msg') else: db_val = TimingDBMap().lookup_interpol(exp=al_mode, lib=self.library_tags['t_tls_hand_dec_client_keyex_msg'], mode='DECRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_tls_hand_dec_client_keyex_msg') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_dec_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_dec_client_keyex_msg'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option])) L().log(603, 't_tls_hand_dec_client_keyex_msg') return 0.01 # self.settings['t_tls_hand_dec_client_keyex_msg'] = 'ecuSW.app_lay.ecu_auth.SSMA_DECR_INNER_REG_MSG' except: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_dec_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_dec_client_keyex_msg'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option])) return 0.000000001
def c_t_ecu_auth_conf_msg_enc(self, size_to_enc, sym_enc_alg, sym_enc_keylen, sym_enc_alg_mode): ''' time to encrypt the conf. msg with the ecu key''' try: # extract infos L().log(703, sym_enc_alg, sym_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(sym_enc_alg) algo_mode = EnumTrafor().to_value(sym_enc_alg_mode) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=algo_mode, lib=self.library_tags['t_ecu_auth_conf_msg_enc'], mode='ENCRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_ecu_auth_conf_msg_enc') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_conf_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_conf_msg_enc'], size_to_enc, sym_enc_alg, sym_enc_keylen, sym_enc_alg_mode ])) L().log(603, 't_ecu_auth_conf_msg_enc') return 0.01 # self.settings['t_ecu_auth_reg_msg_outter_dec'] = 'ecuSW.app_lay.ecu_auth.SSMA_DECR_OUTTER_REG_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_conf_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_conf_msg_enc'], size_to_enc, sym_enc_alg, sym_enc_keylen, sym_enc_alg_mode ])) return 0.000000001
def c_t_str_auth_enc_grant_msg(self, sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode): ''' time to encrypt the grant message''' try: # extract infos L().log(706, sym_enc_alg, sym_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(sym_enc_alg) algo_mode = EnumTrafor().to_value(sym_enc_alg_mode) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=algo_mode, lib=self.library_tags['t_str_auth_enc_grant_msg'], mode='ENCRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_str_auth_enc_grant_msg') # return values if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_enc_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_enc_grant_msg'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) L().log(603, 't_str_auth_enc_grant_msg') return 0.01 # self.settings['t_str_auth_enc_grant_msg'] = 'ecuSW.app_lay.stream_auth.SSMA_STREAM_ENC_GRANT_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_enc_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_enc_grant_msg'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) return 0.000000001
def c_t_tls_hand_enc_cert_verify_msg(self, enc_alg, enc_key_len, msg_size, alg_option): # Public encrypt try: # extract information L().log(604, enc_alg, enc_key_len, msg_size) algorithm = EnumTrafor().to_value(enc_alg) key_len = EnumTrafor().to_value(enc_key_len) # read Database if enc_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_cert_verify_msg'], mode='ENCRYPTION', param_len=key_len, alg=algorithm, \ data_size=msg_size, description='t_tls_hand_enc_cert_verify_msg') else: # RSA: have to slice the message and encrypt each of those if msg_size > ((float(key_len) / 8) - 11): size_to_enc_in = ceil((float(key_len) / 8) - 11) else: size_to_enc_in = msg_size db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_cert_verify_msg'], exp=alg_option, mode='ENCRYPTION', keylen=key_len, \ alg=algorithm, data_size=size_to_enc_in, description='t_tls_hand_enc_cert_verify_msg') # RSA: have to slice the message and encrypt each of those nr_chuncks = math.ceil(msg_size / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_hand_enc_cert_verify_msg') return 0.001 except: logging.error("Error: Could not calculate the Value in 't_tls_hand_enc_cert_verify_msg'") return 0.000000001
def c_t_reg_msg_hash(self, size_to_hash, hash_mech): try: # extract infos L().log(605, hash_mech, size_to_hash) algorithm = EnumTrafor().to_value(hash_mech) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_hash'], mode='HASH', alg=algorithm, data_size=size_to_hash, description='t_reg_msg_hash') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_hash' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_hash'], size_to_hash, hash_mech ])) L().log(603, 't_reg_msg_hash') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_hash' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_hash'], size_to_hash, hash_mech ])) return 0.000000001
def c_t_generate_mac(self, input_size, mac_alg, mac_keylen): ''' generation of the comparison hash is a AES CMAC operation''' try: # extract infos L().log(605, mac_alg, input_size) algorithm = EnumTrafor().to_value(mac_alg) key_len = EnumTrafor().to_value(mac_keylen) alg_mode = "CMAC" # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_generate_compare_mac'], keylen=key_len, mode='ENCRYPTION', alg=algorithm, alg_mode=alg_mode, data_size=input_size) # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_generate_mac') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.error( "Error: Could not calculate the Value in 't_generate_mac'") return 0.000000001 return 0
def c_t_key_exchange_decryption(self, msg_size, dec_alg, dec_key_len, alg_option): ''' Private decryption or alternatively symmetric encryption with master key''' try: # extract information L().log(604, dec_alg, dec_key_len, msg_size) algorithm = EnumTrafor().to_value(dec_alg) key_len = EnumTrafor().to_value(dec_key_len) alg_mode = EnumTrafor().to_value(alg_option) # Symmertic Encryption if isinstance(dec_alg, SymAuthMechEnum): db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_key_exchange_encryption'], mode='DECRYPTION', keylen=key_len, alg=algorithm, alg_mode=alg_mode, data_size=msg_size) else: # read Database if dec_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_key_exchange_decryption'], mode='DECRYPTION', param_len=key_len, alg=algorithm, data_size=msg_size) else: # RSA: have to slice the message and encrypt each of those if msg_size > ((float(key_len) / 8) - 11): size_to_enc_in = ceil((float(key_len) / 8) - 11) else: size_to_enc_in = msg_size db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_key_exchange_decryption'], exp=alg_option, mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_enc_in) # RSA: have to slice the message and encrypt each of those nr_chuncks = math.ceil(msg_size / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_key_exchange_decryption') return 0.001 except: logging.error( "Error: Could not calculate the Value in 't_key_exchange_decryption'" ) return 0.000000001
def c_t_ecu_auth_reg_msg_outter_dec(self, pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option): ''' time to decrypt the outter registration message -> Verify == Public Decrypt! ''' try: # extract infos L().log(702, pub_dec_alg, pub_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(pub_dec_alg) alg_opt = EnumTrafor().to_value(pub_dec_alg_option) key_len = EnumTrafor().to_value(pub_dec_keylen) # DB Lookup if pub_dec_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_outter_dec'], mode='VERIFY', param_len=key_len, \ alg=algorithm, data_size=size_to_dec, description='t_ecu_auth_reg_msg_outter_dec') if pub_dec_alg == AsymAuthMechEnum.RSA and self.library_tags[ 't_ecu_auth_reg_msg_outter_dec'] == "CyaSSL": if size_to_dec > ((float(key_len) / 8) - 11): size_to_dec_in = ceil((float(key_len) / 8) - 11) else: size_to_dec_in = size_to_dec db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_outter_dec'], exp=alg_opt, mode='ENCRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_dec_in, description='t_ecu_auth_reg_msg_outter_dec') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(size_to_dec / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks if pub_dec_alg == AsymAuthMechEnum.RSA and self.library_tags[ 't_ecu_auth_reg_msg_outter_dec'] in [ "Crypto_Lib_SW", "Crypto_Lib_HW" ]: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_outter_dec'], exp=alg_opt, mode='VERIFY', \ keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_ecu_auth_reg_msg_outter_dec') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_outter_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_outter_dec'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option ])) L().log(603, 't_ecu_auth_reg_msg_outter_dec') return 0.01 # self.settings['t_ecu_auth_reg_msg_outter_dec'] = 'ecuSW.app_lay.ecu_auth.SSMA_DECR_OUTTER_REG_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_outter_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_outter_dec'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option ])) return 0.000000001
def asy_decrypt(cipher_text, asymmetric_key, now=float('-inf')): ''' this method decrypts the cipher text asymmetrically with the given key . It also checks if the key is valid in time if defined. Input: cipher_text EncryptedMessage object that was encrypted using the pendant of the given key asymmetric_key AsymetricKey key that is the pendant of the key that was used for encryption Output: clear_text object decrypted clear text (using the given key) ''' # same algorithms cond_1 = cipher_text.decryption_key_id == asymmetric_key.id cond_2 = cipher_text.decryption_alg == asymmetric_key.valid_alg cond_3 = cipher_text.decryption_key_len == asymmetric_key.valid_key_len cond_4 = True # cipher.decryption_alg_mode == key.valid_alg_mode # valid time if asymmetric_key.valid_till != None: cond_4 = now <= asymmetric_key.valid_till if not cond_4: L().log(803, now, asymmetric_key.valid_till) # conditions ok if (cond_1 and cond_2 and cond_3 and cond_4): return cipher_text.msg_unencrpyted # not able to decrypt else: return None
def _main_receive(self): ''' supposed to do nothing''' while True: ''' 1. receive Stuff via the connected transmission module, stuck until message received ''' [self.msg_id, self.msg_data] = yield self.sim_env.process(self.comm_mod.receive_msg()) if self.msg_id: L().log(400, self.sim_env.now, self._ecu_id, [self.msg_id, self.msg_data])
def to_t(self, sim_env, timeout_val, var_name, class_name, caller_id=None): ''' Logs a certain value to the debug output ''' L().log(2, var_name, class_name, timeout_val) return if caller_id != None: self.add_to_three_dict(self.used_timeouts, caller_id, str([class_name, var_name]), timeout_val)
def make(self, class_id, constructor_in): ''' given the constructor parameters for the class with class_id the class with the specified id will be created and returned Input: class_id string Identifier of the class to be generated constructor_in list list of constructor parameters for this specific class Output: instance object instance of the specified class ''' try: # extract class GeneratedClass = self.create_dict[class_id] # @UnusedVariable # create constructor input in_str = "" for i in range(len(constructor_in)): in_str += "constructor_in[" + str(i) + "], " in_str = in_str[:-2] # return instance return eval('GeneratedClass(' + in_str + ')') except: L().log_traceback() return G().val_log_info(None, 201, class_id)
def _main_send(self, sending_action): ''' after the sending actions have been sorted they are all started in an own process that times out for the defined interval and then sends the message Input: sending_action SendingAction current sending action Output: - ''' print("Sending stream %s" % sending_action.message_id) print("sending process for msg ID %s is running (time: %s)" % (sending_action.message_id, self.sim_env.now)) cnt = 0 while True: if self.message_number: if cnt == self.message_number: return cnt += 1 # Send message L().log(501, self.sim_env.now, self._ecu_id, sending_action.message_id, sending_action.data.get()) self.sim_env.process( self.comm_mod.send_msg(self._ecu_id, sending_action.message_id, sending_action.data)) # timeout fixed interval (use random value to avoid message loss due to parallel processes) yield self.sim_env.timeout(sending_action.interval * self._jitter * (1 + 0.000000000001 * random.random()))
def c_t_prf_for_key_legitimation(self, mac_alg, mac_keylen): ''' key generation with AES is a Random Function so same as a PRF''' try: # extract information algorithm = EnumTrafor().to_value(SymAuthMechEnum.AES) key_len = EnumTrafor().to_value(AuKeyLengthEnum.bit_192) # read Database db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_prf_for_key_legitimation'], mode='KEYGEN', keylen=key_len, alg=algorithm) # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_prf_for_key_legitimation') return 0.001 except: logging.error( "Error: Could not calculate the Value in 't_prf_for_key_legitimation'" ) return 0.000000001
def surround_cls(self, cls, func, arg, show): show = False try: exc_str = "cls.%s(arg)" % func exec(exc_str) except: if show: L().log_traceback()
def to(self, sim_env, timeout_val, var_name, class_name, caller_id=None): ''' Logs a certain value to the debug output while at the same time timing out for the duration of the variable value''' L().log(2, var_name, class_name, timeout_val) if caller_id != None: self.add_to_three_dict(self.used_timeouts, caller_id, str([class_name, var_name]), timeout_val) yield sim_env.timeout(timeout_val)
def output_size(self, input_size, algorithm, key_length, mode): ''' maps the size of an input before having used a certain encryption algorithm to the size after the encryption procedure using the defined algorithm and key_length Input: input_size float size of the text before encryption algorithm application algorithm AsymAuthMechEnum/SymAuthMechEnum algorithm of the encryption procedure key_length AuKeyLengthEnum key length used for the encryption procedures Output: output float size of the text after the MAC algorithm was applied ''' output = None if mode == 'HASH': if algorithm == HashMechEnum.MD5: output = self._md5_output(input_size) elif algorithm == HashMechEnum.SHA1: output = self._sha1_output(input_size) elif algorithm == HashMechEnum.SHA256: output = self._sha256_output(input_size) elif mode == 'SIGN': if algorithm == AsymAuthMechEnum.ECC: output = self._ecc_sign_output(input_size, key_length) elif algorithm == AsymAuthMechEnum.RSA: output = self._rsa_sign_output(input_size, key_length) elif mode == 'VERIFY': if algorithm == AsymAuthMechEnum.ECC: output = self._ecc_verify_output(input_size, key_length) elif algorithm == AsymAuthMechEnum.RSA: output = self._rsa_verify_output(input_size, key_length) elif mode == 'ENCRYPTION': if algorithm == AsymAuthMechEnum.ECC: output = self._ecc_enc_output(input_size, key_length) elif algorithm == AsymAuthMechEnum.RSA: output = self._rsa_enc_output(input_size, key_length) elif algorithm == SymAuthMechEnum.AES: output = self._aes_enc_output(input_size, key_length) elif mode == 'DECRYPTION': if algorithm == AsymAuthMechEnum.ECC: output = self._ecc_dec_output(input_size, key_length) elif algorithm == AsymAuthMechEnum.RSA: output = self._rsa_dec_output(input_size, key_length) elif algorithm == SymAuthMechEnum.AES: output = self._aes_dec_output(input_size, key_length) if output < 0: logging.warn("Error Output smaller than allowed %s, %s, %s, %s" % (input_size, algorithm, key_length, mode)) if output == None: L().log_warn(805) return input_size return output
def c_t_normal_msg_enc(self, sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode=False): ''' time to encrypt a normal message''' try: # extract infos L().log(607, 't_normal_msg_enc', sym_enc_alg, sym_enc_keylen, size_to_enc) algorithm_mode = EnumTrafor().to_value(sym_enc_alg_mode) algorithm = EnumTrafor().to_value(sym_enc_alg) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_normal_msg_enc'], alg_mode=algorithm_mode, mode='ENCRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_normal_msg_enc') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_normal_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_normal_msg_enc'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) L().log(603, 't_normal_msg_enc') return 0.01 # self.settings['t_normal_msg_enc'] = 'ecuSW.comm_mod.authorizer.SCCM_STREAM_ENC_SIMP_MSG_SESS_KEY' except: logging.warn( "Error: Could not find in DB the Value in 't_normal_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_normal_msg_enc'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) return 0.000000001
def c_t_conf_msg_dec_time(self, sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode): ''' time to decrypt the confirmation message''' try: # extract infos L().log(607, 't_conf_msg_dec_time', sym_dec_alg, sym_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(sym_dec_alg) algorithm_mode = EnumTrafor().to_value(sym_dec_alg_mode) key_len = EnumTrafor().to_value(sym_dec_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_conf_msg_dec_time'], alg_mode=algorithm_mode, mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_conf_msg_dec_time') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_conf_msg_dec_time' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_conf_msg_dec_time'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) L().log(603, 't_conf_msg_dec_time') return 0.01 # self.settings['t_conf_msg_dec_time'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_DEC_CONF_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_conf_msg_dec_time' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_conf_msg_dec_time'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) return 0.000000001
def c_t_tls_hand_send_client_finish_hash(self, input_size, hash_alg): try: # extract infos L().log(605, hash_alg, input_size) algorithm = EnumTrafor().to_value(hash_alg) # DB Lookup db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_send_client_finish_hash'], mode='HASH', alg=algorithm, data_size=input_size, description='t_tls_hand_send_client_finish_hash') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_hand_send_client_finish_hash') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.error("Error: Could not calculate the Value in 't_tls_record_mac_rec_side'") return 0.000000001 return 0
def _try_logging_transmission(self, t_propagation, t_sending): ''' notes the times that it takes to send the messages Input: t_propagation: float time it takes to propagate the message t_sending float time it takes to send the message ''' try: # Log transmission L().log(300, self.sim_env.now, self.current_message.sender_id, float(self.current_message_length_bit) / 8.0, \ self.current_message_length_bit, self.comp_id, self.current_message.data.get(), t_propagation + t_sending) except: # Log traceback ECULogger().log_traceback() try: L().log(300, self.sim_env.now, self.current_message.sender_id, self.current_message.data, \ self.current_message_length_bit, self.comp_id, self.current_message.data, t_propagation + t_sending) except: pass
def c_t_grant_msg_stream_dec(self, sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode): ''' time to decrypt the grant message ''' try: # extract infos L().log(610, 't_grant_msg_stream_dec', sym_dec_alg, sym_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(sym_dec_alg) key_len = EnumTrafor().to_value(sym_dec_keylen) alg_modee = EnumTrafor().to_value(sym_dec_alg_mode) # DB Lookup db_val = TimingDBMap().lookup_interpol( alg_mode=alg_modee, lib=self.library_tags['t_grant_msg_stream_dec'], mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_grant_msg_stream_dec') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_grant_msg_stream_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_grant_msg_stream_dec'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) L().log(603, 't_grant_msg_stream_dec') return 0.01 # self.settings['t_grant_msg_stream_dec'] = 'ecuSW.comm_mod.authorizer.SCCM_STREAM_DEC_GRANT_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_grant_msg_stream_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_grant_msg_stream_dec'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) return 0.000000001
def certificate_trustworthy(certificate, root_certificate_list, now): ''' this method checks if the given certificate can be verified using the given list of root certificates, when this test is made at the point in time now. Input: certificate ECUCertificate certificate that is to be verified root_certificates_list list list of root certificates now float time in the simpy.Environment when this method is called Output: boolean bool True if this certificate could be verified using the given root certificates ''' # invalid certificate if certificate == None: return False valid, next_certificate = True, certificate # check certificate layerwise while next_certificate != None: try: # ca certificate ca_certificate = find_auth(next_certificate, root_certificate_list) # integrity hashed = HashedMessage(next_certificate, next_certificate.signature_hash) # root if ca_certificate == None: signature = asy_decrypt(next_certificate.signature, next_certificate.pub_key_user) # no root else: signature = asy_decrypt(next_certificate.signature, ca_certificate.pub_key_user) # integrity failed if not signature.same_hash(hashed): return False # expiry if not (now < next_certificate.valid_till and now >= next_certificate.valid_from): return False # next layer next_certificate = ca_certificate except: L().log(804, next_certificate) return False return valid
def c_t_tls_record_mac_rec_side(self, mac_size, mac_alg, mac_key_len): # Create verification hash try: # extract infos L().log(605, mac_alg, mac_size) algorithm = EnumTrafor().to_value(mac_alg) key_len = EnumTrafor().to_value(mac_key_len) alg_mode = "CMAC" # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=alg_mode, lib=self.library_tags['t_tls_record_mac_rec_side'], keylen=key_len, mode='ENCRYPTION', alg=algorithm, data_size=mac_size, description='t_tls_record_mac_rec_side') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_record_mac_rec_side') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.error("Error: Could not calculate the Value in 't_tls_record_mac_rec_side'") return 0.000000001 return 0
def c_t_reg_msg_sym_keygen(self, sym_enc_alg, sym_enc_keylen): ''''time to create the symmetric ECU Key''' # self.settings['t_reg_msg_sym_keygen'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ENC_REG_MSG_CREATE_SYM_KEY' try: # extract information L().log(604, sym_enc_alg, sym_enc_keylen, 0) algorithm = EnumTrafor().to_value(sym_enc_alg) key_len = EnumTrafor().to_value(sym_enc_keylen) # read Database db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_sym_keygen'], mode='KEYGEN', keylen=key_len, alg=algorithm, description='t_reg_msg_sym_keygen') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_sym_keygen' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_sym_keygen'], sym_enc_alg, sym_enc_keylen ])) L().log(603, 't_reg_msg_sym_keygen') return 0.001 except: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_sym_keygen' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_sym_keygen'], sym_enc_alg, sym_enc_keylen ])) return 0.000000001
def _main_receive(self): ''' infinitely waits for an incoming message and logs it once it arrives Input: - Output: - ''' while True: # receive [self.msg_id, self.msg_data] = yield self.sim_env.process(self.comm_mod.receive_msg()) # log received if self.msg_id: L().log(500, self.sim_env.now, self._ecu_id, [self.msg_id, self.msg_data])
def c_t_ecu_auth_reg_msg_create_comp_hash(self, size_to_hash, hash_mech): ''' time it takes to create the hash for the comparision in the registration message ''' try: # extract infos L().log(605, hash_mech, size_to_hash) algorithm = EnumTrafor().to_value(hash_mech) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_create_comp_hash'], mode='HASH', alg=algorithm, data_size=size_to_hash, description='t_ecu_auth_reg_msg_create_comp_hash') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_create_comp_hash' use 0.0...01\nUsed input: %s" % str([ self. library_tags['t_ecu_auth_reg_msg_create_comp_hash'], size_to_hash, hash_mech ])) L().log(603, 't_reg_msg_hash') return 0.01 except: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_create_comp_hash' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_create_comp_hash'], size_to_hash, hash_mech ])) return 0.000000001
def c_t_tls_hand_enc_client_keyex_msg(self, pub_enc_alg, pub_enc_keylen, size_to_enc, pub_enc_alg_option): ''''enrypt the client keyexchange message -> public encryption ''' try: # extract information L().log(604, pub_enc_alg, pub_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(pub_enc_alg) key_len = EnumTrafor().to_value(pub_enc_keylen) # read Database if pub_enc_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_client_keyex_msg'], mode='ENCRYPTION', param_len=key_len, alg=algorithm, data_size=size_to_enc, description='t_tls_hand_enc_client_keyex_msg') else: if size_to_enc > ((float(key_len) / 8) - 11): size_to_enc_in = ceil((float(key_len) / 8) - 11) else: size_to_enc_in = size_to_enc db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_client_keyex_msg'], exp=pub_enc_alg_option, mode='ENCRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_enc_in, description='t_tls_hand_enc_client_keyex_msg') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(size_to_enc / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_enc_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_enc_client_keyex_msg'], size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option])) L().log(603, 't_tls_hand_enc_client_keyex_msg') return 0.001 # self.settings['t_tls_hand_enc_client_keyex_msg'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ENC_REG_MSG_INNER' except: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_enc_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_enc_client_keyex_msg'], size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option])) return 0.000000001
def c_t_str_auth_keygen_grant_msg(self, sym_enc_alg, sym_enc_keylen): ''' time to generate a session key ''' try: # extract infos L().log(707, sym_enc_alg, sym_enc_keylen) algorithm = EnumTrafor().to_value(sym_enc_alg) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_str_auth_keygen_grant_msg'], mode='KEYGEN', keylen=key_len, alg=algorithm, description='t_str_auth_keygen_grant_msg') # return values if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_keygen_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_keygen_grant_msg'], sym_enc_alg, sym_enc_keylen ])) L().log(603, 't_str_auth_keygen_grant_msg') return 0.01 # self.settings['t_str_auth_keygen_grant_msg'] = 'ecuSW.app_lay.stream_auth.SSMA_SESS_KEYGEN_GRANT_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_keygen_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_keygen_grant_msg'], sym_enc_alg, sym_enc_keylen ])) return 0.000000001
def c_t_str_auth_decr_req_msg(self, sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_option): ''' time to decrypt the request message with the ecu key''' try: # extract infos L().log(704, sym_dec_alg, sym_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(sym_dec_alg) alg_option = EnumTrafor().to_value(sym_dec_alg_option) key_len = EnumTrafor().to_value(sym_dec_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=alg_option, lib=self.library_tags['t_str_auth_decr_req_msg'], mode='DECRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_str_auth_decr_req_msg') # return values if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_decr_req_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_decr_req_msg'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_option ])) L().log(603, 't_str_auth_decr_req_msg') return 0.01 # self.settings['t_str_auth_decr_req_msg'] = 'ecuSW.app_lay.stream_auth.SSMA_STREAM_REQ_INI_DECR' except: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_decr_req_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_decr_req_msg'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_option ])) return 0.000000001