def parse_pse_and_ppse_data(xml, sddf_tag, goldpac_dgi_list): sddf_data = '' node_dgi, value_format = get_tag_link_attribute(xml, sddf_tag) if node_dgi == '' or value_format == '': return None for item in goldpac_dgi_list: if item.goldpac_dgi == sddf_tag: sddf_data = item.data data = utils.remove_dgi(sddf_data, node_dgi) need_remove_template = is_need_delete_template(node_dgi) if need_remove_template: data = utils.remove_template70(data) return node_dgi, data
def read_record(self,tag94): ''' 读记录数据 ''' resps = [] afls = utils.parse_afl(tag94) for afl in afls: Log.info('read record: %02X%02X',afl.sfi,afl.record_no) resp = apdu.read_record(afl.sfi,afl.record_no) if resp.sw != 0x9000: Log.error('read record wrong') return resps tools.output_apdu_info(resp) resps.append(resp) if afl.is_static_sign_data: self.sig_data += utils.remove_template70(resp.response) return resps
def _process_pse_and_ppse(dgi_name, data): dgi = Dgi() if dgi_name == 'Store_PSE_1': dgi.name = 'PSE' data = utils.remove_dgi(data, '0101') data = utils.remove_template70(data) dgi.add_tag_value('0101', data) elif dgi_name == 'Store_PSE_2': dgi.name = 'PSE' data = utils.remove_dgi(data, '9102') value = utils.assemble_tlv('A5', '880101' + data) dgi.add_tag_value('9102', value) elif dgi_name == 'Store_PPSE': dgi.name = 'PPSE' # value = dgi.assemble_tlv('BF0C',data) # value = dgi.assemble_tlv('A5',value) data = utils.remove_dgi(data, '9102') dgi.add_tag_value('9102', data) return dgi
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
def _parse_tlv(dgi_name, data): dgi = Dgi() data = utils.remove_dgi(data, dgi_name) int_dgi = utils.str_to_int(dgi_name) if int_dgi < 0x0B01: if data[0:2] != '70': Log.error('数据有误,小于0B01的DGI应包含70模板') return None data = utils.remove_template70(data) if not utils.is_rsa(dgi_name) and utils.is_tlv(data): 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: value = utils.assemble_tlv(tlv.tag, tlv.value) dgi.add_tag_value(tlv.tag, value) else: dgi.add_tag_value(dgi_name, data) return dgi