Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
 def _load_dblookup_vals(self, cfg, db_lookups, proj_vals):
     ''' loads defined values from the database lookup if
         defined (deprecated)
         
         Input:     -
         Output:    -
     '''
     out_lst = []
     for sec in db_lookups:
         for variable in db_lookups[sec]:                
             try:
                 symb = self._cfg_sec_map(cfg, sec)[variable.lower()]
                 db = TimingDBMap()
                 vala = db.lookup_time(sec, variable, symb, proj_vals)
                 if vala != None:
                     out_lst.append([variable, vala])                                        
             except:
                 pass
     return out_lst
Exemplo n.º 11
0
 def _load_dblookup_vals(self, cfg, db_lookups, proj_vals):
     ''' loads defined values from the database lookup if
         defined (deprecated)
         
         Input:     -
         Output:    -
     '''
     out_lst = []
     for sec in db_lookups:
         for variable in db_lookups[sec]:
             try:
                 symb = self._cfg_sec_map(cfg, sec)[variable.lower()]
                 db = TimingDBMap()
                 vala = db.lookup_time(sec, variable, symb, proj_vals)
                 if vala != None:
                     out_lst.append([variable, vala])
             except:
                 pass
     return out_lst
Exemplo n.º 12
0
 def on_type_cb_itemchanged(self):
     ''' changed index if new Setting hit create new Setting'''
     
     for i in range(self.elem_tab.rowCount()):
         try:
             cb = self.type_idx_to_cb[i]
             if(cb.currentText() == "new Setting ..."):
                 idx = cb.findText(self.type_item_state[i])
                 cb.setCurrentIndex(idx)                    
                 self.new_setting(i)
                 continue
             
             if cb.currentText() != self.type_item_state[i] and cb.currentText() != 'CUSTOMIZED':
                 ''' load values '''#                     
                 itm = self.elem_tab.item(i, 1)
                 txt = itm.text()
                 cor_dic = self.type_to_dict[txt]
                 try:
                     val = cor_dic[cb.currentText()]                    
                     self.elem_tab.setItem(i, 3, QTableWidgetItem(str(val)))
                 except:
                     pass
                 
                 self.db_lookup_dict[txt]
                 
                 itm1 = self.elem_tab.item(i, 0)
                 itm2 = self.elem_tab.item(i, 1)
                 
                 ''' if DB Lookup show request -> double click opens window: edit request and edit the condition '''
                 [request, spec] = TimingDBMap().lookup_from_spec(itm1.text(), itm2.text(), cb.currentText())
                 [condition, spec] = TimingDBMap().conditions_from_spec(itm1.text(), itm2.text(), cb.currentText())                    
                 itm = QTableWidgetItem(request)                    
                 self.elem_tab.setItem(i, 4, itm)
                 itm.setToolTip("Conditions: \n%s" % self._pretty_str_cond(condition))
                 self.db_lookup_idx_to_info[i] = [condition, request, spec]
                     
             self.type_item_state[i] = cb.currentText()
         except:
             pass
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
    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
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
 def c_t_tls_record_dec(self, msg_size, enc_alg, enc_key_len, enc_alg_mode):
     # Decrypt the content with symmetric algorithm
     try:
         # extract infos
         algorithm = EnumTrafor().to_value(enc_alg)
         algorithm_mode = EnumTrafor().to_value(enc_alg_mode)
         key_len = EnumTrafor().to_value(enc_key_len) 
         
         # DB Lookup
         db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_record_dec'], alg_mode=algorithm_mode, mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=msg_size, description='t_tls_record_dec')
         
         # return value
         if db_val: 
             return G().val_log_info(db_val, 602, db_val)  
         else: 
             L().log(603, 't_tls_record_dec')        
         return 0.01  
     except:
         logging.error("Error: Could not calculate the Value in 't_tls_record_dec'")
         return 0.000000001 
Exemplo n.º 19
0
 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
Exemplo n.º 20
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
Exemplo n.º 21
0
    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
Exemplo n.º 22
0
    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
Exemplo n.º 23
0
    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
