Page 1 of 1

How to use pyGlobalPlatform to GET DATA from the card

Posted: Tue Nov 24, 2015 7:36 am
by JavaCardOS
The Issuer Security Domain(ISD) stores the following data:
• Issuer Identification Number (IIN)
• Card Image Number (CIN)
• Card Recognition Data
• Issuer Security Domain key information
• Other Card Issuer's proprietary data

These Card Data can be retrieved using the GET DATA command.

Here is the code which shows how to use pyGlobalPlatform to get data from card.

Code: Select all

# Import the module
import globalplatformlib as gp

# Establish context
context = gp.establishContext()

# Select smartcard reader
readernames = gp.listReaders(context)
readerName=readernames[0]

# Connect the reader
cardInfo = gp.connectCard(context, readerName, gp.SCARD_PROTOCOL_Tx)

# Get SCP details
scp, scpi = gp.getSCPDetails(context, cardInfo)

# Mutual Authentication
securityInfo = gp.mutualAuthentication(context, cardInfo, gp.DEFAULT_KEY, gp.DEFAULT_KEY, gp.DEFAULT_KEY, gp.DEFAULT_KEY, 0, 0, scp, scpi, 0, 0)

# Get data from card
data1 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_IIN)
data2 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_CIN)
data3 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_CARD_DATA)
data4 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_KEY_INFORMATION_TEMPLATE)
# Optional
data5 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_SECURITY_LEVEL)
# Optional
data6 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_APPLICATIONS)
# Optional
data7 = gp.getData(context, cardInfo, securityInfo, gp.TAG_DATA_EXTENDED_CARD_RESOURCE_INFORMATION)
# Optional
data8 = gp.getData(context, cardInfo, securityInfo, gp.TAG_CONFIRMATION_COUNTER)
data9 = gp.getData(context, cardInfo, securityInfo, gp.TAG_SEQUENCE_COUNTER)

# Release context
gp.releaseContext(context)

# Print the card information
if data1 != -1:
    print "1 IIN: " + "".join("%02X" %(ord(b)) for b in data1)
if data2 != -1:
    print "2 CIN: " + "".join("%02X" %(ord(b)) for b in data2)
if data3 != -1:
    print "3 CARD DATA: " + "".join("%02X" %(ord(b)) for b in data3)
if data4 != -1:
    print "4 KEY INFORMATION TEMPLATE: " + "".join("%02X" %(ord(b)) for b in data4)
if data5 != -1:
    print "5 SECURITY LEVEL: " + "".join("%02X" %(ord(b)) for b in data5)
if data6 != -1:
    print "6 APPLICATIONS: " + "".join("%02X" %(ord(b)) for b in data6)
if data7 != -1:
    print "7 EXTENDED CARD RESOURCE INFORMATION: " + "".join("%02X" %(ord(b)) for b in data7)
if data8 != -1:
    print "8 CONFIRMATION COUNTER: " + "".join("%02X" %(ord(b)) for b in data8)
if data9 != -1:
    print "9 SEQUENCE COUNTER: " + "".join("%02X" %(ord(b)) for b in data9)

Re: How to use pyGlobalPlatform to GET DATA from the card

Posted: Tue Dec 01, 2015 11:26 pm
by Berlin
hello,
I select all codes about this topic, and paste it into my python script.
There was an error when I run the python script, and it prompt "python.exe stopped working".

This is why? Can anyone help me ?