nfcpy reading public information from contactless credit card with APDU commands

135 Views Asked by At

I am trying to read the public information from my own contactless credit card such as name, expiry date, pan number and card type using python and the nfcpy library, i am struggling to move beyond setting the PPSE and retrieving the card type eg) Visa Debit.

I have used the below code

import nfc
try:
    clf = nfc.ContactlessFrontend()
    assert clf.open('tty:USB0:pn532') is True

    tag = clf.connect(rdwr={'on-connect': lambda tag:False})
    
    cla = 0x00 #Class Byte - command class
    ins = 0xA4 #Instruction Byte - specific command for card to perform
    p1 = 0x04 #Parameters related to the command
    p2 = 0x00 #Parameters related to the command
    lc = 0x00 #If command has a data field, indicates the length of the data field
    data = bytearray.fromhex('325041592E5359532E4444463031') #Data field, if used data field needs to be followed by le field
    le = 0x00 #If command doesnt have data field, indicates expected length of response, 0x00 card gives as much data as is available

    resp = tag.send_apdu(cla,ins,p1,p2,data,check_status=False)
    print(resp)

    clf.close()
except Exception as EX:
    print(f'ERROR - {EX}')
    clf.close()

this code returns a bytearray with x90\x00 at the end to signify success and in the response it does show a "visa debit" card. But the response looks different from every other thread i have read, not all being bytes and actually displaying "Visa Debit" instead of the AID in bytes.

bytearray(b'o:\x84\x0e2PAY.SYS.DDF01\xa5(\xbf\x0c%a#O\x07\xa0\x00\x00\x00\x03\x10\x10P\nVisa Debit\x87\x01\x03\x9f\n\x08\x00\x01\x05\x01\x00\x00\x00\x00\x90\x00')

I found the AID for Visa Debit card and tried sending the below APDU command,

00 B2 01 02 A0 00 00 00 03 10 10 02

but only got response

bytearray(b'n\x00')

I am not sure how to move forward to select the individual records from the card, i dont know if nfcpy is the best library to use. Any advise would be appreciated.

*EDIT To create the SFI file locator in python, i was able to apply bitwise operator directly to the byte without converting to binary string first.

sfi_rec_bytes = 10
p = sfi_rec_bytes[0] >> 3
i = p << 3
g = i | 4
sfi_recs = g
0

There are 0 best solutions below