Christmas is coming!

To celebrate the new year and thank for the support from all our dear customers, Christmas promotional activity is being held in JavaCardOS online store.

During the event, you can enjoy many promotional activities - High Discount on JavaCardOS products,Lucky Draw,Double forum Points.

Come to choose your own Christmas gift and try your luck now!

How to use pyGlobalPlatform to GET DATA from the card

pyGlobalPlatform is a open source python library of globalplatform client library.
User avatar
JavaCardOS
Posts: 250
Joined: Thu Apr 30, 2015 12:00 pm
Points: 2189
Contact:

How to use pyGlobalPlatform to GET DATA from the card

Postby JavaCardOS » Tue Nov 24, 2015 7:36 am

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)

Berlin
Posts: 4
Joined: Tue Dec 01, 2015 10:01 pm
Points: 0
Contact:

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

Postby Berlin » Tue Dec 01, 2015 11:26 pm

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 ?


Return to “pyGlobalPlatform”

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer