def dump_logs():
   ''' First create connection '''
   req_unsolicited = conn.connect()
   ''' If unsolicited read it'''
   if req_unsolicited:
         status, buf, uns = conn.receive()
         check_status_error( status )
   ''' Reset display '''
   conn.send([0xD2, 0x01, 0x01, 0x00])
   status, buf, uns = conn.receive(3)
   check_status_error( status )

   ''' Dump logs '''
   conn.send( [0xD0, 0x05, 0x00, P2_VIPA_LOG])
   ''' Receive and check '''
   status, buf, uns = conn.receive(30)
   check_status_error( status )
   tlv = TLVParser(buf)
   template = tlv.getTag((0x6F))
   filename = TLVParser(template).getTag((0x84))[0].decode('utf-8')
   localfile = filename.split('/')[-1];
   log.log('Log file on terminal: %s, downloading as %s' % (filename, localfile))

   ''' Retrieve log file '''
   progress = partial(utility.display_console_progress_bar, utility.get_terminal_width())
   fileops.getfile(conn, log, filename, localfile, progress)
def processMagstripeFallback(tid):
    # Ask for removal and swipe
    conn.send([0xD0, 0x60, 0x1D, 0x00])
    while True:
        status, buf, uns = getAnswer(False)  # Get unsolicited
        if uns:
            tlv = TLVParser(buf)
            if EMVCardState(tlv) == EMV_CARD_INSERTED:
                tlv = removeEMVCard()
                break
    # Ask for swipe
    if MagstripeCardState(tlv) == EMV_CARD_REMOVED:
        conn.send([0xD2, 0x01, 0x00, 0x01], '\x09Please Swipe Card')
        status, buf, uns = getAnswer()
        # Wait for swipe
        while True:
            status, buf, uns = getAnswer(False)
            if uns:
                tlv = TLVParser(buf)
                magState = MagstripeCardState(tlv)
                if magState == ERROR_UNKNOWN_CARD or magState == MAGSTRIPE_TRACKS_AVAILABLE:
                    break
            log.log('Ignoring unsolicited packet ', tlv)
            continue
    if MagstripeCardState(tlv) == MAGSTRIPE_TRACKS_AVAILABLE:
        vspDecrypt(tlv, tid)

    # We're done!
    return 5
def continueTransaction(continue_trans_tag=CONTINUE_TRANS_TAG):
    log.log('continueTransaction')
    continue_tpl = (0xE0, continue_trans_tag)
    conn.send([0xDE, 0xD2, 0x00, 0x00], continue_tpl)
    while True:
        status, buf, uns = getAnswer(False)  #Don't ignore unsolicited
        if status != 0x9000:
            log.logerr('Transaction terminated with status ', hex(status))
            return -1, status, buf, uns
        tlv = TLVParser(buf)
        #optional E6 (Status) template, reporting why Terminal is in wait state
        if tlv.tagCount(0xE6) != 0:
            log.log('transaction in wait state ', TLVParser(buf))
            log.log('PIN Entry is being performed, waiting for user input')
            #handling to allow user to break from PIN entry to continue test
            print(
                'PIN entry modification, press PC key \'A\' to abort, \'B\' to bypass or \'C\' to cancel'
            )
            while True:
                if kbhit():
                    key = getch()
                    log.log('key press ', key)
                    if key == 'a' or key == 'A':
                        log.logerr('PIN entry aborting')
                        abortDevice()
                        break
                    if key == 'b' or key == 'B':
                        log.logerr('PIN entry bypassing')
                        verifyPIN(P1=0xFF)
                        break
                    if key == 'c' or key == 'C':
                        log.logerr('PIN entry cancelling')
                        verifyPIN(P1=0x00)
                        break
                if conn.is_data_avail():
                    break  # Has user attempted PIN entry, proceed to evaluation of results
                continue
        else:
            #Status result
            if tlv.tagCount(0xE3):
                log.log('transaction approved')
                return TRANSACTION_APPROVED, status, buf, uns
            if tlv.tagCount(0xE4):
                log.log('online request, transaction must be verified online')
                return ONLINE_REQUESTED, status, buf, uns
            if tlv.tagCount(0xE5):
                log.log('transaction declined')
                return TRANSACTION_DECLINED, status, buf, uns
