72

WhatsApp implemented end-to-end encryption (whitepaper) in their latest update.

How is it possible for WhatsApp to send push notifications with message contents to the Apple Push Notification service?

One possible solution would be to send the unencrypted message to APNs from within the app itself but this would be open to abuse and would defeat the purpose of end-to-end encryption.

Update:
I have just tested it a bit more, according to Apple's documentation:

However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

Which I tested, and resulted in me still receiving the plain text push notifications. This would lead me to believe the app is not running in the background to decrypt any notifications received and then repost them.

Update May-2017:

I have now used the VoIP API ( as mentioned in the answers below ) to effectively achieve the same result myself in a demo app. Works very well.

Update July-2017:

Apple no longer allows the usage of the API for push notifications of non-VOIP apps. They do however allow WhatsApp to do it in their infinite fairness.

Update September 2018:

A notification application extension can now be used to decrypt push notifications. However, dynamic libraries are discouraged from use in such extensions so you must have a codebase that can be compiled statically for decryption etc.

Antwan van Houdt
  • 748
  • 1
  • 6
  • 9

2 Answers2

71

WhatsApp could be using VOIP background mode along with PushKit for solving this problem.

Voip pushes are:

  • delivered directly to the app.
  • considered high-priority notifications and are delivered without delay.
  • delivered even if the app was force-quit by the user.

For details refer to Voice Over IP (VoIP) Best Practices

Once the encrypted payload of VOIP push is decrypted they show a “Local Notification” with the decrypted message.

There is one small issue though, PushKit is available only on iOS 8 and later. So, how is Whatsapp doing it for earlier versions of iOS? Well, it isn’t. They don’t allow you to see message preview in notifications on versions earlier that iOS 8 (Verified it on iOS 7, see screenshot)

Whatsapp Settings in iOS 7

Kevin Panko
  • 109
  • 3
Abhay Singh
  • 696
  • 6
  • 4
  • 2
    Just to be clear, this is still conjecture, right? It's a very good explanation and the difference between versions is a nice piece of circumstantial evidence, but it sounds like we still don't know for sure. – octern Apr 06 '16 at 19:28
  • @octern I am planning on attaching LLDB to whatsapp once I get my hands on a jailbroken iphone – Antwan van Houdt Apr 06 '16 at 23:24
  • That makes perfect sense. But why does Threema still claim that there is a [technical limitation](https://threema.ch/en/faq/push_preview)? Or are they just slow/lazy updating their software? – mrclschstr Apr 07 '16 at 10:50
  • 1
    I just wonder why they don't show the name you gave to the contact instead of the username of the sender. Before this feature it was fair, but now its completely possible to show the contact. – Gonzo May 08 '16 at 00:10
  • @AntwanvanHoudt did you happen to test and confirm on a jailbroken phone? Would love to know the results! – smaili May 18 '16 at 16:58
  • @smaili sadly no, I still do not have access to a jailbroken phone. I would still like to investigate this further though. – Antwan van Houdt May 19 '16 at 10:26
  • 1
    In iOS10, WhatsApp may be using `Notification Service Extensions`, using this extension app can receive payload in background, modify/decrypt it and then show it to user. – D4ttatraya Jan 09 '17 at 13:41
  • If you read the apple docs for notification service extensions, it's pretty clear that one of the things they are designed for is encrypted notifications, so it makes sense whatsapp might be using them – Orion Edwards Sep 06 '18 at 02:50
11

What you call Push Notifications (the ones you see in your notification center) are not exactly the same thing as Remote Notifications (the ones sent via APNs).

On Android the two are totally different. First one is called Notification, the second one is called Message or Downstream Message.

But back on iOS the application can generate Local Notifications that will show in your notification center. These don't need to be triggered by any remote notification, it's up to the logic in the app to do it and iOS apps do have the possibility to perform background tasks and sync that can generate these notifications.
Since iOS7, an iOS application can also perform HTTP operations in background for unlimited time (because the application is delegating the network transfer to the system, that will awake the app for a limited amount of time when the transfer is finished).

Remote Notifications, on the other hand, were first designed to send a push directly for APN to the user. But Apple realized the need for developers to send push notifications to their application rather than to the notification center and added a silent flag to Remote Notifications so that the server can send a notification to wake the application without disturbing the user. The application will then perform some synchronization and logic and decide itself to create Local Notications or not (that will show in the notification center).
Besides, Remote Notifications' payload suffered a limit of 256 bytes until recently, which forced many developers to use these notifications as a Push-to-sync message rather than as a data channel.

If you understand me well, then you understand that Whatsapp does not need to send the message payload in the Remote Notifications using APNs.

Thibault D.
  • 465
  • 2
  • 8
  • 2
    I like this answer. I will upvote if you manage to add some references. – GnP Apr 13 '16 at 21:37
  • @gnp Here you go. – Thibault D. Apr 14 '16 at 08:21
  • 1
    Apple's documentation on silent notifications is here: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_updates_to_your_app_silently - and it has the following comment: "The system treats silent notifications as low-priority. You can use them to refresh your app’s content, but the system doesn't guarantee their delivery... ... don't try to send more than two or three silent notifications per hour. " I don't think this would be the avenue that Whatsapp would be using – Orion Edwards Sep 06 '18 at 02:43