Skip to content

Python library to create Apple Passbook (.pkpass) files, modified to take certificates as strings (i.e. from environment variables)

License

Notifications You must be signed in to change notification settings

michaelmcneela/passbook

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Passbook

Passbook

Python library to read/write Apple Passbook (.pkpass) files

If you need the server side implementation (API / WebServices) in django you should check http.//github.com/devartis/django-passbook.

Getting Started

  1. Get a Pass Type Id

Visit the iOS Provisioning Portal -> Pass Type IDs -> New Pass Type ID Select pass type id -> Configure (Follow steps and download generated pass.cer file) Use Keychain tool to export a Certificates.p12 file (need Apple Root Certificate installed)

  1. Generate the necessary certificate and key .pem files
openssl pkcs12 -in "Certificates.p12" -clcerts -nokeys -out certificate.pem 
openssl pkcs12 -in "Certificates.p12" -nocerts -out key.pem
  1. Ensure you have M2Crypto installed
sudo easy_install M2Crypto

Typical Usage

#!/usr/bin/env python

from passbook.models import Pass, Barcode, StoreCard

cardInfo = StoreCard()
cardInfo.addPrimaryField('name', 'John Doe', 'Name')

organizationName = 'Your organization' 
passTypeIdentifier = 'pass.com.your.organization' 
teamIdentifier = 'AGK5BZEN3E'

passfile = Pass(cardInfo, \
    passTypeIdentifier=passTypeIdentifier, \
    organizationName=organizationName, \
    teamIdentifier=teamIdentifier)
passfile.serialNumber = '1234567' 
passfile.barcode = Barcode(message = 'Barcode message')    

# Including the icon and logo is necessary for the passbook to be valid.
passfile.addFile('icon.png', open('images/icon.png', 'r'))
passfile.addFile('logo.png', open('images/logo.png', 'r'))

# Get the certificate strings from environment variables in the PEM format
certificate_string = os.environ['PASSBOOK_CERTIFICATE']
key_string = os.environ['PASSBOOK_KEY']
wwdr_string = os.environ['WWDR_CERTIFICATE']
password = os.environ['PASSBOOK_KEY_PASSWORD']

passfile.create(certificate_string, key_string, wwdr_string, password, 'test.pkpass') # Create and output the Passbook file (.pkpass) 

Note: Getting WWDR Certificate

Certificate is available @ http://developer.apple.com/certificationauthority/AppleWWDRCA.cer It can be exported from KeyChain into a .pem (e.g. wwdr.pem)

Developed by devartis <http://www.devartis.com>.

About

Python library to create Apple Passbook (.pkpass) files, modified to take certificates as strings (i.e. from environment variables)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%