def process_language(lang, is_list, is_user):
    req_unsolicited = conn.connect()
    if req_unsolicited:
        status, buf, uns = conn.receive()
        check_status_error(status)

    p1 = 0x00 if is_user else 0x01 if lang or is_list else 0x02
    p2 = 0x00 if is_list else 0x01
    conn.send([0xD2, 0xD0, p1, p2],
              [[(0xDF, 0xA2,
                 0x22), bytes(lang, encoding='utf-8')]] if lang else None)
    status, buf, uns = conn.receive()
    check_status_error(status)

    tlv = TLVParser(buf)
    languages = tlv.getTag((0xDF, 0xA2, 0x20))

    if lang: return

    if len(languages) == 0:
        log.logerr("No language returned")
        exit(1)

    log.log(
        "Available languages:" if is_list else
        "User selected language:" if is_user else "Current language:",
        ", ".join(l.decode('utf-8') for l in languages))
Пример #5
0
def get_vfi_certificate():
    certNo = 0x00000001
    global ux_certificates
    ux_certificates.clear()
    while True:
        c_tag = tagStorage()
        #BUG: Unable to push the direct string not bytearray
        c_tag.store( (0xDF, 0x83, 0x10), int(certNo) )
        conn.send([0xC5, 0x06, 0x00, 0x00] , c_tag.getTemplate(0xE0))
        status, buf, uns = conn.receive()
        if status == 0x9000:
            tlv = TLVParser(buf)
            if tlv.tagCount( (0xDF, 0x83, 0x11) ) == 1:
                log.log("Success")
                key = tlv.getTag( (0xDF, 0x83, 0x11) )[0]
                log.log("Key: ", hexlify(key))
                ux_certificates.append(key)
                certNo += 1
            else:
                log.logerr("Failure")
        else:
            break
        sleep(1)
    #check_status_error( status )
    log.log("We have ", len(ux_certificates), " UX certificates")
    #log.log("UX certs: ", ux_certificates)
    return len(ux_certificates)
def password_entry():
    req_unsolicited = conn.connect()
    if req_unsolicited:
        status, buf, uns = conn.receive()
        check_status_error(status)

    conn.send([0xD2, 0x01, 0x01, 0x00])  # Reset display
    status, buf, uns = conn.receive(3)
    check_status_error(status)

    conn.send(
        [0xD2, 0xF3, 0x00, 0x04],
        (
            0xE0,
            [
                [(0xDF, 0xB0, 0x05), (ENTRY_UPPER | ENTRY_LOWER).to_bytes(
                    4, byteorder='big')],  # entry modes
                [(0xDF, 0xB0, 0x06), (ENTRY_UPPER).to_bytes(4, byteorder='big')
                 ],  # initial entry mode
            ]))
    status, buf, uns = conn.receive()
    check_status_error(status)

    tlv = TLVParser(buf)
    password = tlv.getTag((0xDF, 0x83, 0x01))[0].decode('utf-8')
    log.log('Password entered:', password)
def demo_function():
   ''' First create connection '''
   req_unsolicited = conn.connect()
   ''' If unsolicited read it'''
   if req_unsolicited:
         status, buf, uns = conn.receive()
         check_status_error( status )
   ''' Reset display '''
   conn.send([0xD2, 0x01, 0x01, 0x00])
   status, buf, uns = conn.receive(3)
   check_status_error( status )
   ''' Store the tags for numeric entry '''
   c_tag = tagStorage()
   c_tag.store( (0xDF, 0xA2, 0x06), [0x00, 0x0D, 0x00, 0x57, 0x00, 0x00] )
   c_tag.store( (0xDF, 0xA2, 0x07), [0x30, 0x00] )
   c_tag.store( (0xDF, 0xA2, 0x08), b'123' )
   ''' Send the message '''
   conn.send( [0xD2, 0x04, 0x00, 0x01], c_tag.getTemplate( 0xE0 ) )
   ''' Receive and check '''
   status, buf, uns = conn.receive(30)
   check_status_error( status )
   '''print the buffer example '''
   '''print(buf) '''
   tlv = TLVParser(buf)
   user_input = tlv.getTag((0xDF, 0xA2, 0x08))
   log.log('User enter [', str(user_input[0], 'iso8859-1'), ']') 
