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 execute GET STATUS command

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 execute GET STATUS command

Postby 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

Postby 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: 628
Joined: Thu May 21, 2015 4:05 am
Points: 2979
Contact:

Re: How to use pyGlobalPlatform to execute GET STATUS command

Postby 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:
getStatus.png

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


Return to “pyGlobalPlatform”

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer