Ejemplo n.º 1
0
def ext_auth(kmc, div_method, secure_level, host_challenge, init_update_data):
    cmd = ''
    cmd_data_len = '10'
    mac = ''
    if secure_level == SECURE_LEVEL.SL_MAC:
        cmd = '84820100'
    elif secure_level == SECURE_LEVEL.SL_MAC_ENC:
        cmd = '84820300'
    else:
        cmd = '84820000'
    scp = init_update_data[22:24]
    card_challenge = init_update_data[24:40]
    card_cryptogram = init_update_data[40:56]
    dek_session_key, mac_session_key, enc_session_key = gen_kmc_session.gen_session_key(
        kmc, div_method, host_challenge, init_update_data)
    card_cryptogram_input = host_challenge + card_challenge
    card_mac = algorithm.des3_full_mac(enc_session_key, card_cryptogram_input)
    if card_mac != card_cryptogram:
        resp = pcsc.ApduResponse()
        resp.sw = 0x6300
        return '', resp
    host_cryptogram_input = card_challenge + host_challenge
    host_mac = algorithm.des3_full_mac(enc_session_key, host_cryptogram_input)
    cmd += cmd_data_len + host_mac
    if scp == '01':
        mac = algorithm.des3_full_mac(enc_session_key, cmd)
    else:  #scp == '02'
        mac = algorithm.des3_mac(mac_session_key, cmd)
    cmd += mac
    return dek_session_key, pcsc.send_raw(cmd)
Ejemplo n.º 2
0
 def lock_app(self):
     tag9F36 = self.get_tag('9F36')
     tag9F26 = self.get_tag(PROCESS_STEP.FIRST_GAC, '9F26')
     key_input = '000000000000' + tag9F36 + '000000000000' + algorithm.xor(
         tag9F36, 'FFFF')
     mac_input = '841E000008' + tag9F36 + tag9F26
     key_mac = algorithm.xor(key_input, self.session_key_mac)
     mac = algorithm.des3_mac(key_mac, mac_input)
     apdu.lock_app(mac)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def gen_mc_cvc3(self, tag56, tag9F6B):
     self.tags['DC'] = algorithm.des3_mac(self.kdcvc3, tag56)[-4:]
     self.tags['DD'] = algorithm.des3_mac(self.kdcvc3, tag9F6B)[-4:]
     return self.tags['DC'] + self.tags['DD']
Ejemplo n.º 5
0
def gen_ac(key,data):
    return algorithm.des3_mac(key,data)