Example #1
0
def process_jetco_special_dgi(xml, goldpac_dgi_list, cps):
    rule_file_handle = RuleXml(xml.file_name)
    add_tag_nodes = xml.get_nodes(xml.root_element, 'AddTag')
    for node in add_tag_nodes:
        attrs = xml.get_attributes(node)
        dgi = Dgi()
        dgi.name = attrs['srcDGI']
        if 'srcTag' not in attrs:
            attrs['srcTag'] = attrs['dstTag']
        data = ''
        is_second_app = False
        if '_2' in dgi.name:
            is_second_app = True
        # 对DF20,DF27做特殊处理
        if attrs['dstDGI'] == 'DF20':
            _, sddf_tag_DF18, _ = rule_file_handle.get_tag_link_attribute(
                'EMVTag', 'DF18')
            _, sddf_tag_DF19, _ = rule_file_handle.get_tag_link_attribute(
                'EMVTag', 'DF19')
            data_DF18 = get_goldpac_data(goldpac_dgi_list, sddf_tag_DF18,
                                         is_second_app)
            data_DF19 = get_goldpac_data(goldpac_dgi_list, sddf_tag_DF19,
                                         is_second_app)
            data = data_DF18 + data_DF19
            data = data[0:data.find('20')]
            data = utils.bcd_to_str(data)
            if len(data) // 2 > 0x7F:
                data = attrs['dstDGI'] + '81' + utils.get_strlen(data) + data
            else:
                data = attrs['dstDGI'] + utils.get_strlen(data) + data
        elif attrs['dstDGI'] == 'DF27':
            _, sddf_tag_DF16, _ = rule_file_handle.get_tag_link_attribute(
                'EMVTag', 'DF16')
            _, sddf_tag_DF17, _ = rule_file_handle.get_tag_link_attribute(
                'EMVTag', 'DF17')
            data_DF16 = get_goldpac_data(goldpac_dgi_list, sddf_tag_DF16,
                                         is_second_app)
            data_DF17 = get_goldpac_data(goldpac_dgi_list, sddf_tag_DF17,
                                         is_second_app)
            data = data_DF16 + data_DF17
            data = data[0:data.find('20')]
            data = utils.bcd_to_str(data)
            if len(data) // 2 > 0x7F:
                data = attrs['dstDGI'] + '81' + utils.get_strlen(data) + data
            else:
                data = attrs['dstDGI'] + utils.get_strlen(data) + data
        else:
            _, sddf_tag, _ = rule_file_handle.get_tag_link_attribute(
                'EMVTag', attrs['dstTag'])
            data = get_goldpac_data(goldpac_dgi_list, sddf_tag, is_second_app)
        dgi.add_tag_value(attrs['srcTag'], data)
        cps.add_dgi(dgi)
    return cps
Example #2
0
def _process_template_and_dgi(dgi,data):
    int_dgi = utils.hex_str_to_int(dgi)
    data_len = len(data)
    if int_dgi <= 0x0B01 and dgi not in no_need_template_70:
        if data_len >= 0xFF * 2:
            data = '7082' + utils.get_strlen(data) + data
        elif data_len > 0x80 * 2:
            data = '7081' + utils.get_strlen(data) + data
        else:
            data = '70' + utils.get_strlen(data) + data
    if data_len > 0x80 * 2 and is_need_ff00_prefix:
        dgi += 'FF00'
    data = dgi + utils.get_strlen(data) + data
    return data
Example #3
0
 def process_add_fixed_tag(self, dgi_name, tag, value, before_tag,
                           after_tag):
     dgis = self.cps.get_all_dgis()
     dgi_names = [dgi.name for dgi in dgis]
     if dgi_name not in dgi_names:
         new_dgi = Dgi()
         new_dgi.name = dgi_name
         new_dgi.add_tag_value(tag, value)
         self.cps.add_dgi(new_dgi)
     else:
         for item in self.cps.dgi_list:
             if item.name == dgi_name:
                 if tag in item.tag_value_dict:
                     old_value = item.get_value(tag)
                     new_value = old_value[len(tag) + 2:] + value
                     new_value = tag + utils.get_strlen(
                         new_value) + new_value
                     item.modify_value(tag, new_value)
                 else:
                     if before_tag is not '':
                         item.insert_before(before_tag, tag, value)
                     elif after_tag is not '':
                         item.insert_after(after_tag, tag, value)
                     else:
                         item.add_tag_value(tag, value)
     return self.cps
