Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

How to use pyGlobalPlatform to execute GET STATUS command

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

How to use pyGlobalPlatform to execute GET STATUS command

Post by JavaCardOS » Tue Nov 24, 2015 8:10 am

GET STATUS command is used to retrieve Issuer Security Domain, Executable Load File, Executable Module, Application or Security Domain Life Cycle status information.

The following code shows how to use pyGlobalPlatform to execute GET STATUS command.

Code: Select all

# Import the module
import globalplatformlib as gp

# EstablishContext
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
isd = gp.getStatus(context, cardInfo, securityInfo, gp.GET_STATUS_P1_ISD)
appSSDs = gp.getStatus(context, cardInfo, securityInfo, gp.GET_STATUS_P1_APP_SSD)
exeFiles = gp.getStatus(context, cardInfo, securityInfo, gp.GET_STATUS_P1_EXECUTABLE_LOAD_FILES)
exeFilesModules = gp.getStatus(context, cardInfo, securityInfo, gp.GET_STATUS_P1_EXECUTABLE_LOAD_FILES_MODULES)

# Release context
gp.releaseContext(context)
 
# Print the data 
for status in (isd, appSSDs, exeFiles, exeFilesModules):
    print "-------------------------------------"
    if status != -1:
        appsInfo, fileModulesInfo = status
        for appInfo in appsInfo:
            print "AID: %s - PRIV: %02X - LIFE-CYCLE-STATE: %02X" %("".join("%02X" %(ord(b)) for b in appInfo['aid']), appInfo['privileges'], appInfo['lifeCycleState'])
        for fileModuleInfo in fileModulesInfo:
            print "AID: %s - PRIV: %02X" %("".join("%02X" %(ord(b)) for b in fileModuleInfo['aid']), fileModuleInfo['lifeCycleState'])
            for moduleInfo in fileModuleInfo['executableModules']:
                print "    " + "".join('%02X' %(ord(b)) for b in moduleInfo)

Robert
Posts: 4
Joined: Thu Jun 04, 2015 10:42 pm
Points :0
Contact:

Re: How to use pyGlobalPlatform to execute GET STATUS command

Post by Robert » Wed Dec 02, 2015 8:00 am

This demo is too complicated. And I'm a beginner of python and JavaCard, the following code, I don't understand, can anyone help me?

Code: Select all

if status != -1:
        appsInfo, fileModulesInfo = status
        for appInfo in appsInfo:
            print "AID: %s - PRIV: %02X - LIFE-CYCLE-STATE: %02X" %("".join("%02X" %(ord(b)) for b in appInfo['aid']), appInfo['privileges'], appInfo['lifeCycleState'])
        for fileModuleInfo in fileModulesInfo:
            print "AID: %s - PRIV: %02X" %("".join("%02X" %(ord(b)) for b in fileModuleInfo['aid']), fileModuleInfo['lifeCycleState'])
            for moduleInfo in fileModuleInfo['executableModules']:
                print "    " + "".join('%02X' %(ord(b)) for b in moduleInfo)
               


Why the variable of "status " can not be -1? According to the code, it will be an array?

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: How to use pyGlobalPlatform to execute GET STATUS command

Post by UNKNwYSHSA » Fri Dec 11, 2015 2:06 am

I using the last version. It throw an exception when getStatus function failed. So you can use try: ... except: ... statement to catch this exception. Following is the sample code:
Exception is not caught:

Exception is caught:
You do not have the required permissions to view the files attached to this post. Please login first.
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 6 guests

JavaCard OS : Disclaimer