Exemplo n.º 24
0
    def c_t_ecu_auth_reg_msg_validate_cert(self, cert_hash_mech, cert_enc_mech, cert_enc_keylen, \
                                   cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn, cert_size):
        ''' time to validate the ecus certificate, hash to sign is the size of the Certificate to be signed '''
        try:
            # extract infos
            L().log(700, cert_enc_mech, cert_enc_keylen, cert_size_hashtosign,
                    cert_ca_len)
            db_val = False
            algorithm = EnumTrafor().to_value(cert_enc_mech)
            hash_alg = EnumTrafor().to_value(cert_hash_mech)
            key_len = EnumTrafor().to_value(cert_enc_keylen)

            # CrypLi RSA: Verify = Time of hash creation + time to encrypt hash / CyaSSL & CrypLi ECC: Verify operation
            if cert_enc_mech == AsymAuthMechEnum.ECC:
                db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='VERIFY', \
                                                       param_len=key_len, alg=algorithm, data_size=cert_size_hashtosign, description='t_ecu_auth_reg_msg_validate_cert')

            if self.library_tags['t_ecu_auth_reg_msg_validate_cert'] in [
                    "Crypto_Lib_SW", "Crypto_Lib_HW"
            ] and cert_enc_mech == AsymAuthMechEnum.RSA:  # RSA SIGN = DECRYPTION, VERIFY= ENCRYPTION
                # 1. create hash of certificate content
                db_val_1 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'],
                    mode='HASH',
                    alg=hash_alg,
                    data_size=cert_size,
                    description='t_ecu_auth_reg_msg_validate_cert')

                # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt)
                if cert_size_hashsigned > ((float(key_len) / 8) - 11):
                    cert_size_hashsigned_in = ceil((float(key_len) / 8) - 11)
                else:
                    cert_size_hashsigned_in = cert_size_hashsigned
                db_val_2 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'],
                    mode='VERIFY',
                    keylen=key_len,
                    alg=algorithm,
                    data_size=cert_size_hashsigned_in,
                    exp=cert_alg_optn,
                    description='t_ecu_auth_reg_msg_validate_cert')
                # in case of RSA have to slice the message and encrypt each of those
                nr_chuncks = math.ceil(cert_size_hashsigned /
                                       ((float(key_len) / 8) - 11))
                db_val_2 = db_val_2 * nr_chuncks

                # 3. create hash of digital signature
                db_val_3 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'],
                    mode='HASH',
                    alg=hash_alg,
                    data_size=cert_size_hashtosign,
                    description='t_ecu_auth_reg_msg_validate_cert')

                db_val = db_val_1 + db_val_2 + db_val_3

            if self.library_tags[
                    't_ecu_auth_reg_msg_validate_cert'] == "CyaSSL" and cert_enc_mech == AsymAuthMechEnum.RSA:
                # 1. create hash of certificate content
                db_val_1 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'],
                    mode='HASH',
                    alg=hash_alg,
                    data_size=cert_size,
                    description='t_ecu_auth_reg_msg_validate_cert')

                # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt)
                if cert_size_hashsigned > ((float(key_len) / 8) - 11):
                    cert_size_hashsigned_in = ceil((float(key_len) / 8) - 11)
                else:
                    cert_size_hashsigned_in = cert_size_hashsigned
                db_val_2 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'],
                    mode='ENCRYPTION',
                    keylen=key_len,
                    alg=algorithm,
                    data_size=cert_size_hashsigned_in,
                    exp=cert_alg_optn,
                    description='t_ecu_auth_reg_msg_validate_cert')
                # in case of RSA have to slice the message and encrypt each of those
                nr_chuncks = math.ceil(cert_size_hashsigned /
                                       ((float(key_len) / 8) - 11))
                db_val_2 = db_val_2 * nr_chuncks

                # 3. create hash of digital signature
                db_val_3 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'],
                    mode='HASH',
                    alg=hash_alg,
                    data_size=cert_size_hashtosign,
                    description='t_ecu_auth_reg_msg_validate_cert')

                db_val = db_val_1 + db_val_2 + db_val_3

            # return value
            if db_val:
                L().log(602, db_val)
            else:
                logging.warn("Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_validate_cert' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_validate_cert'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \
                                   cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn]))
                L().log(603, 't_ecu_auth_reg_msg_validate_cert')
                return 0.0000000001
            abs_time = cert_ca_len * db_val  # repeat cert_ca_len times
            return abs_time  # self.settings['t_ecu_auth_reg_msg_validate_cert'] = 'ecuSW.app_lay.ecu_auth.SSMA_VALID_CERT_REG_MSG'
        except:
            logging.warn("Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_validate_cert' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_validate_cert'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \
                                   cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn]))
            return 0.000000001
Exemplo n.º 25
0
    def c_t_reg_msg_outter_enc(self, size_to_enc, pub_enc_alg, pub_enc_keylen,
                               pub_enc_alg_option):
        ''' time to encrypt the outter part of the reg. msg. i.e. the hashed inner part
            -> sign procedure
        '''

        try:
            # extract infos
            L().log(606, pub_enc_alg, pub_enc_keylen, size_to_enc)
            algorithm = EnumTrafor().to_value(pub_enc_alg)
            key_len = EnumTrafor().to_value(pub_enc_keylen)

            # DB Lookup
            if pub_enc_alg == AsymAuthMechEnum.ECC:
                db_val = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_reg_msg_outter_enc'],
                    mode='SIGN',
                    param_len=key_len,
                    alg=algorithm,
                    data_size=size_to_enc,
                    description='t_reg_msg_outter_enc')
            if pub_enc_alg == AsymAuthMechEnum.RSA and self.library_tags[
                    't_reg_msg_outter_enc'] == "CyaSSL":
                if size_to_enc > (float(key_len) / 8):
                    size_to_enc_in = ceil(float(key_len) / 8)
                else:
                    size_to_enc_in = size_to_enc

                db_val = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_reg_msg_outter_enc'],
                    mode='DECRYPTION',
                    exp=pub_enc_alg_option,
                    keylen=key_len,
                    alg=algorithm,
                    data_size=size_to_enc_in,
                    description='t_reg_msg_outter_enc')
                # 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))
                db_val = db_val * nr_chuncks

            if pub_enc_alg == AsymAuthMechEnum.RSA and self.library_tags[
                    't_reg_msg_outter_enc'] in [
                        "Crypto_Lib_SW", "Crypto_Lib_HW"
                    ]:
                db_val = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_reg_msg_outter_enc'],
                    mode='SIGN',
                    exp=pub_enc_alg_option,
                    keylen=key_len,
                    alg=algorithm,
                    data_size=size_to_enc,
                    description='t_reg_msg_outter_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_reg_msg_outter_enc' use 0.0...01\nUsed input: %s"
                    % str([
                        self.library_tags['t_reg_msg_outter_enc'], size_to_enc,
                        pub_enc_alg, pub_enc_keylen, pub_enc_alg_option
                    ]))
                L().log(603, 't_reg_msg_outter_enc')
            return 0.01  # self.settings['t_reg_msg_outter_enc'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ENC_REG_MSG_OUTTER'

        except:
            logging.warn(
                "Error: Could not find in DB the Value in 't_reg_msg_outter_enc' use 0.0...01\nUsed input: %s"
                % str([
                    self.library_tags['t_reg_msg_outter_enc'], size_to_enc,
                    pub_enc_alg, pub_enc_keylen, pub_enc_alg_option
                ]))
            return 0.000000001
