End-to-end encryption in a chat app

Security Senior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

With end-to-end encryption, how do you show message previews in push notifications?

Options
Hint 1 of 1

Which part of the app runs when a push arrives?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Send an encrypted payload with mutable-content, and decrypt it in a Notification Service Extension with keys from a shared Keychain group

Correct. The server never sees plaintext, and the user still sees the preview.

Why not the others?
  • B Have the server include a plaintext preview. The server would read the message, which breaks E2EE.
  • C Show only 'New message' forever. It's secure, but gives up a feature the extension can provide.
  • D Decrypt only after the user opens the app. Previews would never appear in the notification.

30-second answer

The server can't read messages, so everything that needs plaintext moves to devices: search, previews, link previews and moderation signals. Keys are generated and kept on each device in the Keychain or Secure Enclave, with a protocol for key exchange, multi-device and recovery. Push notifications carry encrypted payloads that a Notification Service Extension decrypts before display.

Practise saying it · 60 s. No recording, just a timer

Explain how E2EE changes the architecture.

Say your answer out loud, then check which of these points you covered:

  • Keys on device
  • Client-side search and previews
  • Service extension for pushes
  • Multi-device keys

Deep dive

Use a proven protocol (such as the Signal protocol or MLS), never a home-made one.

Show safety numbers or key change warnings.

Backups need their own encryption key, or they break E2EE.

Share keys with extensions through a Keychain access group.

Common mistakes

  • Sending plaintext previews in push payloads.
  • Designing custom cryptography.

Senior take & follow-ups

Seniors list what moves to the client and how keys are managed across devices.

Follow-up questions

Think of your answer first, then open the hint.

  1. How do new devices read old messages?

    Show hint

    Encrypted backups or transfer from an existing device.

  2. How does search work?

    Show hint

    On-device indexes over decrypted messages.

Suggest a fix if something here is wrong or out of date.