Announce two new product: SmartCard Reader Rockey200 and USB2.0 Extension Cable

ROCKEY 200 is a handy and portable USB Smart Card reader that can perform read/write operations on any ISO 7816-1/2/3/4 smart cards which are compatible with protocol T=0 and T=1.

USB2.0 Extension Cable With high speed USB 2.0 devices such as USB token ,USB Card Reader and so on.

Come to try it 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: 259
Joined: Thu Apr 30, 2015 12:00 pm
Points: 2267
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