alvinbaena / passkit

Create Apple Wallet Passes in Go
MIT License
95 stars 33 forks source link

x509: malformed certificate #10

Closed theobouwman closed 10 months ago

theobouwman commented 10 months ago

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/mux@v1.8.0/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
alvinbaena commented 10 months ago

I see you have converted the WWDC certificate to PEM format. The code only supports reading the certificate in CER format, which is the one the it's originally in.

Could you try again using the certificate without converting it?

theobouwman commented 10 months ago

@alvinbaena yes it fixed the issue thanks!

But the generated .pkpass is invalid:

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:     "xxxxxx",
        PassTypeIdentifier: "xxxxxx",
        OrganizationName:   "xxxxxx",
        SerialNumber:       "1234",
        Description:        "Card",
        BoardingPass:       c,
        Barcodes: []passkit.Barcode{
            {
                Format:          passkit.BarcodeFormatQR,
                Message:         "https://example.com/1234",
                MessageEncoding: "utf-8",
            },
        },
    }
alvinbaena commented 10 months ago

I will close this issue, and continue on the other one you have opened (#11) .