Example #1
0
 def _get_dgis(self, tag94):
     dgi_list = []
     afls = utils.parse_afl(tag94)
     for afl in afls:
         sfi = utils.int_to_hex_str(afl.sfi)
         record = utils.int_to_hex_str(afl.record_no)
         dgi_list.append(sfi + record)
     return dgi_list
Example #2
0
 def _get_dgi_list(self, tag94):
     '''
     根据tag94获取对应的DGI分组
     '''
     dgi_list = []
     dgi = self.cps.get_dgi(tag94)
     tag94 = utils.parse_tlv(dgi.get_value('94'))
     afls = utils.parse_afl(tag94[0].value)
     for afl in afls:
         sfi = utils.int_to_hex_str(afl.sfi)
         record = utils.int_to_hex_str(afl.record_no)
         dgi_list.append(sfi + record)
     return dgi_list
Example #3
0
 def read_binary(self, offset, read_len):
     '''读取二进制文件,并按二进制呈现为字符串形式'''
     data = ''
     #self._file.seek(offset,0)
     value_arr = self.read(offset, read_len)
     for value in value_arr:
         data += utils.int_to_hex_str(value)
     return data
Example #4
0
def parse_sddf_data(xml, sddf_tag, goldpac_dgi_list=[]):
    sddf_data = ''
    for item in goldpac_dgi_list:
        if item.goldpac_dgi == sddf_tag:
            sddf_data = item.data
    dgi = Dgi()
    node_dgi, value_format = get_tag_link_attribute(xml, sddf_tag)
    if node_dgi == '' or value_format == '':
        return None
    need_remove_template = is_need_delete_template(node_dgi)
    global _aid_list_info
    is_second_app = False
    for _, aid_info in _aid_list_info.items():
        if sddf_tag[4] == aid_info[0]:
            is_second_app = aid_info[1]
            break
    if is_second_app:  #说明包含双应用
        dgi.name = node_dgi + '_2'
    else:
        dgi.name = node_dgi
    if value_format == 'TLV':
        data = utils.remove_dgi(sddf_data, node_dgi)
        if need_remove_template:
            data = utils.remove_template70(data)
        if utils.str_to_int(node_dgi) > 0xA000 or not utils.is_tlv(data):
            dgi.add_tag_value(dgi.name, data)
        else:
            tlvs = utils.parse_tlv(data)
            if len(tlvs) > 0 and tlvs[0].is_template is True:
                value = utils.assemble_tlv(tlvs[0].tag, tlvs[0].value)
                dgi.add_tag_value(dgi.name, value)
            else:
                for tlv in tlvs:
                    if tlv.len > 0x7F:
                        value = tlv.tag + '81' + utils.int_to_hex_str(
                            tlv.len) + tlv.value
                    else:
                        value = tlv.tag + utils.int_to_hex_str(
                            tlv.len) + tlv.value
                    dgi.add_tag_value(tlv.tag, value)
    elif value_format == 'V':
        dgi.add_tag_value(dgi.name, sddf_data)
    return dgi
Example #5
0
 def process_assemble_tlv(self, dgi):
     for item in self.cps.dgi_list:
         if dgi == item.name:
             for key, value in item.tag_value_dict.items():
                 if not key:
                     print('dgi' + dgi + '存在非法的None Tag')
                 if not value:
                     print('dgi' + dgi + ' tag' + key +
                           '值为None,请检查配置文件对该值是否配置正确')
                 data_len = int(len(value) / 2)
                 if data_len > 0x80:
                     item.tag_value_dict[
                         key] = key + '81' + utils.int_to_hex_str(
                             data_len) + item.tag_value_dict[key]
                 else:
                     item.tag_value_dict[key] = key + utils.int_to_hex_str(
                         data_len) + item.tag_value_dict[key]
             return self.cps
     return self.cps
Example #6
0
def store_data(data_type, data, reset=False):
    global store_count
    if reset:
        store_count = 0
    cmd_header = "80E2" + data_type
    cmd_header += utils.int_to_hex_str(store_count)
    cmd = cmd_header + utils.get_strlen(data) + data
    store_count += 1
    if data_type == "80":
        store_count = 0
    return pcsc.send_raw(cmd, (0x9000, ))
Example #7
0
def store_data_mac(data, data_type, dek_session_key, mac_key, reset=False):
    global store_count
    if reset:
        store_count = 0
    cmd_header = "84E2" + data_type
    cmd_header += utils.int_to_hex_str(store_count)
    data = algorithm.des3_cbc_encrypt(dek_session_key, data)
    cmd = cmd_header + utils.get_strlen(data) + data
    store_count += 1
    if data_type == "80":
        store_count = 0
    return pcsc.send_raw(cmd, (0x9000, ))
Example #8
0
 def put_data(self, tag, value):
     tag9F36 = self.get_tag('9F36')
     tag9F26 = self.get_tag(PROCESS_STEP.FIRST_GAC, '9F26')
     key_input = '000000000000' + tag9F36 + '000000000000' + algorithm.xor(
         tag9F36, 'FFFF')
     if len(tag) == 2:
         tag = '00' + tag
     data_len = utils.int_to_hex_str(len(value) // 2 + 8)
     mac_input = '04DA' + tag + data_len + tag9F36 + tag9F26 + value
     key_mac = algorithm.xor(key_input, self.key_mac)
     mac = algorithm.des3_mac(key_mac, mac_input)
     apdu.put_data(tag, value, mac)
Example #9
0
def read_record(sfi, record_no, resp_sw_list=(0x9000, )):
    sfi = (sfi << 3) + 4
    p1 = utils.int_to_hex_str(record_no)
    p2 = utils.int_to_hex_str(sfi)
    cmd = '00B2' + p1 + p2
    return pcsc.send_raw(cmd, resp_sw_list)