Skip to content

Commit 41e14e3

Browse files
author
Callum Oakley
authored
Merge pull request #162 from y-yagi/dont-add-rbnacl-as-dependency
Don't add `rbnacl` as dependency
2 parents 11ae12c + ee3bd43 commit 41e14e3

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,13 @@ end
252252

253253
This library supports [end-to-end encrypted channels](https://pusher.com/docs/channels/using_channels/encrypted-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:
254254

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)
255+
1. Add the `rbnacl` gem to your Gemfile (it's not a gem dependency).
256256

257-
2. Encrypted channel subscriptions must be authenticated in the exact same way as private channels. You should therefore [create an authentication endpoint on your server](https://pusher.com/docs/authenticating_users).
257+
2. 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)
258258

259-
3. Next, generate your 32 byte master encryption key, encode it as base64 and pass it to the Pusher constructor.
259+
3. Encrypted channel subscriptions must be authenticated in the exact same way as private channels. You should therefore [create an authentication endpoint on your server](https://pusher.com/docs/authenticating_users).
260+
261+
4. Next, generate your 32 byte master encryption key, encode it as base64 and pass it to the Pusher constructor.
260262

261263
This is secret and you should never share this with anyone.
262264
Not even Pusher.
@@ -276,9 +278,9 @@ This library supports [end-to-end encrypted channels](https://pusher.com/docs/ch
276278
});
277279
```
278280

279-
4. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
281+
5. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
280282

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.
283+
6. 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.
282284

283285
**Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
284286

lib/pusher/client.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def encrypt(channel, encoded_data)
467467

468468
# Only now load rbnacl, so that people that aren't using it don't need to
469469
# install libsodium
470-
require 'rbnacl'
470+
require_rbnacl
471471

472472
secret_box = RbNaCl::SecretBox.new(
473473
RbNaCl::Hash.sha256(channel + @encryption_master_key)
@@ -485,5 +485,12 @@ def encrypt(channel, encoded_data)
485485
def configured?
486486
host && scheme && key && secret && app_id
487487
end
488+
489+
def require_rbnacl
490+
require 'rbnacl'
491+
rescue LoadError => e
492+
$stderr.puts "You don't have rbnacl installed in your application. Please add it to your Gemfile and run bundle install"
493+
raise e
494+
end
488495
end
489496
end

pusher.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
1717
s.add_dependency 'pusher-signature', "~> 0.1.8"
1818
s.add_dependency "httpclient", "~> 2.8"
1919
s.add_dependency "jruby-openssl" if defined?(JRUBY_VERSION)
20-
s.add_dependency "rbnacl", "~> 7.1"
2120

2221
s.add_development_dependency "rspec", "~> 3.9"
2322
s.add_development_dependency "webmock", "~> 3.9"
@@ -26,6 +25,7 @@ Gem::Specification.new do |s|
2625
s.add_development_dependency "rake", "~> 13.0"
2726
s.add_development_dependency "rack", "~> 2.2"
2827
s.add_development_dependency "json", "~> 2.3"
28+
s.add_development_dependency "rbnacl", "~> 7.1"
2929

3030
s.files = `git ls-files`.split("\n")
3131
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

0 commit comments

Comments
 (0)