alexandercerutti / passkit-generator

The easiest way to generate custom Apple Wallet passes in Node.js
MIT License
895 stars 109 forks source link

Pass could not be opened #166

Closed axlic closed 1 year ago

axlic commented 1 year ago

Running OS

Current

Running Node Version

NODE 18 LTS

Description

pk pass is generating successfully but when I try to open it, Pass could not be opened error occurred

Screenshot 2023-09-27 at 5 51 48 PM

Code

const express = require('express');
const { PKPass } = require("passkit-generator");
const fs = require("fs");
const path = require("path");

const wwdr = fs.readFileSync(path.resolve(__dirname, "./wwdr.pem"));
const signerCert = fs.readFileSync(path.resolve(__dirname, "./cert.pem"));
const signerKey = fs.readFileSync(path.resolve(__dirname, "./key.pem"));

const app = express();
const port = 3000;

app.get('/', (req, res) => {
    res.json({"test":'Hello World!'});
});

app.get('/pass', async (req, res) => {
    try{
        const pass = await PKPass.from({
            /**
             * Note: .pass extension is enforced when reading a
             * model from FS, even if not specified here below
             */
            model: "./model/DBC.pass",
            certificates: {
                wwdr,
                signerCert,
                signerKey,
                signerKeyPassphrase: '1234'
            },
        }, {
            // keys to be added or overridden
            serialNumber: "AAGH44625236dddaffbda",
            teamIdentifier: "myTeamID",
            webServiceURL: "https://example.com/passes/",
            authenticationToken: "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
            description: "Demo pass",
        });

        pass.primaryFields.push({
            key: "name",
            label: "Name",
            value: "Jon Doe",
        })

        pass.secondaryFields.push({
            key: "bank",
            label: "Bank",
            value: "UBL",
        })

        pass.auxiliaryFields.push({
            key: "balance",
            label: "Balance",
            value: "$10",
        })

        const buffer = pass.getAsBuffer();
        // storage to local file
        fs.writeFileSync("myFirstPass.pkpass", buffer);
        console.log("Pass created successfully");

        res.send('created.')
    }
    catch (error) {
        console.error('Error creating pass:', error);
        res.status(500).send('An error occurred while creating the pass.');
    }
});

app.listen(port, () => {
    console.log(`Server is listening at http://localhost:${port}`);
});

DBC.pass structure

Screenshot 2023-09-27 at 5 55 06 PM

Pass.json

{
    "formatVersion" : 1,
    "passTypeIdentifier" : "pass.com.mycompany.app",
    "teamIdentifier" : "myTeamID",
    "serialNumber" : "12345",
    "barcode" : {
        "message" : "https://downloads.timoliver.com.au/tim-businesscard.pkpass",
        "format" : "PKBarcodeFormatQR",
        "messageEncoding" : "iso-8859-1"
    },
    "organizationName" : "Skyive",
    "description" : "SkyiveBusinessCard",
    "foregroundColor" : "rgb(255, 255, 255)",
    "backgroundColor" : "rgb(20, 20, 20)",
    "labelColor" : "rgb(190, 57, 57)",
    "generic": {
        "primaryFields":[],
        "secondaryFields":[],
        "auxiliaryFields":[]
    }
}
alexandercerutti commented 1 year ago

Hi @axlic, thanks for using passkit-generator!

I don't see anything wrong in your code after a first look. Could you please look at the guide for troubleshooting in the wiki and check if Console.app tells you more information?

https://github.com/alexandercerutti/passkit-generator/wiki/Troubleshooting-(Self-help)#through-console-mac-only

Console.app might give a hint to you where you should look at.

Let me know!

axlic commented 1 year ago

@alexandercerutti in the console I'm seeing this error

Invalid data error reading pass pass.com.company.app/AAGH44625236dddaffbda. The passTypeIdentifier or teamIdentifier provided may not match your certificate, or the certificate trust chain could not be verified.

2nd

ERROR: Error Domain=PKPassKitErrorDomain Code=1 "The pass cannot be read because it isn’t valid." UserInfo={NSLocalizedDescription=The pass cannot be read because it isn’t valid., NSUnderlyingError=0x600002670060 {Error Domain=PKPassKitErrorDomain Code=1 "The passTypeIdentifier or teamIdentifier provided may not match your certificate, or the certificate trust chain could not be verified." UserInfo={NSLocalizedDescription=The passTypeIdentifier or teamIdentifier provided may not match your certificate, or the certificate trust chain could not be verified.}}}

3rd Signature validation: FAILED

the teamID is the same id which I take from developer account. event I recreate the whole things but still I'm getting the same error.

axlic commented 1 year ago

@alexandercerutti

I've another question will my code will only work on MacBook where certificates added in the keychain or it will will on my AWS ubuntu server also?

alexandercerutti commented 1 year ago

@axlic verify through this guide which are your passTypeIdentifier and teamIdentifier in your certificates: https://github.com/alexandercerutti/passkit-generator/wiki/Generating-Certificates#which-passtypeidentifier-and-teamidentifier-am-i-using

I've another question will my code will only work on MacBook where certificates added in the keychain or it will will on my AWS ubuntu server also?

It should work also on AWS.

axlic commented 1 year ago

@alexandercerutti I've checked the certificate the team id and passTypeId is correct

Screenshot 2023-09-27 at 8 18 05 PM
alexandercerutti commented 1 year ago

@axlic if you can confirm the values are fine, I don't have any other clue honestly.

Perhaps, but I don't think so, opening it from the iPhone might give a better error message. For the sake of trying, try to not save it to the disk but serve it directly as HTTP Response.

axlic commented 1 year ago

@alexandercerutti currently I'm using macOS 13.4.1 (c) is is make any problem ?

alexandercerutti commented 1 year ago

It shouldn't. I'm running on the same OS (Ventura) and I have no issues. I still think there might be some unknown (yet) issues with the certificates.

If you are available to send them to me in private (on telegram) I can make some tests and compare them with mine.

axlic commented 1 year ago

give me telegram id

one thing more.. is it make difference using G2, G3 or G5 wwdr certificate?

alexandercerutti commented 1 year ago

You can find the link on my Github profile.

There are differences. Not actually sure which ones (except for G1, which is expired). You should use G4, as also reported in the screenshot you sent me.

axlic commented 1 year ago

@alexandercerutti please check telegram

axlic commented 1 year ago

Thank you @alexandercerutti for creating Awesome package like this, it made my day.

alexandercerutti commented 1 year ago

Glad you solved @axlic ! I will still perform some investigations this evening to check what happened.

It would be awesome if you could leave a ⭐ on the project!