Пример #8
0
def chooseOneFromAIDList(aidList):
    text = ''
    itemCnt = 1
    for (adfName, AppLabel) in aidList:

        text += '\xDF\xA2\x02\01'
        text += chr(itemCnt)
        itemCnt += 1

        text += '\xDF\xA2\x03'
        text += chr(len(AppLabel))
        text += AppLabel.decode('ascii')
    log.log("chooseOneFromAIDList text options")

    conn.send([0xD2, 0x03, 0x00, 0x00], text)
    status, buf, uns = conn.receive()
    check_status_error(status)
    tlv = TLVParser(buf)
    itemNumber = tlv.getTag((0xDF, 0xA2, 0x02))
    itemNumber = itemNumber[0]  # get value of tag to bytearray
    itemNumber = int(
        itemNumber[0])  # get first element from bytearray and convert to int
    log.log("Chosen value is: ", itemNumber)
    if itemNumber > len(aidList):
        log.logerr("Returned choice value = ", itemNumber, " is out of bounds")
        return None
    itemIdx = itemNumber - 1
    log.log("This value maps to: ", aidList[itemIdx][0])
    return aidList[itemIdx][0]
def checkEncryptedPAN(tlv):
    tokenTemplate = tlv.getTag((0xFF, 0x7C))
    if len(tokenTemplate) == 0: return

    parsed = TLVPrepare().parse_received_data(tokenTemplate[0] + b'\x90\x00')
    tokenTLV = TLVParser(parsed)
    encryptedPANblock = tokenTLV.getTag((0xDF, 0x83, 0x6F))
    if len(encryptedPANblock) == 0:
        log.log("Encrypted PAN block not found")
        return

    sha1len = 20
    encryptedlen = 128
    if len(encryptedPANblock[0]) != encryptedlen + sha1len:
        log.logerr("Invalid encrypted PAN length: %s, not %s"
            % (len(encryptedPANblock[0]), encryptedlen + sha1len))
    encryptedPAN = encryptedPANblock[0][ : encryptedlen]
    fingerprint = encryptedPANblock[0][-sha1len : ]
    strFingerprint = hexlify(fingerprint).decode('utf-8')
    log.log("Encrypted PAN:", hexlify(encryptedPAN).decode('utf-8'))
    global rsaPublicKeyFingerprint
    if rsaPublicKeyFingerprint != strFingerprint:
        log.logerr("RSA public key fingerprint does not match")
        log.logerr("Ours:", rsaPublicKeyFingerprint)
        log.logerr("Came:", strFingerprint)
        exit(1)
    else:
        log.log("RSA public key fingerprint OK:", strFingerprint)
    decryptedPAN = execute('openssl', 'rsautl', '-decrypt', '-inkey', RSA_PRIVATE_KEY,
        stdinput=encryptedPAN)
    log.log("Decrypted PAN:", decryptedPAN)
Пример #10
0
def putfile(filename, remotefilename, forceput):
    conn = Connection()
    log = getSyslog()
    req_unsolicited = conn.connect()
    if req_unsolicited:
        #Receive unsolicited
        status, buf, uns = conn.receive()
        if status != 0x9000:
            log.logerr('Unsolicited fail')
            exit(-1)
        log.log('Unsolicited', TLVParser(buf))
    progress = partial(util.display_console_progress_bar,
                       util.get_terminal_width())
    if forceput:
        fops.putfile(conn, log, filename, remotefilename, progress=progress)
    else:
        try:
            fops.updatefile(conn,
                            log,
                            filename,
                            remotefilename,
                            False,
                            progress=progress)
        except exc.invResponseException as e:
            log.logerr("Unable to use updatefile fallback to putfile")
            fops.putfile(conn,
                         log,
                         filename,
                         remotefilename,
                         progress=progress)
