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)
# Select CAP file
capFile = 'C:\\workspace\\bignumcalc\\bin\\com\\javacard\\bignumcalc\\javacard\\bignumcalc.cap'
loadFileInfo = gp.readExecutableLoadFileParameters(capFile)
packageAID = loadFileInfo['loadFileAID']
appletAID = loadFileInfo['applets'][0]
# Delete the same package which has been already in the card.
try:
ret = gp.deleteApplication(context, cardInfo, securityInfo, packageAID)
except Exception, e:
print e.message
pass
# Install the applet
ret = gp.installForLoad(context, cardInfo, securityInfo, packageAID, gp.AID_ISD, '', '', 0, 0, 0)
if ret == -1:
raise Exception("Install for load failed.")
ret = gp.load(context, cardInfo, securityInfo, '', capFile)
if ret == -1:
raise Exception("Load failed.")
ret = gp.installForInstall(context, cardInfo, securityInfo, packageAID, appletAID, appletAID, 0, 0, 0, 0, '')
if ret == -1:
raise Exception("Install failed.")
# Release context
gp.releaseContext(context)