In order to thank you for all members' support of our website, we are holding new events - Getting Free Samples by Paying Freight only.
Want to get free samples? Please check this post for more details.

How to use pyGlobalPlatform to execute GET STATUS command

pyGlobalPlatform is a open source python library of globalplatform client library.
User avatar
JavaCardOS
Posts: 263
Joined: Thu Apr 30, 2015 12:00 pm
Points :2295
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 :3023
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 1 guest

JavaCard OS : Disclaimer