def transtest_function():
	log = getSyslog()
	conn = connection.Connection();
	prev_nad = conn.setnad(2)
	#Create ssl server
	#conn.connect_serial('COM1', 57600, timeout=2 );
	req_unsolicited = conn.connect()
	if req_unsolicited:
		#Receive unsolicited
		status, buf, uns = conn.receive()
		if status != 0x9000:
			log.logerr('Unsolicited fail')
			exit(-1)
		log.log('Unsolicited', TLVParser(buf) )
		
	#Send INIT contactless
	conn.send([0xc0, 0x01, 0x00, 0x00])
	status, buf, uns = conn.receive()
	if status != 0x9000:
		log.logerr('ctls init fail')
		exit(-1)


	# Now wait for the user to send CLOSE
	input("[ENTER] to send 'close'")

	#Send CLOSE contactless
	conn.send([0xc0, 0x02, 0x00, 0x00])
	status, buf, uns = conn.receive()
	if status != 0x9000:
		log.logerr('ctls close fail')
		exit(-1)
def get_certificates(is_return_file, level):
    req_unsolicited = conn.connect()
    if req_unsolicited:
        status, buf, uns = conn.receive()
        check_status_error(status)

    p1 = 0x01 if is_return_file else 0x00
    get_all_levels = level is None

    current_level = 0x00 if get_all_levels else level
    while True:
        conn.send([0xC5, 0x06, p1, 0x00], (0xE0, [
            [(0xDF, 0x83, 0x10),
             current_level.to_bytes(4, byteorder='big')],
        ]))
        status, buf, uns = conn.receive()
        if status == 0x9F13:
            log.log("No more certificates in the chain")
            break
        check_status_error(status)

        tlv = TLVParser(buf)
        certs = tlv.getTag((0xDF, 0x83,
                            0x12) if is_return_file else (0xDF, 0x83, 0x11))
        if len(certs) != 1:
            log.logerr("One return tag expected in response, got:", len(certs))
            exit(1)

        cert = certs[0].decode('utf-8')
        label = "file name: " if is_return_file else "content:\n"
        log.log("Certificate level %d %s%s" % (current_level, label, cert))

        if not get_all_levels: break
        current_level = current_level + 1
def startTransaction(start_trans_tag=START_TRANS_TAG):
    log.log('startTransaction')
    start_templ = (0xE0, start_trans_tag)
    conn.send([0xDE, 0xD1, 0x00, 0x00], start_templ)
    while True:
        status, buf, uns = getAnswer(False)  #Don't ignore unsolicited
        #unexpected unsolicited received
        if uns:
            log.log('Unsolicited packet detected: ignoring')
            if status == 0x9000:
                tlv = TLVParser(buf)
                if tlv.tagCount(0xE6) != 0:
                    log.log('Multi application card!')
                continue
            else:
                log.log('unexpected unsolicited message received ', buf)
                continue
        #expected solicited received
        if status != 0x9000:
            if status == 0x9F28:
                return MAGSWIPE_FALLBACK, status, buf, uns
            else:
                log.logerr('Transaction terminated with status ', hex(status))
                return -1, status, buf, uns
        return 0, status, buf, uns
Пример #14
0
def performManualEntry(tid):
    # perform manual entry - PAN, Expiry only
    conn.send([0xD2, 0x14, 0x0F, 0x01])
    status, buf, uns = getAnswer()
    tlv = TLVParser(buf)
    vspDecrypt(tlv, tid)
    S1DecryptData(tlv)
