From 626da89a3a71b74b82d420aa72d53057a7513105 Mon Sep 17 00:00:00 2001 From: Danielle Vass Date: Mon, 6 Apr 2020 15:59:47 +0100 Subject: [PATCH 1/6] add some Private Encrypted Channels docs --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 4bba7c46..c92cf7a0 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ This README covers the following topics: - [Subscribing to channels](#subscribing-to-channels) - [Public channels](#public-channels) - [Private channels](#private-channels) + - [Private encrypted channels](#private-encrypted-channels) - [Presence channels](#presence-channels) - [The User object](#the-user-object) - [Binding and handling events](#binding-and-handling-events) @@ -271,6 +272,38 @@ PrivateChannel channel = pusher.subscribePrivate("private-channel", }); ``` +### Private encrypted channels + +Similar to Private channels, you can also subscribe to a +[private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels) +which means the data passed through Pusher is encrypted and only possible to +decrypt using the shared secret you provide. + +Like the private channel, you must provide your own authentication endpoint, +with your own encryption master key. There is a +[demonstration endpoint to look at using nodejs](https://github.com/pusher/pusher-channels-auth-example#using-e2e-encryption). + +To get started you need to subscribe to your channel, provide a `PrivateEncryptedChannelEventListener` +listener, and a list of the events you are interested in: + +```java +PrivateEncryptedChannel privateEncryptedChannel = + pusher.subscribePrivateEncrypted("private-encrypted-channel", listener, "my-event"); +``` + +In addition to the events that are possible on public channels the +`PrivateEncryptedChannelEventListener` also has the following methods: +* `onAuthenticationFailure(String message, Exception e)` - This is called if +the `Authorizer` does not successfully authenticate the subscription: +* `onDecryptionFailure(Exception e);` - This is called if the message cannot be +decrypted. The decryption will attempt to refresh the shared secret key once +from the `Authorizer`. + +There is a +[working example in the repo](https://github.com/pusher/pusher-websocket-java/blob/master/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java) +which you can use with the +[demonstration authorization endpoint](https://github.com/pusher/pusher-channels-auth-example#using-e2e-encryption) + ### Presence channels [Presence channels](https://pusher.com/docs/channels/using_channels/presence-channels) are private channels which provide additional events exposing who is currently subscribed to the channel. Since they extend private channels they also need to be authenticated (see [authenticating channel subscriptions](https://pusher.com/docs/channels/server_api/authenticating-users)). From d0cebdcb6684ebbbc077ea78590e3f0b0bfcb8ff Mon Sep 17 00:00:00 2001 From: Danielle Vass Date: Tue, 7 Apr 2020 10:15:04 +0100 Subject: [PATCH 2/6] Update Private Encrypted Channels docs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c92cf7a0..f7de0afc 100644 --- a/README.md +++ b/README.md @@ -277,14 +277,14 @@ PrivateChannel channel = pusher.subscribePrivate("private-channel", Similar to Private channels, you can also subscribe to a [private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels) which means the data passed through Pusher is encrypted and only possible to -decrypt using the shared secret you provide. +decrypt using the shared secret you have have. Like the private channel, you must provide your own authentication endpoint, with your own encryption master key. There is a [demonstration endpoint to look at using nodejs](https://github.com/pusher/pusher-channels-auth-example#using-e2e-encryption). To get started you need to subscribe to your channel, provide a `PrivateEncryptedChannelEventListener` -listener, and a list of the events you are interested in: +listener, and a list of the events you are interested in, for example: ```java PrivateEncryptedChannel privateEncryptedChannel = @@ -295,7 +295,7 @@ In addition to the events that are possible on public channels the `PrivateEncryptedChannelEventListener` also has the following methods: * `onAuthenticationFailure(String message, Exception e)` - This is called if the `Authorizer` does not successfully authenticate the subscription: -* `onDecryptionFailure(Exception e);` - This is called if the message cannot be +* `onDecryptionFailure(String event, String reason);` - This is called if the message cannot be decrypted. The decryption will attempt to refresh the shared secret key once from the `Authorizer`. From a7074302044853689c842caaa2af90e4735eca7b Mon Sep 17 00:00:00 2001 From: Danielle Vass Date: Tue, 7 Apr 2020 10:22:22 +0100 Subject: [PATCH 3/6] Feedback to docs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7de0afc..7ea904d8 100644 --- a/README.md +++ b/README.md @@ -277,14 +277,14 @@ PrivateChannel channel = pusher.subscribePrivate("private-channel", Similar to Private channels, you can also subscribe to a [private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels) which means the data passed through Pusher is encrypted and only possible to -decrypt using the shared secret you have have. +decrypt using the shared secret you have. Like the private channel, you must provide your own authentication endpoint, with your own encryption master key. There is a [demonstration endpoint to look at using nodejs](https://github.com/pusher/pusher-channels-auth-example#using-e2e-encryption). -To get started you need to subscribe to your channel, provide a `PrivateEncryptedChannelEventListener` -listener, and a list of the events you are interested in, for example: +To get started you need to subscribe to your channel, provide a `PrivateEncryptedChannelEventListener`, and a list of the events you are +interested in, for example: ```java PrivateEncryptedChannel privateEncryptedChannel = From 5a6a1173149ecb4bb544c4667b6571b38c586731 Mon Sep 17 00:00:00 2001 From: Danielle Vass Date: Tue, 7 Apr 2020 10:51:50 +0100 Subject: [PATCH 4/6] Document the example app better --- .../PrivateEncryptedChannelExampleApp.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java index b883e60f..df077df3 100644 --- a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java +++ b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java @@ -9,13 +9,32 @@ import com.pusher.client.connection.ConnectionStateChange; import com.pusher.client.util.HttpAuthorizer; +/* +This app demonstrates how to use Private Encrypted Channels. + +Please ensure you update this relevant parts below with your Pusher credentials before running. +and ensure you have set up an authorization endpoint with end to end encryption. Your Pusher credentials +can be found at https://dashboard.pusher.com, selecting the channels project, and visiting the App Keys +tab. + +A demonstration authorization endpoint using nodejs can be found +https://github.com/pusher/pusher-channels-auth-example#using-e2e-encryption + +For more information on private encrypted channels please read +https://pusher.com/docs/channels/using_channels/encrypted-channels + +For more pecific information on how to use private encrypted channels check out +https://github.com/pusher/pusher-websocket-java#private-encrypted-channels + */ + public class PrivateEncryptedChannelExampleApp implements ConnectionEventListener, PrivateEncryptedChannelEventListener { - private String apiKey = "FILL_ME_IN"; // "key" at https://dashboard.pusher.com + private String key = "FILL_ME_IN"; private String channelName = "private-encrypted-channel"; private String eventName = "my-event"; private String cluster = "eu"; + private String authorizationEndpoint = "http://localhost:3030/pusher/auth"; private PrivateEncryptedChannel channel; @@ -28,15 +47,15 @@ private PrivateEncryptedChannelExampleApp(final String[] args) { case 4: cluster = args[3]; case 3: eventName = args[2]; case 2: channelName = args[1]; - case 1: apiKey = args[0]; + case 1: key = args[0]; } final HttpAuthorizer authorizer = new HttpAuthorizer( - "http://localhost:3030/pusher/auth"); + authorizationEndpoint); final PusherOptions options = new PusherOptions().setAuthorizer(authorizer).setEncrypted(true); options.setCluster(cluster); - Pusher pusher = new Pusher(apiKey, options); + Pusher pusher = new Pusher(key, options); pusher.connect(this); channel = pusher.subscribePrivateEncrypted(channelName, this, eventName); From bac5d8a3e0923fcc9a4730873fb2262a4775f448 Mon Sep 17 00:00:00 2001 From: Danielle Vass Date: Tue, 7 Apr 2020 14:31:33 +0100 Subject: [PATCH 5/6] Feedback on docs --- README.md | 6 ++++-- .../client/example/PrivateEncryptedChannelExampleApp.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7ea904d8..7cf09c7f 100644 --- a/README.md +++ b/README.md @@ -275,9 +275,11 @@ PrivateChannel channel = pusher.subscribePrivate("private-channel", ### Private encrypted channels Similar to Private channels, you can also subscribe to a -[private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels) +[private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels). +Pusher fully supports end-to-end encryption of these private encrypted channels. which means the data passed through Pusher is encrypted and only possible to -decrypt using the shared secret you have. +decrypt using the shared secret you have. This means that only you and your +connected clients will be able to read your messages. Pusher cannot decrypt them. Like the private channel, you must provide your own authentication endpoint, with your own encryption master key. There is a diff --git a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java index df077df3..6d09c0b3 100644 --- a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java +++ b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java @@ -30,7 +30,7 @@ public class PrivateEncryptedChannelExampleApp implements ConnectionEventListener, PrivateEncryptedChannelEventListener { - private String key = "FILL_ME_IN"; + private String channelsKey = "FILL_ME_IN"; private String channelName = "private-encrypted-channel"; private String eventName = "my-event"; private String cluster = "eu"; @@ -47,7 +47,7 @@ private PrivateEncryptedChannelExampleApp(final String[] args) { case 4: cluster = args[3]; case 3: eventName = args[2]; case 2: channelName = args[1]; - case 1: key = args[0]; + case 1: channelsKey = args[0]; } final HttpAuthorizer authorizer = new HttpAuthorizer( @@ -55,7 +55,7 @@ private PrivateEncryptedChannelExampleApp(final String[] args) { final PusherOptions options = new PusherOptions().setAuthorizer(authorizer).setEncrypted(true); options.setCluster(cluster); - Pusher pusher = new Pusher(key, options); + Pusher pusher = new Pusher(channelsKey, options); pusher.connect(this); channel = pusher.subscribePrivateEncrypted(channelName, this, eventName); From f23a1b974cfd5ff91513f2e917f33da0c16a7924 Mon Sep 17 00:00:00 2001 From: Danielle Vass Date: Tue, 7 Apr 2020 14:33:47 +0100 Subject: [PATCH 6/6] Delete duplicated parts of the docs --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 7cf09c7f..b8aad678 100644 --- a/README.md +++ b/README.md @@ -276,10 +276,7 @@ PrivateChannel channel = pusher.subscribePrivate("private-channel", Similar to Private channels, you can also subscribe to a [private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels). -Pusher fully supports end-to-end encryption of these private encrypted channels. -which means the data passed through Pusher is encrypted and only possible to -decrypt using the shared secret you have. This means that only you and your -connected clients will be able to read your messages. Pusher cannot decrypt them. +This library now fully supports end-to-end encryption. This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them. Like the private channel, you must provide your own authentication endpoint, with your own encryption master key. There is a