Exemplo n.º 26
0
    def c_t_adv_msg_secmodcert_enc(self, cert_hash_mech, cert_enc_mech, cert_enc_keylen, \
                                   cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn, cert_size):
        ''' time to validate the certificates of the security module '''
        try:
            # extract parameters
            db_value = False
            algorithm = EnumTrafor().to_value(cert_enc_mech)
            hash_algorithm = EnumTrafor().to_value(cert_hash_mech)
            key_length = EnumTrafor().to_value(cert_enc_keylen)

            # logging
            L().log(601, cert_enc_mech, cert_enc_keylen, cert_size_hashtosign,
                    cert_ca_len)

            # CrypLi RSA: Verify = Time of hash creation + time to encrypt hash / CyaSSL & CrypLi ECC: Verify operation
            if cert_enc_mech == AsymAuthMechEnum.ECC:
                db_value = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='VERIFY',
                    param_len=key_length,
                    alg=algorithm,
                    data_size=cert_size_hashtosign,
                    description='t_adv_msg_secmodcert_enc')

            if self.library_tags['t_adv_msg_secmodcert_enc'] in [
                    "Crypto_Lib_SW", "Crypto_Lib_HW"
            ] and cert_enc_mech == AsymAuthMechEnum.RSA:
                # 1. create hash of certificate content
                db_val_1 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='HASH',
                    alg=hash_algorithm,
                    data_size=cert_size,
                    description='t_adv_msg_secmodcert_enc')

                # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt)
                if cert_size_hashsigned > ((key_length / 8) - 11):
                    cert_size_hashsigned_in = ceil((float(key_length) / 8) -
                                                   11)
                else:
                    cert_size_hashsigned_in = cert_size_hashsigned
                db_val_2 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='VERIFY',
                    keylen=key_length,
                    alg=algorithm,
                    data_size=cert_size_hashsigned_in,
                    exp=cert_alg_optn,
                    description='t_adv_msg_secmodcert_enc')
                # in case of RSA have to slice the message and encrypt each of those
                nr_chuncks = math.ceil(cert_size_hashsigned /
                                       ((float(key_length) / 8) - 11))
                db_val_2 = db_val_2 * nr_chuncks

                # 3. create hash of digital signature
                db_val_3 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='HASH',
                    alg=hash_algorithm,
                    data_size=cert_size_hashtosign,
                    description='t_adv_msg_secmodcert_enc')

                db_value = db_val_1 + db_val_2 + db_val_3

            if self.library_tags[
                    't_adv_msg_secmodcert_enc'] == "CyaSSL" and cert_enc_mech == AsymAuthMechEnum.RSA:
                # 1. create hash of certificate content
                db_val_1 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='HASH',
                    alg=hash_algorithm,
                    data_size=cert_size,
                    description='t_adv_msg_secmodcert_enc')

                # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt)
                if cert_size_hashsigned > ((key_length / 8) - 11):
                    cert_size_hashsigned_in = ceil((float(key_length) / 8) -
                                                   11)
                else:
                    cert_size_hashsigned_in = cert_size_hashsigned
                db_val_2 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='ENCRYPTION',
                    keylen=key_length,
                    alg=algorithm,
                    data_size=cert_size_hashsigned_in,
                    exp=cert_alg_optn,
                    description='t_adv_msg_secmodcert_enc')
                # in case of RSA have to slice the message and encrypt each of those
                nr_chuncks = math.ceil(cert_size_hashsigned /
                                       ((float(key_length) / 8) - 11))
                db_val_2 = db_val_2 * nr_chuncks

                # 3. create hash of digital signature
                db_val_3 = TimingDBMap().lookup_interpol(
                    lib=self.library_tags['t_adv_msg_secmodcert_enc'],
                    mode='HASH',
                    alg=hash_algorithm,
                    data_size=cert_size_hashtosign,
                    description='t_adv_msg_secmodcert_enc')

                db_value = db_val_1 + db_val_2 + db_val_3

            # Set value
            if db_value:
                L().log(602, db_value)
            else:
                logging.warn("Error: Could not find in DB the Value in 't_adv_msg_secmodcert_enc' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_adv_msg_secmodcert_enc'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \
                                   cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn]))
                return G().val_log_info(0.0000000001, 603,
                                        't_adv_msg_secmodcert_enc')

            # repeat cert_ca_len times
            abs_time = cert_ca_len * db_value

            return abs_time  # self.settings['t_adv_msg_secmodcert_enc'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ADV_SEC_MOD_CERT_VAL'
        except:
            logging.warn("Error: Could not find in DB the Value in 't_adv_msg_secmodcert_enc' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_adv_msg_secmodcert_enc'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \
                                   cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn]))
            return 0.000000001
Exemplo n.º 27
0
LWASpecPresets().hold_rule = [False, 10]  # hold on/off; minimal interval between two stream requests

LWASpecPresets().request_spec = [100, 9999999999]  # size of request message and timeout maximum

LWASpecPresets().deny_spec = [100]  # deny message size
LWASpecPresets().grant_spec = [100]  # grant message size

LWASpecPresets().session_key_info = [SymAuthMechEnum.AES, AuKeyLengthEnum.bit_128, SymAuthMechEnum.ECB]  # session key information

# set further layer specifications
GeneralSpecPreset().enable()
GeneralSpecPreset().physical_layer = StdPhysicalLayer
GeneralSpecPreset().datalink_layer = StdDatalinkLayer  # datalink layer that is used in all ECUs that implement this option
GeneralSpecPreset().transport_layer = FakeSegmentTransportLayer

TimingDBMap().enable_fallback_message = True

#===============================================================================
#     Setting up a project
#===============================================================================

# register ECUs that are located outside of the usual folders
# usual folders: components.base.ecu.types and components.security.ecu.types
#api.register_ecu_classes(r"C:\Users\artur.mrowca\workspace\ECUSimulation\components\base\gateways")

# setup the logging
api_log_path = os.path.join(os.path.dirname(__file__), "logs/api.log")
api.show_logging(logging.INFO, api_log_path, True)

# create an empty environment specification for the environment
sim_env = api.create_environment(200)