You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46Lines changed: 46 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -248,5 +248,51 @@ else
248
248
end
249
249
```
250
250
251
+
### End-to-end encryption
252
+
253
+
This library supports end-to-end encryption of your private channels. This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them. You can enable this feature by following these steps:
254
+
255
+
1. Install [Libsodium](https://github.com/jedisct1/libsodium), which we rely on to do the heavy lifting. [Follow the installation instructions for your platform.](https://github.com/RubyCrypto/rbnacl/wiki/Installing-libsodium)
256
+
257
+
2. You should first set up Private channels. This involves [creating an authentication endpoint on your server](https://pusher.com/docs/authenticating_users).
258
+
259
+
3. Next, generate your 32 byte master encryption key, encode it as base64 and pass it to the Pusher constructor.
260
+
261
+
This is secret and you should never share this with anyone.
262
+
Not even Pusher.
263
+
264
+
```bash
265
+
openssl rand -base64 32
266
+
```
267
+
268
+
```rb
269
+
pusher =newPusher::Client.new({
270
+
app_id:'your-app-id',
271
+
key:'your-app-key',
272
+
secret:'your-app-secret',
273
+
cluster:'your-app-cluster',
274
+
use_tls:true
275
+
encryption_master_key_base64:'<KEY GENERATED BY PREVIOUS COMMAND>',
276
+
});
277
+
```
278
+
279
+
4. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
280
+
281
+
5. Subscribe to these channels in your client, and you're done! You can verify it is working by checking out the debug console on the [https://dashboard.pusher.com/](dashboard) and seeing the scrambled ciphertext.
282
+
283
+
**Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
284
+
285
+
**Limitation**: you cannot trigger a single event on multiple channels in a call to `trigger`, e.g.
286
+
287
+
```rb
288
+
pusher.trigger(
289
+
['channel-1', 'private-encrypted-channel-2'],
290
+
'test_event',
291
+
{ message:'hello world' },
292
+
)
293
+
```
294
+
295
+
Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.
0 commit comments