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 upload and install applet

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

How to use pyGlobalPlatform to upload and install applet

Postby JavaCardOS » Tue Nov 24, 2015 8:35 am

Here is the code implementing how to upload and install applet into java card via pyGlobalPlatform.

Code: Select all

# Import the module
import globalplatformlib as gp

# EstablishContext
context = gp.establishContext()

# Select smartcard reader
readernames = gp.listReaders(context)

# 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.
    ret = gp.deleteApplication(context, cardInfo, securityInfo, packageAID)
except Exception, e:
    print e.message

# 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

Posts: 15
Joined: Wed Aug 19, 2015 3:11 am
Points: 48

Re: How to use pyGlobalPlatform to upload and install applet

Postby nobody2015 » Tue Dec 01, 2015 11:46 pm

Is there have the API function descriptions about this pyGlobalPlatform library?

Return to “pyGlobalPlatform”

Who is online

Users browsing this forum: No registered users and 0 guests

JavaCard OS : Disclaimer