Example #4
0
 def create_check_aid_case(self, check_aid_list):
     case_node = self.smart_qc.create_case_node('AID检测-非接',
                                                'SSQCaseEx3.dll')
     # <DeviceList>
     device_list_node = self.smart_qc.create_node(case_node, 'DeviceList')
     self.smart_qc.create_device_node(device_list_node, 'PC Twin2')
     # <SpecialInput>
     special_input_node = self.smart_qc.create_node(case_node,
                                                    'SpecialInput')
     # <CardStruct>
     card_struct_node = self.smart_qc.create_node(special_input_node,
                                                  'CardSturct')
     # <MF>
     self.smart_qc.create_node(card_struct_node, 'MF', fid='3F00')
     # <ApduList>
     app_nodes = self.dp_xml_handle.get_child_nodes(
         self.dp_xml_handle.root_element, 'App')
     cur_aids = []
     for app_node in app_nodes:
         aid = self.dp_xml_handle.get_attribute(app_node, 'aid')
         if not aid:
             Log.error(
                 'can not get aid from dp xml, check wether the dp xml is correct.'
             )
             return
         cur_aids.append(aid)
     need_check_aids = []
     for aid in check_aid_list:
         if aid not in cur_aids:
             need_check_aids.append(aid)
     apdu_list_node = self.smart_qc.create_node(card_struct_node,
                                                'ApduList')
     for aid in need_check_aids:
         apdu = '00A40400' + utils.get_strlen(aid) + aid
         self.smart_qc.create_node(apdu_list_node,
                                   'Apdu ',
                                   value=apdu,
                                   sw12="6A82")
     test_process_list_node = self.smart_qc.create_node(
         case_node, 'TestProcessList')
     self.smart_qc.create_node(test_process_list_node,
                               'Card_sturct_test',
                               enable='false')
     self.smart_qc.create_node(test_process_list_node,
                               'Compare_IC_info',
                               enable='false')
     self.smart_qc.create_node(test_process_list_node,
                               'Special_file_test',
                               enable='false')
     self.smart_qc.create_node(test_process_list_node,
                               'Transaction_test',
                               enable='false')
     self.smart_qc.create_node(test_process_list_node,
                               'Check_atr',
                               enable='false')
     self.smart_qc.create_node(test_process_list_node,
                               'ApduList_test',
                               enable='true')
Example #5
0
def send(cmd_header, data, resp_sw_list=(0x9000, )):
    '''
    在连接读卡器后,发送APDU指令。
    cmd_header 表示指令头
    data 表示要发送给终端的数据
    resp_sw_list 表示期望的响应返回码列表,若返回不是期望的响应码,则自动退出APDU的交互
    '''
    cmd = cmd_header + utils.get_strlen(data) + data
    return send_raw(cmd, resp_sw_list)
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 process_assemble_dgi(self, src_dgi, src_tag, format_str):
     data = ""
     tag_list = format_str.split(',')
     for tag in tag_list[::-1]:
         if '.' not in tag:  #说明是模板
             data = tag + utils.get_strlen(data) + data
         else:
             dst_dgi = tag.split('.')[0]
             dst_tag = tag.split('.')[1]
             if dst_dgi == '':
                 data = dst_tag + data
             elif dst_dgi[len(dst_dgi) - 1] == 'v':
                 dst_dgi = dst_dgi[0:len(dst_dgi) - 1]
                 value = self.cps.get_tag_value(dst_dgi, dst_tag)
                 if not value:
                     print('dgi %s tag %s 不存在' % (dst_dgi, dst_tag))
                 data = value + data
             else:
                 value = ''
                 if dst_dgi in ('9102', '9103'):  #对于9103,9102需要特殊处理
                     tlvs = utils.parse_tlv(
                         self.cps.get_tag_value(dst_dgi, dst_dgi))
                     for tlv in tlvs:
                         if tlv.tag == dst_tag:
                             value = tlv.value
                             break
                 else:
                     value = self.cps.get_tag_value(dst_dgi, dst_tag)
                 if not value:
                     print('dgi %s tag %s 不存在' % (dst_dgi, dst_tag))
                 tag_len = utils.get_strlen(value)
                 data = dst_tag + tag_len + value + data
     dgi = Dgi()
     dgi.name = src_dgi
     dgi.add_tag_value(src_tag, data)
     self.cps.add_dgi(dgi)
     return self.cps
