Firefox push notifications - sending data via curl

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

Firefox demo project mentioned in the Firefox wiki creates curl launch options like:

 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 a payload to curl that will be delivered to a registered service-worker ?

+5
source share
1 answer

This is not easy, because the payload must be encrypted.

If you are just interested in checking out the functionality, I recommend trying this page . In the end, if you follow the steps, it prints a curl command to send a notification.

If you want to know more about how to encrypt a payload, click here .

If you want to use the Node.js library, which hides the complexity of sending the payload, there is a web push library .

Assuming that:

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

Command example:

 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 
+5
source

Source: https://habr.com/ru/post/1244921/


All Articles