I'm trying to retrieve the PAN of a smart card using pyscard
in Python
. What I have done so far is to connect to the reader and to retrieve various information about the reader and the card... but I cannot find the way to get the serial number...
Using pyscard, the first thing to do is to create a communication context
between PC and Smart Card:
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
Once the context has been established, let's try to get the list of active smart card readers:
hresult, readers = SCardListReaders(hcontext, [])
readers
is a list, readers[0] will contain the reader, should you possess only one. At this point, what I did is to get the ATR
of the card:
hresult, hcard, dwActiveProtocol = SCardConnect(hcontext,
current_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
And it works. Then I tried to communicate with the card: here I write the way to get a random number, using the APDU command and the 0x84 hex in the second position (INS).
hresult, response = SCardTransmit(hcard,dwActiveProtocol,[0x00, 0x84, 0x00, 0x00, 0x00])
As you can see an APDU is composed by 5 different hex digits: CLA, INS, P1, P2, P3.
Ok, still not serial number, but I'm fighting at least :-)
By the way, I'm reading the pyscard documentation and the ISO7816 doc.
Thank you in advance!