Example #9
0
def install_app(packet_aid,
                applet_aid,
                inst_aid,
                priviliage,
                install_param,
                token='00',
                resp_sw_list=(0x9000, )):
    cmd_header = '80E60C00'
    packet_aid_len = utils.get_strlen(packet_aid)
    applet_aid_len = utils.get_strlen(applet_aid)
    inst_aid_len = utils.get_strlen(inst_aid)
    priviliage_len = utils.get_strlen(priviliage)
    install_param_len = utils.get_strlen(install_param)
    data = packet_aid_len + packet_aid + applet_aid_len + applet_aid + inst_aid_len + inst_aid
    data += priviliage_len + priviliage + install_param_len + install_param + token
    cmd = cmd_header + utils.get_strlen(data) + data
    return pcsc.send_raw(cmd, resp_sw_list)
Example #10
0
def gpo(pdol, resp_sw_list=(0x9000, )):
    pdol_len = utils.get_strlen(pdol)
    data = '83' + pdol_len + pdol
    data_len = utils.get_strlen(data)
    cmd = '80A80000' + data_len + data
    return pcsc.send_raw(cmd, resp_sw_list)
Example #11
0
def select_file(file_id):
    file_id_len = utils.get_strlen(file_id)
    cmd = '00A40000' + file_id_len + file_id
    return pcsc.send_raw(cmd)
Example #12
0
def select(instance_id, resp_sw_list=(0x9000, )):
    aid_len = utils.get_strlen(instance_id)
    cmd = '00A40400' + aid_len + instance_id
    return pcsc.send_raw(cmd, resp_sw_list)
Example #13
0
def delete_app(aid, resp_sw_list=(0x9000, )):
    aid_len = utils.get_strlen(aid)
    data = '4F' + aid_len + aid
    data_len = utils.get_strlen(data)
    cmd = '80E40000' + data_len + data
    return pcsc.send_raw(cmd, resp_sw_list)
Example #14
0
def gac(crypto_type, data, resp_sw_list=(0x9000, )):
    p1 = str(crypto_type.value) + '0'
    cmd = '80AE' + p1 + '00' + utils.get_strlen(data) + data
    return pcsc.send_raw(cmd, resp_sw_list)
Example #15
0
def lock_app(mac, resp_sw_list=(0x9000, )):
    cmd = '841E0000' + utils.get_strlen(mac) + mac
    return pcsc.send_raw(cmd, resp_sw_list)
Example #16
0
def put_data(tag, data, mac, resp_sw_list=(0x9000, )):
    lc = utils.get_strlen(data + mac)
    if len(tag) == 2:
        tag = '00' + tag
    cmd = '04DA' + tag + lc + data + mac
    return pcsc.send_raw(cmd, resp_sw_list)
Example #17
0
def external_auth(arpc, arc):
    data = arpc + arc
    cmd = '00820000' + utils.get_strlen(data) + data
    return pcsc.send_raw(cmd)
Example #18
0
def internal_auth(ddol):
    cmd = '00880000' + utils.get_strlen(ddol) + ddol
    return pcsc.send_raw(cmd)
Example #19
0
def init_update(host_challenge, key_verson='00', key_id='00'):
    cmd_header = '8050' + key_verson + key_id
    cmd = cmd_header + utils.get_strlen(host_challenge) + host_challenge
    return pcsc.send_raw(cmd)