Пример #15
0
def execute_script(filename):
    global __SCRIPT_ROOT
    __SCRIPT_ROOT = os.path.dirname(os.path.abspath(filename))
    th_ast_parser = __create_ast_th_language_syntax()
    ast = th_ast_parser.parseFile(filename, True)
    log = getSyslog()
    conn = connection.Connection()
    req_unsolicited = conn.connect()
    abort_sw1sw2 = True
    pool = tagStorage()
    localtempl = {}
    if req_unsolicited:
        #Receive unsolicited
        status, buf, uns = conn.receive()
        if status != 0x9000:
            raise exc.invResponseException('Unsolicited message fail', status)
        log.log('Unsolicited', TLVParser(buf))
    for toks in ast:
        if toks[0] == 'setnad':
            conn.setnad(toks[1])
            log.loginfo('Set NAD to', toks[1])
        elif toks[0] == '#':
            log.loginfo("Comment:", str(toks[1]).strip())
        elif toks[0] == 'setdevice':
            log.loginfo('Set device to', toks[1])
        elif toks[0] == 'flush':
            log.loginfo('Flush comms')
        elif toks[0] == 'clearlocalpool':
            pool.clear()
            localtempl.clear()
            log.loginfo('Clear local pool')
        elif toks[0] == 'pause':
            log.loginfo('Pause for', toks[1], 'sec')
            time.sleep(toks[1])
        elif toks[0] == 'send':
            __send_command(toks, conn, pool, localtempl, log)
        elif toks[0] == 'abortsw1sw2':
            abort_sw1sw2 = toks[1]
            log.loginfo('Abort SW1SW2 =', abort_sw1sw2)
        elif toks[0] == 'wait':
            __wait_command(toks, conn, log, abort_sw1sw2)
        elif toks[0] == 'prompt':
            log.loginfo('Prompt message:', str(" ").join(toks[1].asList()))
            __wait_command(toks, conn, log, abort_sw1sw2)
        elif toks[0] == 'storelocaltag':
            pool = __storetag_command(toks, pool)
        elif toks[0] == 'appendlocal':
            tpl, data = __appendlocal_command(toks, pool)
            localtempl[tpl] = data
        elif toks[0] == 'senddirect':
            __senddirect_command(toks, conn, log)
        elif toks[0] == 'putfile':
            __putfile_command(toks, conn, log)
        elif toks[0] == 'updatefile':
            __updatefile_command(toks, conn, log)
        elif toks[0] == 'getfile':
            __getfile_command(toks, conn, log)
        else:
            log.logerr('Unknown tokens', str(toks))
            raise exc.logicalException('Unknown tokens in script')
def Connect(conn, log):
    req_unsolicited = conn.connect()
    if req_unsolicited:
        status, buf, uns = conn.receive()
        if status != 0x9000:
            log.logerr('Unsolicited fail')
            exit(-1)
        log.log('Unsolicited', TLVParser(buf))
def manageDisplayContract(P1=READ_CONTRAST):
    log.log('manageDisplayContract')
    conn.send([0xD0, 0x70, P1, 0x00])
    status, buf, uns = getAnswer()
    if P1 == READ_CONTRAST:
        tlv = TLVParser(buf)
        if status == 0x9000 and not tlv.tagCount((0xDF, 0xA2, 0x0B)) == 1:
            log.logerr('message had a missing expected tag (DFA20B)', buf)
        return -1, status, buf, uns
    return 0, status, buf, uns
Пример #18
0
def GenerateHMAC():
    req_unsolicited = conn.connect()
    if req_unsolicited:
        status, buf, uns = conn.receive()
        check_status_error(status)

    #pan = b'\x41\x11\x11\x11\x11\x11\x11\x11'
    pan = '4111111111111111'
    # expected HMAC for TC test secrets: d1f8827dd9276f9f80f8890d3e607ac03ca022ba91b8024356dcdf54ad434f83
    # pan = b'\x34\x30\x30\x35\x35\x36\x32\x32\x33\x31\x32\x31\x32\x31\x34\x39'
    c_tag = tagStorage()
    c_tag.store((0xDF, 0xEC, 0x0E), pan)  # message for MAC
    c_tag.store((0xDF, 0xEC, 0x23), 0x06)  # host ID
    #c_tag.store((0xDF, 0xEC, 0x23), 0x07)  # host ID
    conn.send([0xC4, 0x22, 0x00, 0x00], c_tag.getTemplate(0xE0))
    log.log("Generate HMAC sent")

    status, buf, uns = conn.receive()
    log.log("Generate HMAC response received")
    check_status_error(status)

    tlv = TLVParser(buf)
    tag_output_data = (0xDF, 0xEC, 0x7B)
    if (tlv.tagCount(tag_output_data) == 1):
        hmac = tlv.getTag(tag_output_data)[0]
        log.log("Generated HMAC:", hexlify(hmac).decode('utf-8'))

        c_tag = tagStorage()
        c_tag.store((0xDF, 0xEC, 0x0E), hmac)  # message for MAC
        #c_tag.store((0xDF, 0xEC, 0x23), 0x06)  # host ID
        c_tag.store((0xDF, 0xEC, 0x23), 0x07)  # host ID
        conn.send([0xC4, 0x22, 0x00, 0x00], c_tag.getTemplate(0xE0))
        log.log("Generate HMAC sent")

        status, buf, uns = conn.receive()
        log.log("Generate HMAC response received")
        check_status_error(status)

        tlv = TLVParser(buf)
        tag_output_data = (0xDF, 0xEC, 0x7B)
        if (tlv.tagCount(tag_output_data) == 1):
            hmac = tlv.getTag(tag_output_data)[0]
            log.log("Generated HMAC:", hexlify(hmac).decode('utf-8'))
