Page MenuHomePhabricator

Implement main <-> renderer IPC and use it to decrypt notifications
ClosedPublic

Authored by marcin on Nov 23 2023, 9:01 AM.
Tags
None
Referenced Files
F3390016: D9964.diff
Fri, Nov 29, 9:40 PM
Unknown Object (File)
Mon, Nov 18, 5:31 AM
Unknown Object (File)
Oct 30 2024, 9:21 PM
Unknown Object (File)
Oct 3 2024, 7:30 AM
Unknown Object (File)
Oct 2 2024, 3:23 AM
Unknown Object (File)
Oct 2 2024, 3:23 AM
Unknown Object (File)
Oct 2 2024, 3:23 AM
Unknown Object (File)
Oct 2 2024, 3:23 AM
Subscribers

Details

Summary

This differential implements main <-> rendered IPC and uses it combined with decryption function from previous differential to decrypt notifications. In
summary notification decryption workflow is as follows:

  1. Desktop code in push-notifications.js receives notification and checks that it is encrypted (encryptedPayload) field.
  2. Sends decrypted payload to renderer process (web app) using onEncryptedNotification IPC.
  3. Renderer receives it in callback registered in push-notifs-handler.js in web code. In this callback it decrypts payload using decryptDesktopNotification

function.

  1. Decrypted notification is sent to main process using showDecryptedNotification IPC.
  2. Main process receives decrypted notification in ipcMain.on('show-decrypted-notification', (...) => {...}) where it shows notification.
Test Plan
  1. Apply this patch to local keyserver (it basically enables session establishment for desktop device and encrypts notification):

https://gist.github.com/marcinwasowicz/2df9c9bd4491862173241744d54a016f

  1. Send some notifications.
  2. Ensure they are correctly displayed and olm session version for currently logged user in desktop app increments with each notification.

With this differential we can also test large influx of out of order notifications (https://linear.app/comm/issue/ENG-5385/handle-large-number-of-out-of-order-notifications-incoming-afer-long).

  1. Apply this patch on top of first patch to your local keyserver (it artificially calls multiple sendPushNotifs promises on single message): https://gist.github.com/marcinwasowicz/673b62b70998588a7e6f4be31bddd2c8
  2. Send message.
  3. Ensure all notifications that arrive are correctly decrypted.

Diff Detail

Repository
rCOMM Comm
Branch
marcin/eng-5383
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Accepting, but please fix the issues in inline comments.

web/push-notif/push-notifs-handler.js
49–57

electron?.onX functions return a function that unregister the listener.
This is the () => void in electron-types.js and return () => ipcRenderer.removeListener('on-encrypted-notification', withEvent); in preload.js

We can return a cleanup function from useEffect to be called whenever we re-run it.

Alternatively we can write

React.useEffect(() => {
   const cleanupFunction = electron?.onEncryptedNotification(...);
   return cleanupFunction;
}, [staffCanSee])
55

I don't think this await is needed here

This revision is now accepted and ready to land.Nov 24 2023, 6:13 AM
web/push-notif/push-notifs-handler.js
49–57

Your first suggestion results in eslint error:

React Hook useEffect received a function whose dependencies are unknown. Pass an inline function instead.

That said I went ahead with the second option.

web/push-notif/push-notifs-handler.js
49–57

Please ignore the comment above - it resulted from my mistake.

Return cleanup function fore effect