node-apn / node-apn

:calling: Apple Push Notification module for Node.js
MIT License
4.37k stars 681 forks source link

endpoint error: unable to get local issuer certificate UNABLE_TO_GET_ISSUER_CE RT_LOCALLY for VOIP #696

Open dewijones92 opened 3 years ago

dewijones92 commented 3 years ago

Hi I am having a problem sending VOIP notifications. I am using voip_services.cer of Certificate Type - VoIP Services I used my keychain to export the Certificates.p12 file

I then used used the following commands (thanks to https://alexanderpaterson.com/posts/send-ios-push-notifications-with-a-node-backend) $ openssl x509 -in voip_services.cer -inform DER -outform PEM -out cert.pem $ openssl pkcs12 -in Certificates.p12 -out key.pem -nodes

Here is my code:

    const production = true;

    const configs: ProviderOptions [] = [
      {
        cert: path.resolve(baseDir, certFileName ),
        key: path.resolve(baseDir, keyFileName ),
        production,
    } ]

    configs.map(conf  => {
      console.log(`------------------------`)
      console.log(`usedConfig: ${JSON.stringify(conf)}`);
      const apnProvider = new apn.Provider(conf);
      const note = new apn.Notification();

      const recepients: string[] = [];
      recepients.push(apn.token('DEVICE_TOKEN'));

      note.topic = 'packagename.voip'; // you have to add the .voip here!!

      note.expiry = Math.floor(Date.now() / 1000) + 60; // Expires 1 minute from now.
      note.badge = 3;
      note.sound = "ping.aiff";
      note.alert = " You have a new message";
      note.payload = {'messageFrom': 'Rahul test apn'};
      note.priority = 10;

      apnProvider.send(note, recepients).then((reponse) => {
        console.log(`-----------------------___RESULT__-----------------------------`);
        console.log(`DEWI SENDT NOTIF`);
        console.log(`${JSON.stringify(conf)}`);
        console.log(`${ JSON.stringify( reponse ) }`);
      }).catch(e => {
        console.log(`apn provider error: ${JSON.stringify( e )}`)
      });
    });

But I can't get it working. Here is the error I get:

{"sent":[],"failed":[{"device":"DEVICE_TOKEN","error":{"jse_shortmsg":"endpoint error","jse_cause":{"code":"UNABLE_TO_GET_ISSUER_CE
RT_LOCALLY"},"jse_info":{},"message":"endpoint error: unable to get local issuer certificate"}}]}

Any idea on how to fix unable to get local issuer certificate ? Many thanks

origamih commented 3 years ago

I got the same problem fixed by upgrading (downgrading for some cases) node to v12