alvinbaena / passkit Goto Github PK
View Code? Open in Web Editor NEWCreate Apple Wallet Passes in Go
License: MIT License
Create Apple Wallet Passes in Go
License: MIT License
Got an error
asn1: structure error: tags don't match (16 vs {class:0 tag:13 length:45 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} certificate @2
on calling passkit.LoadSigningInformationFromFiles()
. Certificate files are valid, I use them for building passes in PHP.
What could that be?
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.
With an exported WWDR certificate (https://www.apple.com/certificateauthority/AppleWWDRCAG4.cer):
signInfo, err := passkit.LoadSigningInformationFromFiles(
"apple.pass/Certificates.p12",
"xxxxxxxx",
"apple.pass/wwdr.pem",
)
if err != nil {
panic(err)
}
2023/11/01 23:56:09 http: panic serving 127.0.0.1:59909: x509: malformed certificate
goroutine 65 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1868 +0xb9
panic({0x1664420?, 0xc000486310?})
/usr/local/go/src/runtime/panic.go:920 +0x270
main.SignAndStore({0x1, {0x17655d1, 0x4}, {0x1774ca0, 0x19}, {0x0, 0x0}, {0x176f8f4, 0x12}, {0x176f906, ...}, ...}, ...)
/Users/theobouwman/dev/projects/momo/momo-wallet-pass-api/pass.go:68 +0x129
main.(*App).Handler(0x18617e0?, {0x18603f0?, 0xc0003d22a0}, 0xc000163100)
/Users/theobouwman/dev/projects/momo/momo-wallet-pass-api/handler.go:40 +0x1e5
net/http.HandlerFunc.ServeHTTP(0xc000163000?, {0x18603f0?, 0xc0003d22a0?}, 0x2f8ea50?)
/usr/local/go/src/net/http/server.go:2136 +0x29
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000ec000, {0x18603f0, 0xc0003d22a0}, 0xc000162f00)
/Users/theobouwman/go/pkg/mod/github.com/gorilla/[email protected]/mux.go:210 +0x1c5
net/http.serverHandler.ServeHTTP({0xc0003fa930?}, {0x18603f0?, 0xc0003d22a0?}, 0x6?)
/usr/local/go/src/net/http/server.go:2938 +0x8e
net/http.(*conn).serve(0xc0001c9320, {0x18617e0, 0xc0003fa3c0})
/usr/local/go/src/net/http/server.go:2009 +0x5f4
created by net/http.(*Server).Serve in goroutine 45
/usr/local/go/src/net/http/server.go:3086 +0x5cb
Upon generating the .pkpass from the file template, the iOS Simulator throws the following error instead of loading the pass:
Failed to add pass: 'file:///Users/dev/Documents/projects/pass/pass.pkpass' Error Domain=PKPassKitErrorDomain Code=1 "No data supplied" UserInfo={NSLocalizedDescription=No data supplied}.
I've used the code from the README to generate the .pkpass:
package main
import (
"archive/zip"
"bytes"
"fmt"
"io/ioutil"
"os"
"github.com/alvinbaena/passkit"
"github.com/google/uuid"
)
func main() {
c := passkit.NewGenericPass()
field := passkit.Field{
Key: "key",
Label: "label",
Value: "value",
}
serial := uuid.NewString()
fmt.Printf("pass id: %s\n", serial)
c.AddHeaderField(field)
c.AddPrimaryFields(field)
c.AddSecondaryFields(field)
c.AddAuxiliaryFields(field)
c.AddBackFields(field)
pass := passkit.Pass{
FormatVersion: 1,
TeamIdentifier: "==TEAM-ID==",
PassTypeIdentifier: "==Pass-Identifier==",
OrganizationName: "orgName",
SerialNumber: serial,
Description: "test",
Generic: c,
Barcodes: []passkit.Barcode{
{
Format: passkit.BarcodeFormatQR,
Message: "1312312312312312312312312312",
MessageEncoding: "utf-8",
},
},
}
template := passkit.NewFolderPassTemplate("passes/mypass.pass")
signInfo, err := passkit.LoadSigningInformationFromFiles("certs/passmaker.p12", "test", "certs/wwdr.cer")
signer := passkit.NewMemoryBasedSigner()
if err != nil {
panic(err)
}
fmt.Print("Pass signed\n")
z, err := signer.CreateSignedAndZippedPassArchive(&pass, template, signInfo)
if err != nil {
fmt.Println("Error creating archive:", err)
return
}
fmt.Print("Archive Created\n")
err = os.WriteFile("pass.pkpass", z, 0644)
if err != nil {
panic(err)
}
fmt.Print("Finished creating pass\n")
}
No certificate errors are being thrown, so I think it's safe to say it's not related to certificates/signing.
I'm using the the Generic.pass from Apple as a template, and replaced the values of the JSON with the above fields. I also printed the contents of the pass.json after it was loaded into memory and all the fields were filled out as they were supposed to be, but I still get this error.
Thanks for the great package! Noticed there was no License attached to it.
Can one be added? MIT?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.