def processTestCase():
    req_unsolicited = conn.connect()
    if req_unsolicited:
        #Receive unsolicited
        log.log('Waiting for unsolicited')
        status, buf, uns = getAnswer(False)
        log.log('Unsolicited', TLVParser(buf))

    abortDevice()
    resetDevice()
def processTestCase():
    req_unsolicited = conn.connect()
    if req_unsolicited:
        #Receive unsolicited
        log.log('Waiting for unsolicited')
        status, buf, uns = getAnswer(False)
        log.log('Unsolicited', TLVParser(buf))

    testFile = 'i:guiapp.cfg'
    getBinaryStatus(testFile)
Пример #21
0
def GenerateHMAC():
    req_unsolicited = conn.connect()
    if req_unsolicited:
        status, buf, uns = conn.receive()
        check_status_error(status)

    pan = b'\x41\x11\x11\x11\x11\x11\x11\x11'
    # pan = b'\x34\x30\x30\x35\x35\x36\x32\x32\x33\x31\x32\x31\x32\x31\x34\x39'
    c_tag = tagStorage()
    c_tag.store((0xDF, 0xEC, 0x0E), pan)  # message for MAC
    c_tag.store((0xDF, 0xEC, 0x23), 0x06)  # host ID
    #c_tag.store((0xDF, 0xEC, 0x23), 0x07)  # host ID
    conn.send([0xC4, 0x22, 0x00, 0x00], c_tag.getTemplate(0xE0))
    log.log("Generate HMAC sent")

    status, buf, uns = conn.receive()
    log.log("Generate HMAC response received")
    check_status_error(status)

    tlv = TLVParser(buf)
    tag_output_data = (0xDF, 0xEC, 0x7B)
    if (tlv.tagCount(tag_output_data) == 1):
        hmac = tlv.getTag(tag_output_data)[0]
        log.log("Generated HMAC:", hexlify(hmac).decode('utf-8'))

        c_tag = tagStorage()
        c_tag.store((0xDF, 0xEC, 0x0E), hmac)  # message for MAC
        #c_tag.store((0xDF, 0xEC, 0x23), 0x06)  # host ID
        c_tag.store((0xDF, 0xEC, 0x23), 0x07)  # host ID
        conn.send([0xC4, 0x22, 0x00, 0x00], c_tag.getTemplate(0xE0))
        log.log("Generate HMAC sent")

        status, buf, uns = conn.receive()
        log.log("Generate HMAC response received")
        check_status_error(status)

        tlv = TLVParser(buf)
        tag_output_data = (0xDF, 0xEC, 0x7B)
        if (tlv.tagCount(tag_output_data) == 1):
            hmac = tlv.getTag(tag_output_data)[0]
            log.log("Generated HMAC:", hexlify(hmac).decode('utf-8'))
def awaitCardRemoval():
    displayCommand(P1=0x0E)
    #unsolicited response
    while True:
        status, buf, uns = getAnswer(False)  #Don't ignore unsolicited
        if not uns:
            log.logerr('unexpected solicited message received ', buf)
            return -1, status, buf, uns
        tlv = TLVParser(buf)
        if emvCardState(tlv) == EMV_CARD_REMOVED:
            break
    return 0, status, buf, uns
def freeSpace():
    log.log('freeSpace')
    conn.send([0x00, 0xD0, 0x00, 0x00])
    status, buf, uns = getAnswer()
    tlv = TLVParser(buf)
    if status == 0x9000 and not (tlv.tagCount(
        (0xDF, 0xDE, 0x7E)) == 2 and tlv.tagCount((0xDF, 0xDE, 0x7F)) == 2):
        log.logerr(
            'message had a missing expected tag or tags (DFDE7E and DFDE7F)',
            buf)
        return -1, status, buf, uns
    return 0, status, buf, uns
def configureFileVersions():
    log.log('configureFileVersions')
    conn.send([0xD0, 0x01, 0x00, 0x00])
    status, buf, uns = getAnswer()
    tlv = TLVParser(buf)
    if status == 0x9000 and not (tlv.tagCount(
        (0xDF, 0xDE, 0x7E)) and tlv.tagCount((0xDF, 0xDE, 0x7F))):
        log.logerr(
            'message had a missing expected tag or tags (DFDE7E and DFDE7F)',
            buf)
        return -1, status, buf, uns
    return 0, status, buf, uns
def resetDevice(P1=0x00, P2=0x00):
    log.log('resetDevice')
    conn.send([0xD0, P1, P2, 0x01])
    status, buf, uns = getAnswer()
    tlv = TLVParser(buf)
    tid = tlv.getTag((0x9F, 0x1e))
    if len(tid):
        tid = str(tid[0], 'iso8859-1')
        log.log('Terminal TID: ', tid)
    else:
        tid = ''
        log.logerr('Invalid TID (or cannot determine TID)!')
    return tid, status, buf, uns
def checkfile( filename ):
    conn = Connection()
    log = getSyslog()
    req_unsolicited = conn.connect()
    if req_unsolicited:
        #Receive unsolicited
        status, buf, uns = conn.receive()
        if status != 0x9000:
            log.logerr('Unsolicited fail')
            exit(-1)
        log.log('Unsolicited', TLVParser(buf) )
    progress = partial( util.display_console_progress_bar, util.get_terminal_width() )
    openfile( conn, log, filename, progress )
def getAnswer(ignoreUnsolicited=True, stopOnErrors=True):
    while True:
        status, buf, uns = conn.receive()
        if uns and ignoreUnsolicited:
            log.log('Unsolicited packet detected: ', TLVParser(buf))
            continue
        if status != 0x9000:
            log.logerr('Pinpad reported error ', hex(status))
            if stopOnErrors:
                performCleanup()
                exit(-1)
        break
    return status, buf, uns
Пример #28
0
def get_cert_file():
    c_tag = tagStorage()
    c_tag.store( (0xDF, 0x83, 0x10), 0x00000000 )
    conn.send([0xC5, 0x06, 0x01, 0x00], c_tag.getTemplate(0xE0))
    status, buf, uns = conn.receive()
    if status == 0x9000:
        tlv = TLVParser(buf)
        if tlv.tagCount( (0xDF, 0x83, 0x12 ) ) == 1:
            fname = tlv.getTag( (0xDF, 0x83, 0x12) )[0]
            log.log("Cert file ", fname)
        else:
            log.logerr("Error, no cert name!")
    else:
        log.logerr("Bad response ", status)
def getAnswer(ignoreUnsolicited=True, stopOnErrors=True, noErrors=False):
    while True:
        status, buf, uns = conn.receive()
        if uns and ignoreUnsolicited:
            log.log('Unsolicited packet detected: ', TLVParser(buf))
            continue
        if status != 0x9000 and (not noErrors):
            log.logerr('Pinpad reported error ', hex(status))
            if stopOnErrors:
                performCleanup()
                log.logerr('*** TEST BEING HALTED ABNORMALLY ***')
                exit(-1)
        break
    return status, buf, uns
Пример #30
0
def delfile(file):
    conn = Connection()
    log = getSyslog()
    req_unsolicited = conn.connect()
    if req_unsolicited:
        #Receive unsolicited
        status, buf, uns = conn.receive()
        if status != 0x9000:
            log.logerr('Unsolicited fail')
            exit(-1)
        log.log('Unsolicited', TLVParser(buf) )
    
    conn.send([0x00, 0xAB, 0x00, 0x00], file)
    sw12 = conn.receive()[0]
    if sw12 != 0x9000: exit(sw12)