Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox push notifications - send data via curl

Mozilla Firefox since 44 version (unlike 49 version of Google Chrome) supports push-notifications with payload. One can see examples here.

Firefox demo project, which is mentioned on Firefox wiki page, generates curl run parameters as:

curl -I -X POST --header "ttl: 60" "https://updates.push.services.mozilla.com/push/gAAAAABW4ccaidtFYOP2m56-XiY_NSKDXV1QiJ-4cpZG5BF-W7FjWE17SDt-h-b4b4VJamuvL30OcI9msyM1bupE9YHrwQZH4D7Uh2YS8cE_Tpvnvm3CgpBjblH58sE78HQjjbahB5NG4CkkKLj13gz0eB9mOAVGfcM3qo4Z61M5fn_6HZqLvCg="

Now how to add payload to curl, which will be delivered to registered service-worker?

like image 538
Maxim Korobov Avatar asked Mar 11 '16 21:03

Maxim Korobov


1 Answers

It isn't simple because the payload needs to be encrypted.

If you're just interested in testing the functionality out, I recommend trying this page. At the end, if you follow the steps, it prints the curl command to send a notification.

If you want to learn more about how to encrypt the payload, there's the standard here.

If you want to use a Node.js library that hides the complexity to send the payload, there's the web-push library.

Assuming:

  • p256dh key = BPdbyNlxaH6zreGrZfHWtct8xVR9g1LjOagGsdyxllxT-BsWC5zFBlp4AsD4uXZ3kAA6zfqQPLoLxEklSI2muoU
  • salt = FD9bsatP7pGf6qeO_XVu_Q
  • local key = BMGAejiMWatMYFfEdV-YIZpbMeW9N41tav6DW_S7eNRP6In9wwKs-XpKGGkxZUI3-bPti5HBBLY1E8uVRlsF6FE

An example command would be:

echo -ne "\x12\xdb\xd8\xc5\xcc\x92\x0f\xf2\xa5\x9d\x8c\xca\xea\x58\x13\xf6\xbd\x9a\x14\xa5\xca\x6f\xa0\xb3\x6c\x73\x32\x4a\x4e\x03\x55\x8c\x11\x62\x45\x8d" > encrypted.data; curl -v -X POST https://updates.push.services.mozilla.com/push/v1/SUBSCRIPTION_ID_HERE -H "encryption-key: keyid=p256dh;dh=BMGAejiMWatMYFfEdV-YIZpbMeW9N41tav6DW_S7eNRP6In9wwKs-XpKGGkxZUI3-bPti5HBBLY1E8uVRlsF6FE" -H "encryption: keyid=p256dh;salt=FD9bsatP7pGf6qeO_XVu_Q" -H "content-encoding: aesgcm128" -H "TTL: 60" --data-binary @encrypted.data
like image 60
Marco Castelluccio Avatar answered Nov 09 '22 01:11

Marco Castelluccio