alexandercerutti / passkit-generator

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

Invalid PEM formatted message #10

Closed adrienafl closed 5 years ago

adrienafl commented 5 years ago

Hi !

I'm trying to use your lib but I'm not able to get it working.

I try to run a basic example

const { Pass } = require("passkit-generator");

let pass = new Pass({
    model: "./passModels/myFirstModel",
    certificates: {
        wwdr: "./certs/wwdr.pem",
        signerCert: "./certs/signercert.pem",
        signerKey: {
            keyFile: "./certs/signerkey.pem",
            passphrase: "pass"
        }
    }
});

// Adding some settings to be written inside pass.json
pass.localize("fr");
pass.barcode("36478105430"); // Random value

// Generate the stream, which gets returned through a Promise
pass.generate()
    .then(stream => {
        console.log(stream);
    })
    .catch(err => {
        console.log(err);
    });

I get the following error :

Error: Error: Invalid PEM formatted message. at readCertificates.then.then.catch (/Users/aflalo/node_modules/passkit-generator/src/pass.js:68:11)

I tried to log the Certificate object created before readind :

{ _raw: { wwdr: './certs/wwdr.pem', signerCert: './certs/signercert.pem', signerKey: { keyFile: './certs/signerkey.pem', passphrase: 'pass' } } }

Any clue ? Thanks

alexandercerutti commented 5 years ago

Hi! I'll try to do my best to help you! Do you have ./certs folder with the files, do you? The Certificate variable is okay. The error is related to a bad-formatted PEM file. You have to check if the content of the keys.

Try to execute this command on the signerkey.pem and signercert.pem and see if they have any content.

$ openssl x509 -in filename.pem -noout -text

Which procedure did you follow to get the two files? The one for macOS or the one not for macOS? Or can you upload the two files here?

adrienafl commented 5 years ago

Thanks for your quick answer. I notices that the signerkey.pem is wrong. Are you sure about the command to generate it ?

I successfuly read the signercert.pem and wwdr.pem and to read the signerKey I used

openssl rsa -in signerKey.pem -text

and it worked

And to generate the file I used

$ openssl pkcs12 -in Certificates-pass.p12 -nocerts -out signerKey.pem -passin pass:1234 -passout pass:password

Returns

MAC verified OK

[Edited since I found the appropriate command to read the file generated] To decrypt I used $ openssl x509 -in signerKey.pem -passin pass:password

Returns

For information the result is : unable to load certificate 4677650028:error:09FFF06C:PEM routines:CRYPTO_internal:no start line:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.230.1/libressl-2.6/crypto/pem/pem_lib.c:683:Expecting: TRUSTED CERTIFICATE

Thanks for helping.

PS : I successfully generate my passes with the signpass binary provided by apple so my guess is a wrong key transformation for usage with the lib

adrienafl commented 5 years ago

Ok, I changed something I just don't know why but now it's working...

Thanks !

alexandercerutti commented 5 years ago

Well, yeah, I'm sure about the command. You used the "non-macOS-steps", right? Because the command you told me you used, is the same I putted in the "macOS steps". I'd like to better understand for the future. 😊

Aitorgb commented 2 years ago

Hi! I have the same problem.

My code is :

let pass = new PKPass(
    {
        model: './card.pass',
        icon: './public/images/icon.png',
        icon2x: './public/images/icon@2x.png',
        logo: './public/images/logo.png'
    },
    {
        wwdr: './certs/wwdrr.pem',
        signerCert: './certs/signercert.pem',
        signerKey: './certs/signerkey.pem'
    }
);

    pass.type = 'storeCard';
    pass
        .getAsStream()
        .then((stream) => {
            console.log(stream);
        })
        .catch((err) => {
            console.log(err);
        });

The error is

Error: Invalid PEM formatted message. at Object.pem.decode (/Users/aitor/Documents/Tangram Publicidad y YOYO/tarjetas-virtuales/virtual-card/node_modules/node-forge/lib/pem.js:192:11)

I execute this command openssl x509 -in filename.pem -noout -text

The signerKey.pem not working.

Any clue ? Thanks

alexandercerutti commented 2 years ago

Hey @Aitorgb, this is a quite-old thread. Also, I'm not sure which version of passkit-generator are you using. That seems a hybrid of v2 and v3. I suggest you look at examples, read the documentation I wrote in the wiki, and all the docs available. If you still have issues, please open another issue thread and we can talk about it there. 😉

Hint: Passkit-generator v3 does not support paths for certificates. Hint2: try to run examples with your data, so you can be sure your certificates are working

midoshawky commented 1 year ago

@Aitorgb Hi did u manage to bypass this? because im facing same issue now signerKey is not opening and it has issue