wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

Notifications for end-to-end chat, decrypt once received #935

Closed Pietro-Putelli closed 1 year ago

Pietro-Putelli commented 1 year ago

I have created a chat app and I'm using this library to handle push notifications when users share messages. The is based on the logic of private and public keys, here's the workflow:

  1. Generate a key pair once the user install the app, save locally the PRIVATE_KEY and upload to server the PUBLIC_KEY.
  2. Send encrypted message to the server.
  3. Once the server has received the message, it sends push notifications using the APNs for apple or FMC for google APIs.

The problem arise here, the content of the message is encrypted and the server can't decrypt it before sending the push notification since it doesn't has the PRIVATE_KEY of the user, and it's right.

So my solution is to send background notification to device and once received send a local notification with the decrypted message because I can access to the user's PRIVATE_KEY stored in the app.

The following method works fine to catch the remote background notifications, decrypt the body and send a local notification with readable content to the user:

Notifications.events().registerNotificationReceivedBackground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
      console.log("Notification Received - Background", notification.payload);
      completion({alert: true, sound: true, badge: false});
});

But it only works if the app is open or in background. Is there a way, like instagram or whatsapp do, to catch the remote push notification with encrypted body, decrypt it using local user private key and "update" the push notification content?

I know that a possible workaround is like Tinder does, using "USER sends you a message", but I'd like to make the content visible even if the app is closed.

Thank you.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 1 year ago

The issue has been closed for inactivity.