hs-pkpass-0.4: A library for Passbook pass creation & signing

Safe HaskellNone

Passbook

Contents

Description

This module provides different functions to sign a Passbook Pass.

Please read the documentation!

One set of functions uses the signpass tool included in Apple's Passbook Support Materials to sign the pass. This uses the system keychain directly, but works on OS X only.

The other set of functions uses OpenSSL instead, in this case you need to export your certificate using the process described in the OpenSSL section of this document.

If you want to use this module with an existing .pkpass file, you can import it using the function loadPass. Please note that you still need to provide the assets in a separate directory, loadPass only parses the pass.json file.

Using these function is very simple, assuming you have created a Pass called myPass and you have the related assets (e.g. the logo.png and icon.png files) stored in a folder named myPass/.

You want the signed pass to be stored in a folder called passes/. You call signpass like this:

 (path, passId) <- signpass "myPass" "passes" myPass

You will find the pass at path with the filename passId.pkpass. Using the types from Passbook.Types ensures that passes are generated correctly.

Please note that an icon.png file must be present in your asset folder, otherwise the generated pass will not work. This is not checked by this module.

Refer to Apple's Passbook documentation at https://developer.apple.com/passbook/ for more information or to retrieve the signpass tool which is included in the Passbook Support Materials. (iOS Developer Membership necessary)

Synopsis

Sign using signpass

These functions sign a Pass using the signpass tool provided by Apple in the Passbook Support Materials. You can find those at https://developer.apple.com/passbook/ however, an iOS Developer Membership is necessary for the download.

The signpass utility needs access to your keychain. OS X will prompt you for this the first time you run the tool.

Please make sure that the signpass tool is within your $PATH. These functions work on OS X only.

signpassSource

Arguments

:: FilePath

Input file path (asset directory)

-> FilePath

Output file path

-> Pass

The pass to sign

-> IO (FilePath, Text)

The filepath of the signed .pkpass and its UUID

Takes the filepaths to the folder containing the path assets and the output folder, a Pass and uses a random UUID to create and sign the pass.

Important: OS X only!

signpassWithIdSource

Arguments

:: Text

The pass ID

-> FilePath

Input file path (asset directory)

-> FilePath

Output file path

-> Pass

The pass to sign

-> IO FilePath 

Signs the Pass using the provided ID, no random UUID generation happens here.

Important: OS X only!

signpassWithModifierSource

Arguments

:: FilePath

Input file path (asset directory)

-> FilePath

Output file path

-> Pass

The pass to sign

-> (Text -> Pass -> Pass)

Modifier function

-> IO (FilePath, Text)

The filepath of the signed .pkpass and its UUID

Works like signpass, except for the fourth argument which is a modifier function that updates the pass with the generated UUID. This is useful for cases where you want to store the UUID in the barcode or some other field on the pass as well.

An example function for use with this is updateBarcode.

Important: OS X only!

Sign using OpenSSL

These functions sign a Pass using OpenSSL. They work on operating systems other than OS X as well. To use these you need to export your certificate from the keychain. Assuming you have saved the certificatea as cert.p12 , the conversion works like this:

 $ openssl pkcs12 -in cert.p12 -clcerts -nokeys -out certificate.pem
 $ openssl pkcs12 -in cert.p12 -nocerts -out keypw.pem

Enter a password for your key file, you will only need this once in the next step. Then strip the password from your key file using:

 $ openssl rsa -in keypw.pem -out key.pem

Important: All paths passed to these functions must be absolute.

signOpenSource

Arguments

:: FilePath

Input file path (asset directory)

-> FilePath

Output folder

-> FilePath

Certificate

-> FilePath

Certificate key

-> Pass

The pass to sign

-> IO (FilePath, Text)

The signed .pkpass file and ID

Takes the filepaths to the folder containing the path assets and the output folder, the paths to the certificate and the key, a Pass and uses a random UUID to create and sign the pass.

signOpenWithModifierSource

Arguments

:: FilePath

Input file path (asset directory)

-> FilePath

Output folder

-> FilePath

Certificate

-> FilePath

Certificate key

-> Pass

The pass to sign

-> (Text -> Pass -> Pass)

Modifier function

-> IO (FilePath, Text)

The signed .pkpass file and ID

Works like signOpen, except for the fourth argument which is a modifier function that updates the pass with the generated UUID. This is useful for cases where you want to store the UUID in the barcode or some other field on the pass as well.

An example function for use with this is updateBarcode.

signOpenWithIdSource

Arguments

:: FilePath

Input file path (asset directory)

-> FilePath

Output folder

-> FilePath

Certificate

-> FilePath

Certificate key

-> Pass

The pass to sign

-> Text

The pass ID

-> IO FilePath

The signed .pkpass file

Signs the Pass using the provided ID, no random UUID generation happens here.

Helper functions

genPassId :: IO TextSource

Generates a random UUID for a Pass using Data.UUID and System.Random

updateBarcode :: Text -> Pass -> PassSource

Updates the barcode in a pass with the UUID. This can be passed to signpassWithModifier or signOpenWithModifier.

loadPassSource

Arguments

:: FilePath

Location of the .pkpass file

-> IO (Maybe Pass) 

Tries to parse the pass.json file contained in a .pkpass into a valid Pass. If Passbook accepts the .pkpass file, this function should never return Nothing.