diff --git a/README.md b/README.md index 4bba7c46..b8aad678 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,37 @@ 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). +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 +[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`, and a list of the events you are +interested in, for example: + +```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(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`. + +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)). diff --git a/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java b/src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java index b883e60f..6d09c0b3 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 channelsKey = "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: channelsKey = 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(channelsKey, options); pusher.connect(this); channel = pusher.subscribePrivateEncrypted(channelName, this, eventName);