1

I'm having issues with node.js sending push notifications, I think because I'm doing something wrong with my APN certificate thats generated in my apple developer account. Im getting this error from Node.js.

VError: Failed to generate token: error:0906D06C:PEM routines:PEM_read_bio:no start line

I'm not sure I've generated the right file in the apple developer account. See below screenshot, when i click download this gives me a "aps.cer" file which is what i'm putting in my node.js project and using with node-app module. Here is how im setting it in my code:

let options = {
        token: {
            key: "aps.cer",
            keyId: "singlemeout.Single-Me-Out",
            teamId: "Team Name"
        },
        production: false
    };

Here is a screen shot of my certificate.

enter image description here

croc_hunter
  • 285
  • 3
  • 12

1 Answers1

2

You are providing node-apn with a token-based configuration, while you are using certificates.

If you want to keep using certificates:

  • the certificate should be in PEM format.

    You can do the conversion like this:

    openssl x509 -inform DER -in aps.cer -out certificate.pem
    
  • you need to provide the key, either by adding it to the certificate, or by providing it as a separate file

  • you need to use the cert, key and or pfx properties in your config object rather than token.key etc.

    let options = {
            cert: "certificate.pem",
            key: "privatekey.pem"
        };
    

Alternatively, you can switch to using tokens.

See https://github.com/node-apn/node-apn/blob/master/doc/provider.markdown for full details.

Also your production property is not consistent with the certificate used.

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • Thanks for the reply. I have a couple questions; What file do i use for the "key" file, is that the original aps.cer file that i have? Or a different file? Also, after i generate the "certificate.pem" file, how would i define the options variable in my node code? Something like this? let options = { token: { keyId: "singlemeout.Single-Me-Out", teamId: "Team Name" }, cert: "certificate.pem", production: true }; – croc_hunter Jan 03 '18 at 16:22
  • The private key you generated at the same time as the certificate request you uploaded to get your certificate. I don't use the standard Apple procedure and generate it using openssl, but it should be in your Keychain and you will need to export it. I have updated the answer to be more explicit regarding how you should specify the cert and key filenames. – jcaron Jan 03 '18 at 16:26
  • OK, I found the Apple Push Services certificate in my keychain, which I exported as a .pem into my project directory, but now i get this error when in run node. Error: error:0906D06C:PEM routines:PEM_read_bio:no start line – croc_hunter Jan 03 '18 at 16:42
  • I actually looked at both files, and the file in my key chain is identical to the certificate.pem file (this is the .cer that i converted to the .pem using openssl). – croc_hunter Jan 03 '18 at 16:49
  • It's not the certificate you need to export, it's the private key. Or both at the same time. – jcaron Jan 03 '18 at 16:55
  • Sorry for all the questions, but how do i do that? I only see Apple Push Services certificate in my keychain, and when I try export this, there are 3 options: .cer, .pem, or certificate bundle .p7b. Do you mean the p7b file, and once i have that how do i extract the private key from it? – croc_hunter Jan 03 '18 at 17:00
  • I never use Keychain access for that, but I believe it should be in the "login" keychain (top left), in the "Keys" Category (bottom left). Select it, right-click for export. You probably need to export is as .p12 and then convert it. – jcaron Jan 03 '18 at 17:07
  • Ah found it. Thanks! Yes, it was a .12 and i converted it to a .pem and its working. – croc_hunter Jan 03 '18 at 17:11