Skip to main content

Encryption and your users in mobile apps

Markdown

What your app sends and receives through WordPlus Cloud is sealed, as in a browser: the realtime servers carry it, and keep the history of a room, without being able to read or change it. The app gets its keys from your server only, with the settings it signs in with or from your keys route, and opens everything before your code sees it.

What is sealed​

WhatSealed withWho can open it
Events to a room, from your server, an app or a page, and its kept historythe room keywhoever the room rule lets in
The info of a presence memberthe room keythe same
Events your server sends a user (toUser)the key of the userthe apps and pages of that user
Your users in the directorythe day keyeveryone your app knows
The media of a call between two people, and of a group call encrypted end to enda key for that callits people

A room your server declares public: true is not sealed, and neither is one with seal: false. The realtime servers see room names, event names, user ids, which key a value needs, and sealed values. They never hold a key.

Calls and live streams​

In Capacitor and in React Native, as in a browser:

  • A call between two people is encrypted end to end on every path: direct between the two, through our relays, or through our media servers.
  • A group call is encrypted end to end when your server says so, with encrypt: true in its token or its rule (permissions).
  • A live stream is not encrypted end to end: its picture and its chat are for everyone watching, so they are encrypted on the way, and the media servers see them.

In React Native, calls and streams come from @wordplus/realtime-react-native, on iOS for now (calls).

Sealing needs random numbers​

React Native has no crypto.getRandomValues, which sealing needs in rooms: import react-native-get-random-values first, before anything else, in index.ts. connect() of @wordplus/realtime/native says so if it is missing. The Capacitor web view has it.

Keys and sign-in​

  • Give the app the user keys with its sign-in: your server config( user ) has them, and connect() takes them as keys, so the app connects with no request first.
  • Keys renew by themselves: the app asks your keys route (/api/realtime/keys, with its token) for any it lacks, such as the key of the next day or of a room.
  • Losing access: when your server moves on the key of a room or of a user, the app no longer opens what comes (encryption in depth).

Signing out​

The app calls rt.close() when its user signs out, before another user signs in on it: it closes the connection and forgets the keys of the app. Under a RealtimeProvider, rendering it for nobody, or taking it away, does the same.

Your users​

The app reads the directory as a page does:

const users = await rt.users( [ 34 ] );   // { 34: { user_id: 34, name: 'Ann', avatar: '…' } }

A user is in it once they have connected with an identity your server signed (the app sends theirs with its keys), so show a name of your own until then, and ask again when they come online.

The key derivation, and every label: encryption in depth.