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)