Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass could not be opened #11

Open
theobouwman opened this issue Nov 3, 2023 · 4 comments
Open

Pass could not be opened #11

theobouwman opened this issue Nov 3, 2023 · 4 comments

Comments

@theobouwman
Copy link

Screenshot 2023-11-03 at 12 23 51
c := passkit.NewBoardingPass(passkit.TransitTypeAir)
	field := passkit.Field{
		Key:   "name",
		Label: "Name",
		Value: passInfo.name,
	}

	c.AddHeaderField(field)
	c.AddPrimaryFields(field)
	c.AddSecondaryFields(field)
	c.AddAuxiliaryFields(field)
	c.AddBackFields(field)

	pass := passkit.Pass{
		FormatVersion:      1,
		TeamIdentifier:     "xxxx",
		PassTypeIdentifier: "xxxx",
		OrganizationName:   "xxxx",
		SerialNumber:       "1234",
		Description:        "Card",
		BoardingPass:       c,
		Barcodes: []passkit.Barcode{
			{
				Format:          passkit.BarcodeFormatQR,
				Message:         "xxx",
				MessageEncoding: "utf-8",
			},
		},
	}

template := passkit.NewInMemoryPassTemplate()

iconUrl, _ := url.ParseRequestURI("xxxx")
template.AddFileFromURL(passkit.BundleIcon, *iconUrl)
template.AddFileFromURL(passkit.BundleThumbnail, *iconUrl)

signer := passkit.NewMemoryBasedSigner()
	signInfo, err := passkit.LoadSigningInformationFromFiles(
		"apple.pass/Certificates.p12",
		"xxxx",
		"apple.pass/wwdr.cer",
	)
	if err != nil {
		panic(err)
	}

	z, err := signer.CreateSignedAndZippedPassArchive(&pass, template, signInfo)
	if err != nil {
		panic(err)
	}

	err = os.WriteFile("pass.pkpass", z, 0644)
	if err != nil {
		panic(err)
	}

The pass.pkpass file is created.

unzip pass.pkpass 
Archive:  pass.pkpass
  inflating: signature               
  inflating: icon.png                
  inflating: thumbnail.png           
  inflating: pass.json               
  inflating: manifest.json           

And all files are included.

@alvinbaena
Copy link
Owner

When signing the pass you have to make sure that the signing certificate, downloaded from the developer portal, is not modified or chained with any other certificates. You have to use it as is.

Have you added the pass certificate into the PKCS12 store with other certificates?, this will not work as the signature will be different.

@theobouwman
Copy link
Author

Steps:

  1. Download Pass Type ID certificate from Apple Portal with these steps (https://www.walletthat.com/help/creating-a-pass-type-id-pass-signing-certificate/)
  2. Download wwdr.cer from Apple Portal
  3. And run the code I already gave.

So where is it going wrong?

@theobouwman
Copy link
Author

When signing the pass you have to make sure that the signing certificate, downloaded from the developer portal, is not modified or chained with any other certificates. You have to use it as is.

Have you added the pass certificate into the PKCS12 store with other certificates?, this will not work as the signature will be different.

To get a .p12 file you must open the .cer file from the portal and export it as .p12 right?

@alvinbaena
Copy link
Owner

alvinbaena commented Dec 16, 2023

Sorry for my late response.

If I recall correctly you have to add it to your machine's keychain, as stated on the link you provided, and then export it as a p12 file. When exporting the certificate chain you must only include the certificate for your pass (with it's respective private key) on the p12 file. This means no other pass certificates should be included in the p12 file.

Also, if you haven't, please update the library code. Recently there have been some community contributions regarding the certificate signing process.

Also, please try using the updated example and see if the error persists. This new example uses fields with different keys, this may be the error you're seeing.

c := passkit.NewBoardingPass(passkit.TransitTypeAir)

// Utility functions for adding fields to a pass
c.AddHeaderField(passkit.Field{
    Key: "your_head_key",
    Label: "your_displayable_head_label",
    Value:"value",
})
c.AddPrimaryFields(passkit.Field{
    Key: "your_prim_key",
    Label: "your_displayable_prim_label",
    Value:"value",
})
c.AddSecondaryFields(passkit.Field{
    Key: "your_sec_key",
    Label: "your_displayable_sec_label",
    Value:"value",
})
c.AddAuxiliaryFields(passkit.Field{
    Key: "your_aux_key",
    Label: "your_displayable_aux_label",
    Value:"value",
})
c.AddBackFields(passkit.Field{
    Key: "your_back_key",
    Label: "your_displayable_back_label",
    Value:"value",
})

pass := passkit.Pass{
    FormatVersion:       1,
    TeamIdentifier:      "TEAMID",
    PassTypeIdentifier:  "pass.type.id",
    AuthenticationToken: "123141lkjdasj12314",
    OrganizationName:    "Your Organization",
    SerialNumber:        "1234",
    Description:         "test",
    BoardingPass:         c,
    Barcodes: []passkit.Barcode{
        {
            Format:          passkit.BarcodeFormatPDF417,
            Message:         "1312312312312312312312312312",
            MessageEncoding: "utf-8",
        },
    },
}

@alvinbaena alvinbaena reopened this Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants