pusher 1.4.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +83 -79
- data/README.md +15 -12
- data/lib/pusher.rb +0 -3
- data/lib/pusher/channel.rb +9 -0
- data/lib/pusher/client.rb +62 -78
- data/lib/pusher/version.rb +1 -1
- metadata +21 -41
- data/.document +0 -5
- data/.gemtest +0 -0
- data/.github/stale.yml +0 -26
- data/.gitignore +0 -24
- data/.travis.yml +0 -16
- data/Gemfile +0 -2
- data/Rakefile +0 -11
- data/examples/async_message.rb +0 -28
- data/examples/presence_channels/presence_channels.rb +0 -56
- data/examples/presence_channels/public/presence_channels.html +0 -28
- data/lib/pusher/native_notification/client.rb +0 -69
- data/pusher.gemspec +0 -34
- data/spec/channel_spec.rb +0 -170
- data/spec/client_spec.rb +0 -773
- data/spec/spec_helper.rb +0 -26
- data/spec/web_hook_spec.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ec4402d063ad4e8193f92bee0a9116987cd1388e3f21be49b7bfbe62ad4dbab
|
4
|
+
data.tar.gz: 0f974393c92fba1afbae6b85faf96d6950932cc0b24b538d1493300ec1e51e0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f6e5cc6dc5a02db77200c18244e07dee27bc52abd3e4c376642b56e330d5d4bf86494c393ddeb340a38054c45ab3358eafc5a3d2dd0b8f17f471a8b6ba283d
|
7
|
+
data.tar.gz: ad18ed1ce95a46e383b9af71b38b528cae273083deafca6f3d187f4586a27d8a900c719be612a76822ef30b58b8e41ce15fac540f15f0f7904ce9276dd138b2c
|
data/CHANGELOG.md
CHANGED
@@ -1,121 +1,125 @@
|
|
1
|
-
|
2
|
-
==================
|
1
|
+
# Changelog
|
3
2
|
|
4
|
-
|
3
|
+
## 2.0.1
|
5
4
|
|
6
|
-
|
7
|
-
==================
|
5
|
+
* [CHANGED] Only include lib and essential docs in gem.
|
8
6
|
|
9
|
-
|
7
|
+
## 2.0.0
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
* [CHANGED] Use TLS by default.
|
10
|
+
* [REMOVED] Support for Ruby 2.4 and 2.5.
|
11
|
+
* [FIXED] Handle empty or nil configuration.
|
12
|
+
* [REMOVED] Legacy Push Notification integration.
|
13
|
+
* [ADDED] Stalebot and Github actions.
|
13
14
|
|
14
|
-
|
15
|
-
* Add a `use_tls` option for SSL (defaults to false).
|
16
|
-
* Add a `from_url` client method (in addition to existing `from_env` option).
|
17
|
-
* Improved documentation and fixed typos.
|
18
|
-
* Add Ruby 2.4 to test matrix.
|
15
|
+
## 1.4.3
|
19
16
|
|
20
|
-
|
17
|
+
* [FIXED] Remove newline from end of base64 encoded strings, some decoders don't like
|
18
|
+
them.
|
19
|
+
|
20
|
+
## 1.4.2
|
21
21
|
==================
|
22
22
|
|
23
|
-
*
|
24
|
-
|
25
|
-
* Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
|
23
|
+
* [FIXED] Return `shared_secret` to support authenticating encrypted channels. Thanks
|
24
|
+
@Benjaminpjacobs
|
26
25
|
|
27
|
-
1.
|
28
|
-
==================
|
26
|
+
## 1.4.1
|
29
27
|
|
30
|
-
*
|
28
|
+
* [CHANGED] Remove rbnacl from dependencies so we don't get errors when it isn't
|
29
|
+
required. Thanks @y-yagi!
|
31
30
|
|
32
|
-
1.
|
33
|
-
==================
|
31
|
+
## 1.4.0
|
34
32
|
|
35
|
-
*
|
33
|
+
* [ADDED] Support for end-to-end encryption.
|
36
34
|
|
37
|
-
1.
|
38
|
-
==================
|
35
|
+
## 1.3.3
|
39
36
|
|
40
|
-
*
|
37
|
+
* [CHANGED] Rewording to clarify "Pusher Channels" or simply "Channels" product name.
|
41
38
|
|
42
|
-
1.2
|
43
|
-
==================
|
39
|
+
## 1.3.2
|
44
40
|
|
45
|
-
*
|
41
|
+
* [FIXED] Return a specific error for "Request Entity Too Large" (body over 10KB).
|
42
|
+
* [ADDED] Add a `use_tls` option for SSL (defaults to false).
|
43
|
+
* [ADDED] Add a `from_url` client method (in addition to existing `from_env` option).
|
44
|
+
* [CHANGED] Improved documentation and fixed typos.
|
45
|
+
* [ADDED] Add Ruby 2.4 to test matrix.
|
46
46
|
|
47
|
-
1.1
|
48
|
-
==================
|
47
|
+
## 1.3.1
|
49
48
|
|
50
|
-
*
|
49
|
+
* [FIXED] Added missing client batch methods to default client delegations
|
50
|
+
* [CHANGED] Document raised exception in the `authenticate` method
|
51
|
+
* [FIXED] Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
|
51
52
|
|
52
|
-
1.
|
53
|
-
==================
|
53
|
+
## 1.3.0
|
54
54
|
|
55
|
-
|
56
|
-
are stable.
|
55
|
+
* [ADDED] Add support for sending push notifications on up to 10 interests.
|
57
56
|
|
58
|
-
|
59
|
-
==================
|
57
|
+
## 1.2.1
|
60
58
|
|
61
|
-
*
|
62
|
-
* Improve error handling on missing config
|
59
|
+
* [FIXED] Fixes Rails 5 compatibility. Use duck-typing to detect request object
|
63
60
|
|
64
|
-
|
65
|
-
==================
|
61
|
+
## 1.2.0
|
66
62
|
|
67
|
-
*
|
63
|
+
* [CHANGED] Minor release for Native notifications
|
68
64
|
|
69
|
-
|
70
|
-
==================
|
65
|
+
## 1.2.0.rc1
|
71
66
|
|
72
|
-
*
|
73
|
-
* Ruby 1.8.7 is not supported anymore.
|
67
|
+
* [ADDED] Add support for Native notifications
|
74
68
|
|
75
|
-
|
76
|
-
==================
|
69
|
+
## 1.1.0
|
77
70
|
|
78
|
-
*
|
79
|
-
* Added `Pusher.channel_users`
|
71
|
+
* [ADDED] Add support for batch events
|
80
72
|
|
81
|
-
0.
|
82
|
-
==================
|
73
|
+
## 1.0.0
|
83
74
|
|
84
|
-
|
75
|
+
* [CHANGED] No breaking changes, this release is just to follow semver and show that we
|
76
|
+
are stable.
|
85
77
|
|
86
|
-
0.
|
87
|
-
==================
|
78
|
+
## 0.18.0
|
88
79
|
|
89
|
-
*
|
90
|
-
|
80
|
+
* [ADDED] Introduce `Pusher::Client.from_env`
|
81
|
+
* [FIXED] Improve error handling on missing config
|
91
82
|
|
92
|
-
0.
|
93
|
-
==================
|
94
|
-
* Updated to use the `pusher-signature` gem instead of `signature`.
|
95
|
-
This resolves namespace related issues.
|
83
|
+
## 0.17.0
|
96
84
|
|
97
|
-
|
98
|
-
==================
|
85
|
+
* [ADDED] Introduce the `cluster` option.
|
99
86
|
|
100
|
-
|
87
|
+
## 0.16.0
|
101
88
|
|
102
|
-
|
103
|
-
|
89
|
+
* [CHANGED] Bump httpclient version to 2.7
|
90
|
+
* [REMOVED] Ruby 1.8.7 is not supported anymore.
|
104
91
|
|
105
|
-
|
106
|
-
* SECURITY: Prevent POODLE. Disable SSLv3, update httpclient to v2.5
|
107
|
-
* Fix channel name character limit.
|
108
|
-
* Adds support for listing users on a presence channel
|
92
|
+
## 0.15.2
|
109
93
|
|
110
|
-
|
111
|
-
|
94
|
+
* [CHANGED] Documented `Pusher.channel_info`, `Pusher.channels`
|
95
|
+
* [ADDED] Added `Pusher.channel_users`
|
112
96
|
|
113
|
-
|
97
|
+
## 0.15.1
|
114
98
|
|
115
|
-
0.
|
116
|
-
|
99
|
+
* [FIXED] Fixed a bug where the `authenticate` method added in 0.15.0 wasn't exposed on the Pusher class.
|
100
|
+
|
101
|
+
## 0.15.0
|
102
|
+
|
103
|
+
* [ADDED] Added `Pusher.authenticate` method for authenticating private and presence channels.
|
104
|
+
This is prefered over the older `Pusher['a_channel'].authenticate(...)` style.
|
105
|
+
|
106
|
+
## 0.14.6
|
107
|
+
|
108
|
+
* [CHANGED] Updated to use the `pusher-signature` gem instead of `signature`.
|
109
|
+
This resolves namespace related issues.
|
110
|
+
|
111
|
+
## 0.14.5
|
112
|
+
|
113
|
+
* [SECURITY] Prevent auth delegation trough crafted socket IDs
|
114
|
+
|
115
|
+
## 0.14.4
|
116
|
+
|
117
|
+
* [SECURITY] Prevent timing attack, update signature to v0.1.8
|
118
|
+
* [SECURITY] Prevent POODLE. Disable SSLv3, update httpclient to v2.5
|
119
|
+
* [FIXED] Fix channel name character limit.
|
120
|
+
* [ADDED] Adds support for listing users on a presence channel
|
117
121
|
|
118
|
-
|
122
|
+
## 0.14.2
|
119
123
|
|
120
|
-
* Bump httpclient to v2.4. See #62 (POODLE SSL)
|
121
|
-
* Fix limited channel count at README.md. Thanks @tricknotes
|
124
|
+
* [CHANGED] Bump httpclient to v2.4. See #62 (POODLE SSL)
|
125
|
+
* [CHANGED] Fix limited channel count at README.md. Thanks @tricknotes
|
data/README.md
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
This Gem provides a Ruby interface to [the Pusher HTTP API for Pusher Channels](https://pusher.com/docs/channels/library_auth_reference/rest-api).
|
4
4
|
|
5
|
-
[![Build Status](https://
|
5
|
+
[![Build Status](https://github.com/pusher/pusher-http-ruby/workflows/Tests/badge.svg)](https://github.com/pusher/pusher-http-ruby/actions?query=workflow%3ATests+branch%3Amaster) [![Gem](https://img.shields.io/gem/v/pusher)](https://rubygems.org/gems/pusher) [![Gem](https://img.shields.io/gem/dt/pusher)](https://rubygems.org/gems/pusher)
|
6
|
+
|
7
|
+
## Supported Platforms
|
8
|
+
|
9
|
+
* Ruby - supports **Ruby 2.6 or greater**.
|
6
10
|
|
7
11
|
## Installation and Configuration
|
8
12
|
|
@@ -36,7 +40,7 @@ pusher = Pusher::Client.new(
|
|
36
40
|
)
|
37
41
|
```
|
38
42
|
|
39
|
-
The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `
|
43
|
+
The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `true`. It will set the `scheme` and `port`. A custom `port` value takes precendence over `use_tls`.
|
40
44
|
|
41
45
|
If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher Channels client like so:
|
42
46
|
|
@@ -79,11 +83,11 @@ If you need to make requests via a HTTP proxy then it can be configured
|
|
79
83
|
Pusher.http_proxy = 'http://(user):(password)@(host):(port)'
|
80
84
|
```
|
81
85
|
|
82
|
-
By default API requests are made over
|
86
|
+
By default API requests are made over HTTPS. HTTP can be used by setting `use_tls` to `false`.
|
83
87
|
Issuing this command is going to reset `port` value if it was previously specified.
|
84
88
|
|
85
89
|
``` ruby
|
86
|
-
Pusher.
|
90
|
+
Pusher.use_tls = false
|
87
91
|
```
|
88
92
|
|
89
93
|
As of version 0.12, SSL certificates are verified when using the synchronous http client. If you need to disable this behaviour for any reason use:
|
@@ -252,11 +256,13 @@ end
|
|
252
256
|
|
253
257
|
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:
|
254
258
|
|
255
|
-
1.
|
259
|
+
1. Add the `rbnacl` gem to your Gemfile (it's not a gem dependency).
|
256
260
|
|
257
|
-
2.
|
261
|
+
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)
|
258
262
|
|
259
|
-
3.
|
263
|
+
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).
|
264
|
+
|
265
|
+
4. Next, generate your 32 byte master encryption key, encode it as base64 and pass it to the Pusher constructor.
|
260
266
|
|
261
267
|
This is secret and you should never share this with anyone.
|
262
268
|
Not even Pusher.
|
@@ -276,9 +282,9 @@ This library supports [end-to-end encrypted channels](https://pusher.com/docs/ch
|
|
276
282
|
});
|
277
283
|
```
|
278
284
|
|
279
|
-
|
285
|
+
5. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
|
280
286
|
|
281
|
-
|
287
|
+
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.
|
282
288
|
|
283
289
|
**Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
|
284
290
|
|
@@ -293,6 +299,3 @@ pusher.trigger(
|
|
293
299
|
```
|
294
300
|
|
295
301
|
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.
|
296
|
-
|
297
|
-
## Supported Ruby versions
|
298
|
-
2.4+
|
data/lib/pusher.rb
CHANGED
@@ -28,9 +28,7 @@ module Pusher
|
|
28
28
|
extend Forwardable
|
29
29
|
|
30
30
|
def_delegators :default_client, :scheme, :host, :port, :app_id, :key, :secret, :http_proxy
|
31
|
-
def_delegators :default_client, :notification_host, :notification_scheme
|
32
31
|
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
|
33
|
-
def_delegators :default_client, :notification_host=, :notification_scheme=
|
34
32
|
|
35
33
|
def_delegators :default_client, :authentication_token, :url, :cluster
|
36
34
|
def_delegators :default_client, :encrypted=, :url=, :cluster=
|
@@ -66,4 +64,3 @@ require 'pusher/channel'
|
|
66
64
|
require 'pusher/request'
|
67
65
|
require 'pusher/resource'
|
68
66
|
require 'pusher/webhook'
|
69
|
-
require 'pusher/native_notification/client'
|
data/lib/pusher/channel.rb
CHANGED
@@ -174,6 +174,15 @@ module Pusher
|
|
174
174
|
r
|
175
175
|
end
|
176
176
|
|
177
|
+
def shared_secret(encryption_master_key)
|
178
|
+
return unless encryption_master_key
|
179
|
+
|
180
|
+
secret_string = @name + encryption_master_key
|
181
|
+
digest = OpenSSL::Digest::SHA256.new
|
182
|
+
digest << secret_string
|
183
|
+
digest.digest
|
184
|
+
end
|
185
|
+
|
177
186
|
private
|
178
187
|
|
179
188
|
def validate_socket_id(socket_id)
|
data/lib/pusher/client.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
require 'base64'
|
2
|
-
|
3
2
|
require 'pusher-signature'
|
4
3
|
|
5
4
|
module Pusher
|
6
5
|
class Client
|
7
|
-
attr_accessor :scheme, :host, :port, :app_id, :key, :secret, :
|
6
|
+
attr_accessor :scheme, :host, :port, :app_id, :key, :secret, :encryption_master_key
|
8
7
|
attr_reader :http_proxy, :proxy
|
9
8
|
attr_writer :connect_timeout, :send_timeout, :receive_timeout,
|
10
9
|
:keep_alive_timeout
|
11
10
|
|
12
11
|
## CONFIGURATION ##
|
12
|
+
DEFAULT_CONNECT_TIMEOUT = 5
|
13
|
+
DEFAULT_SEND_TIMEOUT = 5
|
14
|
+
DEFAULT_RECEIVE_TIMEOUT = 5
|
15
|
+
DEFAULT_KEEP_ALIVE_TIMEOUT = 30
|
16
|
+
DEFAULT_CLUSTER = "mt1"
|
13
17
|
|
14
18
|
# Loads the configuration from an url in the environment
|
15
19
|
def self.from_env(key = 'PUSHER_URL')
|
@@ -25,51 +29,35 @@ module Pusher
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def initialize(options = {})
|
28
|
-
|
29
|
-
|
30
|
-
:port => 80,
|
31
|
-
}
|
32
|
+
@scheme = "https"
|
33
|
+
@port = options[:port] || 443
|
32
34
|
|
33
|
-
if options
|
34
|
-
|
35
|
-
default_options[:port] = 443
|
35
|
+
if options.key?(:encrypted)
|
36
|
+
warn "[DEPRECATION] `encrypted` is deprecated and will be removed in the next major version. Use `use_tls` instead."
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
merged_options[:host] = options[:host]
|
42
|
-
elsif options.has_key?(:cluster)
|
43
|
-
merged_options[:host] = "api-#{options[:cluster]}.pusher.com"
|
44
|
-
else
|
45
|
-
merged_options[:host] = "api.pusherapp.com"
|
39
|
+
if options[:use_tls] == false || options[:encrypted] == false
|
40
|
+
@scheme = "http"
|
41
|
+
@port = options[:port] || 80
|
46
42
|
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
merged_options[:notification_scheme] =
|
53
|
-
options.fetch(:notification_scheme, "https")
|
44
|
+
@app_id = options[:app_id]
|
45
|
+
@key = options[:key]
|
46
|
+
@secret = options[:secret]
|
54
47
|
|
55
|
-
@
|
56
|
-
|
57
|
-
|
58
|
-
)
|
48
|
+
@host = options[:host]
|
49
|
+
@host ||= "api-#{options[:cluster]}.pusher.com" unless options[:cluster].nil? || options[:cluster].empty?
|
50
|
+
@host ||= "api-#{DEFAULT_CLUSTER}.pusher.com"
|
59
51
|
|
60
|
-
|
61
|
-
@encryption_master_key =
|
62
|
-
Base64.decode64(options[:encryption_master_key_base64])
|
63
|
-
end
|
52
|
+
@encryption_master_key = Base64.strict_decode64(options[:encryption_master_key_base64]) if options[:encryption_master_key_base64]
|
64
53
|
|
65
|
-
@http_proxy =
|
66
|
-
self.http_proxy = options[:http_proxy] if options[:http_proxy]
|
54
|
+
@http_proxy = options[:http_proxy]
|
67
55
|
|
68
56
|
# Default timeouts
|
69
|
-
@connect_timeout =
|
70
|
-
@send_timeout =
|
71
|
-
@receive_timeout =
|
72
|
-
@keep_alive_timeout =
|
57
|
+
@connect_timeout = DEFAULT_CONNECT_TIMEOUT
|
58
|
+
@send_timeout = DEFAULT_SEND_TIMEOUT
|
59
|
+
@receive_timeout = DEFAULT_RECEIVE_TIMEOUT
|
60
|
+
@keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT
|
73
61
|
end
|
74
62
|
|
75
63
|
# @private Returns the authentication token for the client
|
@@ -83,10 +71,10 @@ module Pusher
|
|
83
71
|
def url(path = nil)
|
84
72
|
raise ConfigurationError, :app_id unless @app_id
|
85
73
|
URI::Generic.build({
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
74
|
+
scheme: @scheme,
|
75
|
+
host: @host,
|
76
|
+
port: @port,
|
77
|
+
path: "/apps/#{@app_id}#{path}"
|
90
78
|
})
|
91
79
|
end
|
92
80
|
|
@@ -110,13 +98,12 @@ module Pusher
|
|
110
98
|
@http_proxy = http_proxy
|
111
99
|
uri = URI.parse(http_proxy)
|
112
100
|
@proxy = {
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
101
|
+
scheme: uri.scheme,
|
102
|
+
host: uri.host,
|
103
|
+
port: uri.port,
|
104
|
+
user: uri.user,
|
105
|
+
password: uri.password
|
118
106
|
}
|
119
|
-
@http_proxy
|
120
107
|
end
|
121
108
|
|
122
109
|
# Configure whether Pusher API calls should be made over SSL
|
@@ -136,6 +123,8 @@ module Pusher
|
|
136
123
|
end
|
137
124
|
|
138
125
|
def cluster=(cluster)
|
126
|
+
cluster = DEFAULT_CLUSTER if cluster.nil? || cluster.empty?
|
127
|
+
|
139
128
|
@host = "api-#{cluster}.pusher.com"
|
140
129
|
end
|
141
130
|
|
@@ -148,7 +137,7 @@ module Pusher
|
|
148
137
|
# Set an encryption_master_key to use with private-encrypted channels from
|
149
138
|
# a base64 encoded string.
|
150
139
|
def encryption_master_key_base64=(s)
|
151
|
-
@encryption_master_key = s ? Base64.
|
140
|
+
@encryption_master_key = s ? Base64.strict_decode64(s) : nil
|
152
141
|
end
|
153
142
|
|
154
143
|
## INTERACT WITH THE API ##
|
@@ -330,24 +319,6 @@ module Pusher
|
|
330
319
|
post_async('/batch_events', trigger_batch_params(events.flatten))
|
331
320
|
end
|
332
321
|
|
333
|
-
def notification_client
|
334
|
-
@notification_client ||=
|
335
|
-
NativeNotification::Client.new(@app_id, @notification_host, @notification_scheme, self)
|
336
|
-
end
|
337
|
-
|
338
|
-
|
339
|
-
# Send a push notification
|
340
|
-
#
|
341
|
-
# POST /apps/[app_id]/notifications
|
342
|
-
#
|
343
|
-
# @param interests [Array] An array of interests
|
344
|
-
# @param message [String] Message to send
|
345
|
-
# @param options [Hash] Additional platform specific options
|
346
|
-
#
|
347
|
-
# @return [Hash]
|
348
|
-
def notify(interests, data = {})
|
349
|
-
notification_client.notify(interests, data)
|
350
|
-
end
|
351
322
|
|
352
323
|
# Generate the expected response for an authentication endpoint.
|
353
324
|
# See http://pusher.com/docs/authenticating_users for details.
|
@@ -375,14 +346,20 @@ module Pusher
|
|
375
346
|
#
|
376
347
|
def authenticate(channel_name, socket_id, custom_data = nil)
|
377
348
|
channel_instance = channel(channel_name)
|
378
|
-
channel_instance.authenticate(socket_id, custom_data)
|
349
|
+
r = channel_instance.authenticate(socket_id, custom_data)
|
350
|
+
if channel_name.match(/^private-encrypted-/)
|
351
|
+
r[:shared_secret] = Base64.strict_encode64(
|
352
|
+
channel_instance.shared_secret(encryption_master_key)
|
353
|
+
)
|
354
|
+
end
|
355
|
+
r
|
379
356
|
end
|
380
357
|
|
381
358
|
# @private Construct a net/http http client
|
382
359
|
def sync_http_client
|
383
|
-
|
384
|
-
require 'httpclient'
|
360
|
+
require 'httpclient'
|
385
361
|
|
362
|
+
@client ||= begin
|
386
363
|
HTTPClient.new(@http_proxy).tap do |c|
|
387
364
|
c.connect_timeout = @connect_timeout
|
388
365
|
c.send_timeout = @send_timeout
|
@@ -401,14 +378,14 @@ module Pusher
|
|
401
378
|
require 'em-http' unless defined?(EventMachine::HttpRequest)
|
402
379
|
|
403
380
|
connection_opts = {
|
404
|
-
:
|
405
|
-
:
|
381
|
+
connect_timeout: @connect_timeout,
|
382
|
+
inactivity_timeout: @receive_timeout,
|
406
383
|
}
|
407
384
|
|
408
385
|
if defined?(@proxy)
|
409
386
|
proxy_opts = {
|
410
|
-
:
|
411
|
-
:
|
387
|
+
host: @proxy[:host],
|
388
|
+
port: @proxy[:port]
|
412
389
|
}
|
413
390
|
if @proxy[:user]
|
414
391
|
proxy_opts[:authorization] = [@proxy[:user], @proxy[:password]]
|
@@ -462,28 +439,35 @@ module Pusher
|
|
462
439
|
|
463
440
|
# Encrypts a message with a key derived from the master key and channel
|
464
441
|
# name
|
465
|
-
def encrypt(
|
442
|
+
def encrypt(channel_name, encoded_data)
|
466
443
|
raise ConfigurationError, :encryption_master_key unless @encryption_master_key
|
467
444
|
|
468
445
|
# Only now load rbnacl, so that people that aren't using it don't need to
|
469
446
|
# install libsodium
|
470
|
-
|
447
|
+
require_rbnacl
|
471
448
|
|
472
449
|
secret_box = RbNaCl::SecretBox.new(
|
473
|
-
|
450
|
+
channel(channel_name).shared_secret(@encryption_master_key)
|
474
451
|
)
|
475
452
|
|
476
453
|
nonce = RbNaCl::Random.random_bytes(secret_box.nonce_bytes)
|
477
454
|
ciphertext = secret_box.encrypt(nonce, encoded_data)
|
478
455
|
|
479
456
|
MultiJson.encode({
|
480
|
-
"nonce" => Base64::
|
481
|
-
"ciphertext" => Base64::
|
457
|
+
"nonce" => Base64::strict_encode64(nonce),
|
458
|
+
"ciphertext" => Base64::strict_encode64(ciphertext),
|
482
459
|
})
|
483
460
|
end
|
484
461
|
|
485
462
|
def configured?
|
486
463
|
host && scheme && key && secret && app_id
|
487
464
|
end
|
465
|
+
|
466
|
+
def require_rbnacl
|
467
|
+
require 'rbnacl'
|
468
|
+
rescue LoadError => e
|
469
|
+
$stderr.puts "You don't have rbnacl installed in your application. Please add it to your Gemfile and run bundle install"
|
470
|
+
raise e
|
471
|
+
end
|
488
472
|
end
|
489
473
|
end
|