pubnub 5.2.2 → 5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -3
- data/.pubnub.yml +16 -4
- data/.tool-versions +1 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +6 -6
- data/LICENSE.txt +24 -25
- data/VERSION +1 -1
- data/features/step_definitions/access_steps.rb +0 -2
- data/features/step_definitions/crypto_steps.rb +99 -0
- data/features/support/cryptor.rb +58 -0
- data/features/support/hooks.rb +0 -1
- data/lib/pubnub/client.rb +30 -1
- data/lib/pubnub/error.rb +3 -0
- data/lib/pubnub/event.rb +13 -5
- data/lib/pubnub/events/add_message_action.rb +2 -2
- data/lib/pubnub/events/grant_token.rb +1 -1
- data/lib/pubnub/events/history.rb +18 -6
- data/lib/pubnub/events/publish.rb +7 -3
- data/lib/pubnub/events/remove_channel_members.rb +3 -3
- data/lib/pubnub/events/remove_channel_metadata.rb +1 -1
- data/lib/pubnub/events/remove_memberships.rb +3 -3
- data/lib/pubnub/events/remove_uuid_metadata.rb +1 -1
- data/lib/pubnub/events/set_channel_members.rb +3 -3
- data/lib/pubnub/events/set_channel_metadata.rb +2 -2
- data/lib/pubnub/events/set_memberships.rb +3 -3
- data/lib/pubnub/events/set_uuid_metadata.rb +2 -2
- data/lib/pubnub/events/signal.rb +1 -1
- data/lib/pubnub/events/subscribe.rb +5 -0
- data/lib/pubnub/formatter.rb +22 -11
- data/lib/pubnub/modules/crypto/crypto_module.rb +159 -0
- data/lib/pubnub/modules/crypto/crypto_provider.rb +31 -0
- data/lib/pubnub/modules/crypto/cryptor.rb +73 -0
- data/lib/pubnub/modules/crypto/cryptor_header.rb +251 -0
- data/lib/pubnub/modules/crypto/cryptors/aes_cbc_cryptor.rb +67 -0
- data/lib/pubnub/modules/crypto/cryptors/legacy_cryptor.rb +84 -0
- data/lib/pubnub/modules/crypto/module.rb +8 -0
- data/lib/pubnub/subscribe_event/formatter.rb +8 -8
- data/lib/pubnub/version.rb +1 -1
- data/pubnub.gemspec +2 -2
- metadata +15 -5
- data/lib/pubnub/crypto.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b811bcac62af8b07a13d11b2ddcc4d2ab8f58410e1b3ac3112aa2221aa7445c
|
4
|
+
data.tar.gz: 337be3ead454cc2a8ea9c29b14c6dfd07ba0eee5b801d1f7ea8dc9cb0c94c140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d8f8f6307e338a94479d0b571c63f2232a8682b0f1f616b3d9b2ebcc3eb1ebf815104b2f769a71ea04a40bf87a2f4901153cd13f70e611ed229432a60b34ed7
|
7
|
+
data.tar.gz: 82431be095bed63b13960c42dcaf3831fff1e569f6ebb77f84dec7a757e4a26a825ca5a26f34ee1ad611452541c8c153c2f841231cd490498caaea1f21e58c62
|
data/.github/CODEOWNERS
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
* @parfeon @
|
2
|
-
.
|
3
|
-
README.md @techwritermat @kazydek
|
1
|
+
* @parfeon @seba-aln
|
2
|
+
README.md @techwritermat @kazydek @parfeon @seba-aln
|
data/.pubnub.yml
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
---
|
2
|
-
version: "5.
|
2
|
+
version: "5.3.1"
|
3
3
|
changelog:
|
4
|
+
- date: 2023-11-03
|
5
|
+
version: v5.3.1
|
6
|
+
changes:
|
7
|
+
- type: improvement
|
8
|
+
text: "Update license information."
|
9
|
+
- date: 2023-10-16
|
10
|
+
version: v5.3.0
|
11
|
+
changes:
|
12
|
+
- type: feature
|
13
|
+
text: "Add crypto module that allows to configure SDK to encrypt and decrypt messages."
|
14
|
+
- type: bug
|
15
|
+
text: "Improved security of crypto implementation by adding enhanced AES-CBC cryptor."
|
4
16
|
- date: 2023-03-14
|
5
17
|
version: v5.2.2
|
6
18
|
changes:
|
@@ -663,7 +675,7 @@ sdks:
|
|
663
675
|
- x86-64
|
664
676
|
- distribution-type: package
|
665
677
|
distribution-repository: RubyGems
|
666
|
-
package-name: pubnub-5.
|
678
|
+
package-name: pubnub-5.3.1.gem
|
667
679
|
location: https://rubygems.org/gems/pubnub
|
668
680
|
requires:
|
669
681
|
- name: addressable
|
@@ -768,8 +780,8 @@ sdks:
|
|
768
780
|
- x86-64
|
769
781
|
- distribution-type: library
|
770
782
|
distribution-repository: GitHub release
|
771
|
-
package-name: pubnub-5.
|
772
|
-
location: https://github.com/pubnub/ruby/releases/download/v5.
|
783
|
+
package-name: pubnub-5.3.1.gem
|
784
|
+
location: https://github.com/pubnub/ruby/releases/download/v5.3.1/pubnub-5.3.1.gem
|
773
785
|
requires:
|
774
786
|
- name: addressable
|
775
787
|
min-version: 2.0.0
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby
|
1
|
+
ruby 3.2.2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## v5.3.1
|
2
|
+
November 03 2023
|
3
|
+
|
4
|
+
#### Modified
|
5
|
+
- Update license information.
|
6
|
+
|
7
|
+
## v5.3.0
|
8
|
+
October 16 2023
|
9
|
+
|
10
|
+
#### Added
|
11
|
+
- Add crypto module that allows to configure SDK to encrypt and decrypt messages.
|
12
|
+
|
13
|
+
#### Fixed
|
14
|
+
- Improved security of crypto implementation by adding enhanced AES-CBC cryptor.
|
15
|
+
|
1
16
|
## v5.2.2
|
2
17
|
March 14 2023
|
3
18
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pubnub (5.
|
4
|
+
pubnub (5.3.1)
|
5
5
|
addressable (>= 2.0.0)
|
6
6
|
concurrent-ruby (~> 1.1.5)
|
7
7
|
concurrent-ruby-edge (~> 0.5.0)
|
@@ -100,8 +100,8 @@ GEM
|
|
100
100
|
dry-equalizer (~> 0.2)
|
101
101
|
dry-initializer (~> 3.0)
|
102
102
|
dry-schema (~> 1.5)
|
103
|
-
ffi (1.
|
104
|
-
ffi (1.
|
103
|
+
ffi (1.16.2)
|
104
|
+
ffi (1.16.2-java)
|
105
105
|
hashdiff (1.0.1)
|
106
106
|
httpclient (2.8.3)
|
107
107
|
interception (0.5)
|
@@ -115,10 +115,10 @@ GEM
|
|
115
115
|
parallel (1.19.2)
|
116
116
|
parser (2.7.1.4)
|
117
117
|
ast (~> 2.4.1)
|
118
|
-
pry (0.
|
118
|
+
pry (0.14.2)
|
119
119
|
coderay (~> 1.1)
|
120
120
|
method_source (~> 1.0)
|
121
|
-
pry (0.
|
121
|
+
pry (0.14.2-java)
|
122
122
|
coderay (~> 1.1)
|
123
123
|
method_source (~> 1.0)
|
124
124
|
spoon (~> 0.0)
|
@@ -187,7 +187,7 @@ DEPENDENCIES
|
|
187
187
|
awesome_print
|
188
188
|
codacy-coverage
|
189
189
|
cucumber
|
190
|
-
pry
|
190
|
+
pry (>= 0.14.2)
|
191
191
|
pry-rescue
|
192
192
|
pry-stack_explorer
|
193
193
|
pubnub!
|
data/LICENSE.txt
CHANGED
@@ -1,30 +1,29 @@
|
|
1
|
-
PubNub
|
2
|
-
Copyright
|
3
|
-
http://www.pubnub.com/
|
4
|
-
http://www.pubnub.com/terms
|
1
|
+
PubNub Software Development Kit License Agreement
|
2
|
+
Copyright © 2023 PubNub Inc. All rights reserved.
|
5
3
|
|
6
|
-
|
4
|
+
Subject to the terms and conditions of the license, you are hereby granted
|
5
|
+
a non-exclusive, worldwide, royalty-free license to (a) copy and modify
|
6
|
+
the software in source code or binary form for use with the software services
|
7
|
+
and interfaces provided by PubNub, and (b) redistribute unmodified copies
|
8
|
+
of the software to third parties. The software may not be incorporated in
|
9
|
+
or used to provide any product or service competitive with the products
|
10
|
+
and services of PubNub.
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
"Software"), to deal in the Software without restriction, including
|
11
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
12
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
-
permit persons to whom the Software is furnished to do so, subject to
|
14
|
-
the following conditions:
|
12
|
+
The above copyright notice and this license shall be included
|
13
|
+
in or with all copies or substantial portions of the software.
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
This license does not grant you permission to use the trade names, trademarks,
|
16
|
+
service marks, or product names of PubNub, except as required for reasonable
|
17
|
+
and customary use in describing the origin of the software and reproducing
|
18
|
+
the content of this license.
|
18
19
|
|
19
|
-
THE SOFTWARE IS PROVIDED
|
20
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
-
|
23
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
-
|
25
|
-
|
20
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF
|
21
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
23
|
+
EVENT SHALL PUBNUB OR THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE
|
24
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
25
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
26
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
http://www.pubnub.com/
|
30
|
-
http://www.pubnub.com/terms
|
28
|
+
https://www.pubnub.com/
|
29
|
+
https://www.pubnub.com/terms
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.3.1
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
require 'pubnub'
|
4
|
+
|
5
|
+
Given(/^Crypto module with '([^']*)' cryptor$/) do |cryptor_id|
|
6
|
+
@cryptor_ids = [cryptor_id]
|
7
|
+
end
|
8
|
+
|
9
|
+
Given(/^Crypto module with default '([^']*)' and additional '([^']*)' cryptors$/) do |cryptor_id1, cryptor_id2|
|
10
|
+
@cryptor_ids = [cryptor_id1, cryptor_id2]
|
11
|
+
end
|
12
|
+
|
13
|
+
Given(/^Legacy code with '([^']*)' cipher key and '(random|constant|-)' vector$/) do |cipher_key, use_random_iv|
|
14
|
+
use_random_iv = use_random_iv != 'constant'
|
15
|
+
@legacy_cryptor = Cryptor.new cipher_key, use_random_iv
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(/^with '([^']*)' cipher key$/) do |cipher_key|
|
19
|
+
@cipher_key = cipher_key
|
20
|
+
end
|
21
|
+
|
22
|
+
Then(/^with '(random|constant|-)' vector$/) do |use_random_iv|
|
23
|
+
@use_random_iv = use_random_iv != 'constant'
|
24
|
+
end
|
25
|
+
|
26
|
+
When(/^I encrypt '([^']*)' file as '([^']*)'$/) do |file_name, _|
|
27
|
+
@source_file_name = file_name
|
28
|
+
@source_file_content = File.binread "sdk-specifications/features/encryption/assets/#{file_name}"
|
29
|
+
@encrypted_content = crypto_module.encrypt @source_file_content
|
30
|
+
if file_name.include? 'empty'
|
31
|
+
@encrypt_status = 'encryption error' if @encrypted_content.nil? && @encrypt_status.nil?
|
32
|
+
@encrypt_status = 'success' if !@encrypted_content.nil? && @encrypt_status.nil?
|
33
|
+
else
|
34
|
+
expect(@encrypted_content).not_to eq nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
When(/^I decrypt '([^']*)' file$/) do |file_name|
|
39
|
+
file_content = File.binread "sdk-specifications/features/encryption/assets/#{file_name}"
|
40
|
+
|
41
|
+
begin
|
42
|
+
@decrypted_content = crypto_module.decrypt file_content
|
43
|
+
rescue Pubnub::UnknownCryptorError
|
44
|
+
@decrypt_status = 'unknown cryptor error'
|
45
|
+
end
|
46
|
+
@decrypt_status = 'decryption error' if @decrypted_content.nil? && @decrypt_status.nil?
|
47
|
+
@decrypt_status = 'success' if !@decrypted_content.nil? && @decrypt_status.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
When(/^I decrypt '([^']*)' file as '([^']*)'$/) do |file_name, _|
|
51
|
+
file_content = File.binread "sdk-specifications/features/encryption/assets/#{file_name}"
|
52
|
+
|
53
|
+
begin
|
54
|
+
@decrypted_content = crypto_module.decrypt file_content
|
55
|
+
rescue Pubnub::UnknownCryptorError
|
56
|
+
@decrypt_status = 'unknown cryptor error'
|
57
|
+
end
|
58
|
+
@decrypt_status = 'decryption error' if @decrypted_content.nil? && @decrypt_status.nil?
|
59
|
+
@decrypt_status = 'success' if !@decrypted_content.nil? && @decrypt_status.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
Then(/^Decrypted file content equal to the '([^']*)' file content$/) do |file_name|
|
63
|
+
file_content = File.binread "sdk-specifications/features/encryption/assets/#{file_name}"
|
64
|
+
expect(@decrypted_content).not_to eq nil
|
65
|
+
expect(@decrypted_content).to eq file_content
|
66
|
+
end
|
67
|
+
|
68
|
+
Then('Successfully decrypt an encrypted file with legacy code') do
|
69
|
+
expect(@legacy_cryptor).not_to eq nil
|
70
|
+
base64_encoded = Base64.strict_encode64(@encrypted_content)
|
71
|
+
decrypted_content = @legacy_cryptor.decrypt(base64_encoded)
|
72
|
+
expect(decrypted_content).not_to eq nil
|
73
|
+
expect(decrypted_content).to eq @source_file_content
|
74
|
+
end
|
75
|
+
|
76
|
+
Then(/^I receive '([^']*)'$/) do |outcome|
|
77
|
+
expect(@encrypt_status || @decrypt_status).not_to eq nil
|
78
|
+
expect(@encrypt_status || @decrypt_status).to eq outcome
|
79
|
+
end
|
80
|
+
|
81
|
+
# Crypto module
|
82
|
+
#
|
83
|
+
# @return [Pubnub::Crypto::CryptoModule] Crypto module instance.
|
84
|
+
def crypto_module
|
85
|
+
cryptors = []
|
86
|
+
@cryptor_ids.each do |cryptor_id|
|
87
|
+
cryptor = if cryptor_id == 'acrh'
|
88
|
+
Pubnub::Crypto::AesCbcCryptor.new @cipher_key
|
89
|
+
elsif cryptor_id == 'legacy'
|
90
|
+
Pubnub::Crypto::LegacyCryptor.new @cipher_key, @use_random_iv
|
91
|
+
end
|
92
|
+
cryptors.push(cryptor) unless cryptor.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
raise ArgumentError, "No crypto identifiers specified: #{@cryptor_ids}" if cryptors.empty?
|
96
|
+
|
97
|
+
default_cryptor = cryptors.shift
|
98
|
+
Pubnub::Crypto::CryptoModule.new default_cryptor, cryptors unless default_cryptor.nil?
|
99
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Internal Crypto class used for message encryption and decryption
|
2
|
+
class Cryptor
|
3
|
+
def initialize(cipher_key, use_random_iv)
|
4
|
+
@alg = 'AES-256-CBC'
|
5
|
+
sha256_key = Digest::SHA256.hexdigest(cipher_key.to_s)
|
6
|
+
@key = sha256_key.slice(0, 32)
|
7
|
+
@using_random_iv = use_random_iv
|
8
|
+
@iv = @using_random_iv == true ? random_iv : '0123456789012345'
|
9
|
+
end
|
10
|
+
|
11
|
+
def encrypt(message)
|
12
|
+
aes = OpenSSL::Cipher.new(@alg)
|
13
|
+
aes.encrypt
|
14
|
+
aes.key = @key
|
15
|
+
aes.iv = @iv
|
16
|
+
|
17
|
+
json_message = message.to_json
|
18
|
+
cipher = @using_random_iv == true ? @iv : ''
|
19
|
+
cipher << aes.update(json_message)
|
20
|
+
cipher << aes.final
|
21
|
+
|
22
|
+
Base64.strict_encode64(cipher)
|
23
|
+
end
|
24
|
+
|
25
|
+
def decrypt(cipher_text)
|
26
|
+
undecoded_text = Base64.decode64(cipher_text)
|
27
|
+
iv = @iv
|
28
|
+
|
29
|
+
if cipher_text.length > 16 && @using_random_iv == true
|
30
|
+
iv = undecoded_text.slice!(0..15)
|
31
|
+
end
|
32
|
+
|
33
|
+
decode_cipher = OpenSSL::Cipher.new(@alg).decrypt
|
34
|
+
decode_cipher.key = @key
|
35
|
+
decode_cipher.iv = iv
|
36
|
+
|
37
|
+
plain_text = decryption(undecoded_text, decode_cipher)
|
38
|
+
|
39
|
+
plain_text
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def decryption(cipher_text, decode_cipher)
|
45
|
+
plain_text = decode_cipher.update(cipher_text)
|
46
|
+
plain_text << decode_cipher.final
|
47
|
+
rescue StandardError => e
|
48
|
+
puts "Pubnub :: DECRYPTION ERROR: #{e}"
|
49
|
+
'"DECRYPTION ERROR"'
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def random_iv
|
55
|
+
random_bytes = Random.new.bytes(16).unpack('NnnnnN')
|
56
|
+
format('%08x%04x%04x', *random_bytes)
|
57
|
+
end
|
58
|
+
end
|
data/features/support/hooks.rb
CHANGED
data/lib/pubnub/client.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
|
3
5
|
require 'pubnub/error'
|
4
6
|
require 'pubnub/uuid'
|
5
7
|
require 'pubnub/formatter'
|
6
|
-
require 'pubnub/crypto'
|
7
8
|
require 'pubnub/constants'
|
8
9
|
require 'pubnub/configuration'
|
9
10
|
require 'pubnub/subscribe_callback'
|
10
11
|
|
12
|
+
require 'pubnub/modules/crypto/module'
|
13
|
+
|
11
14
|
require 'pubnub/schemas/envelope_schema'
|
12
15
|
|
13
16
|
require 'pubnub/event'
|
@@ -183,6 +186,7 @@ module Pubnub
|
|
183
186
|
clean_env
|
184
187
|
prepare_env
|
185
188
|
validate! @env
|
189
|
+
setup_crypto_module
|
186
190
|
@telemetry = Telemetry.new
|
187
191
|
Pubnub.logger.debug('Pubnub::Client') do
|
188
192
|
"Created new Pubnub::Client instance. Version: #{Pubnub::VERSION}"
|
@@ -339,6 +343,14 @@ module Pubnub
|
|
339
343
|
@env[:token] = token
|
340
344
|
end
|
341
345
|
|
346
|
+
# Data processing crypto module.
|
347
|
+
#
|
348
|
+
# @return [Pubnub::Crypto::CryptoProvider, nil] Crypto module for data encryption and
|
349
|
+
# decryption.
|
350
|
+
def crypto_module
|
351
|
+
@env[:crypto_module]
|
352
|
+
end
|
353
|
+
|
342
354
|
private
|
343
355
|
|
344
356
|
def create_state_pools(event)
|
@@ -386,9 +398,26 @@ module Pubnub
|
|
386
398
|
Concurrent.global_logger = Pubnub.logger
|
387
399
|
@subscriber = Subscriber.new(self)
|
388
400
|
options[:user_id] = options[:uuid] if options[:user_id].nil?
|
401
|
+
|
402
|
+
if options[:cipher_key] && options[:crypto_module]
|
403
|
+
puts 'It is expected that only cipherKey or cryptoModule will be configured ' \
|
404
|
+
'at once. PubNub client will use the configured cryptoModule.'
|
405
|
+
end
|
406
|
+
|
389
407
|
@env = options
|
390
408
|
end
|
391
409
|
|
410
|
+
# Complete crypto module configuration
|
411
|
+
# Create crypto module if it is required by user (specified
|
412
|
+
# <i>cipher_key</i> and not <i>crypto_module</i>).
|
413
|
+
def setup_crypto_module
|
414
|
+
random_iv = @env[:random_iv]
|
415
|
+
key = @env[:cipher_key]
|
416
|
+
|
417
|
+
# Create crypto module if it is not specified
|
418
|
+
@env[:crypto_module] = Crypto::CryptoModule.new_legacy(key, random_iv) if key && @env[:crypto_module].nil?
|
419
|
+
end
|
420
|
+
|
392
421
|
def prepare_env
|
393
422
|
assign_defaults
|
394
423
|
setup_pools
|
data/lib/pubnub/error.rb
CHANGED
data/lib/pubnub/event.rb
CHANGED
@@ -113,12 +113,12 @@ module Pubnub
|
|
113
113
|
def operation_http_method
|
114
114
|
case @event
|
115
115
|
when Pubnub::Constants::OPERATION_DELETE, Pubnub::Constants::OPERATION_REMOVE_MESSAGE_ACTION,
|
116
|
-
|
117
|
-
|
116
|
+
Pubnub::Constants::OPERATION_REMOVE_CHANNEL_METADATA, Pubnub::Constants::OPERATION_REMOVE_UUID_METADATA,
|
117
|
+
Pubnub::Constants::OPERATION_REVOKE_TOKEN
|
118
118
|
'delete'
|
119
119
|
when Pubnub::Constants::OPERATION_SET_UUID_METADATA, Pubnub::Constants::OPERATION_SET_CHANNEL_METADATA,
|
120
|
-
|
121
|
-
|
120
|
+
Pubnub::Constants::OPERATION_SET_CHANNEL_MEMBERS, Pubnub::Constants::OPERATION_SET_MEMBERSHIPS,
|
121
|
+
Pubnub::Constants::OPERATION_REMOVE_CHANNEL_MEMBERS, Pubnub::Constants::OPERATION_REMOVE_MEMBERSHIPS
|
122
122
|
'patch'
|
123
123
|
when Pubnub::Constants::OPERATION_ADD_MESSAGE_ACTION
|
124
124
|
'post'
|
@@ -170,7 +170,7 @@ module Pubnub
|
|
170
170
|
|
171
171
|
def create_variables_from_options(options)
|
172
172
|
variables = %w[channel channels message http_sync callback
|
173
|
-
ssl cipher_key random_iv secret_key auth_key
|
173
|
+
ssl cipher_key random_iv crypto_module secret_key auth_key
|
174
174
|
publish_key subscribe_key timetoken action_timetoken message_timetoken
|
175
175
|
open_timeout read_timeout idle_timeout heartbeat
|
176
176
|
group action read write delete manage ttl presence start
|
@@ -217,6 +217,14 @@ module Pubnub
|
|
217
217
|
ck.call(data)
|
218
218
|
end
|
219
219
|
|
220
|
+
# Data processing crypto module.
|
221
|
+
#
|
222
|
+
# @return [Pubnub::Crypto::CryptoProvider, nil] Crypto module for data encryption and
|
223
|
+
# decryption.
|
224
|
+
def crypto_module
|
225
|
+
@crypto_module
|
226
|
+
end
|
227
|
+
|
220
228
|
def error_message(parsed_response)
|
221
229
|
parsed_response['message']
|
222
230
|
rescue StandardError
|
@@ -13,8 +13,8 @@ module Pubnub
|
|
13
13
|
|
14
14
|
def fire
|
15
15
|
Pubnub.logger.debug('Pubnub::Add Message Action') { "Fired event #{self.class}" }
|
16
|
-
type_payload = { type: @type, value: @value}
|
17
|
-
body = Formatter.format_message(type_payload,
|
16
|
+
type_payload = { type: @type, value: @value }
|
17
|
+
body = Formatter.format_message(type_payload, nil, false)
|
18
18
|
|
19
19
|
response = send_request(body, { "Content-Type": 'application/json' })
|
20
20
|
|
@@ -34,7 +34,7 @@ module Pubnub
|
|
34
34
|
patterns: prepare_permissions(:pattern, @channels, @channel_groups, @uuids, @spaces_permissions, @users_permissions)
|
35
35
|
}.select { |_, v| v }
|
36
36
|
}
|
37
|
-
body = Formatter.format_message(raw_body,
|
37
|
+
body = Formatter.format_message(raw_body, nil, false)
|
38
38
|
response = send_request(body, { "Content-Type": "application/json" })
|
39
39
|
|
40
40
|
envelopes = fire_callbacks(handle(response, uri))
|
@@ -8,6 +8,11 @@ module Pubnub
|
|
8
8
|
def initialize(options, app)
|
9
9
|
@event = :history
|
10
10
|
@telemetry_name = :l_hist
|
11
|
+
|
12
|
+
# Override crypto module if custom cipher key has been used.
|
13
|
+
random_iv = options.key?(:random_iv) ? options[:random_iv] : true
|
14
|
+
options[:crypto_module] = Crypto::CryptoModule.new_legacy(options[:cipher_key], random_iv) if options[:cipher_key]
|
15
|
+
|
11
16
|
super
|
12
17
|
end
|
13
18
|
|
@@ -63,23 +68,30 @@ module Pubnub
|
|
63
68
|
|
64
69
|
def decrypt_history(message, crypto)
|
65
70
|
if @include_token || @include_meta
|
66
|
-
|
71
|
+
encrypted_message = Base64.decode64(message['message'])
|
72
|
+
message['message'] = JSON.parse(crypto.decrypt(encrypted_message), quirks_mode: true)
|
67
73
|
|
68
74
|
message
|
69
75
|
else
|
70
|
-
|
76
|
+
encrypted_message = Base64.decode64(message)
|
77
|
+
JSON.parse(crypto.decrypt(encrypted_message), quirks_mode: true)
|
71
78
|
end
|
72
79
|
end
|
73
80
|
|
74
81
|
def valid_envelope(parsed_response, req_res_objects)
|
75
82
|
messages = parsed_response[0]
|
76
83
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
crypto = Crypto.new(cipher_key, random_iv)
|
84
|
+
# TODO: Uncomment code below when cryptor implementations will be added.
|
85
|
+
if crypto_module && messages
|
86
|
+
crypto = crypto_module
|
81
87
|
messages = messages.map { |message| decrypt_history(message, crypto) }
|
82
88
|
end
|
89
|
+
# if (@cipher_key || @app.env[:cipher_key] || @cipher_key_selector || @app.env[:cipher_key_selector]) && messages
|
90
|
+
# cipher_key = compute_cipher_key(parsed_response)
|
91
|
+
# random_iv = compute_random_iv(parsed_response)
|
92
|
+
# crypto = Crypto.new(cipher_key, random_iv)
|
93
|
+
# messages = messages.map { |message| decrypt_history(message, crypto) }
|
94
|
+
# end
|
83
95
|
|
84
96
|
start = parsed_response[1]
|
85
97
|
finish = parsed_response[2]
|
@@ -10,6 +10,11 @@ module Pubnub
|
|
10
10
|
def initialize(options, app)
|
11
11
|
@event = :publish
|
12
12
|
@telemetry_name = :l_pub
|
13
|
+
|
14
|
+
# Override crypto module if custom cipher key has been used.
|
15
|
+
random_iv = options.key?(:random_iv) ? options[:random_iv] : true
|
16
|
+
options[:crypto_module] = Crypto::CryptoModule.new_legacy(options[:cipher_key], random_iv) if options[:cipher_key]
|
17
|
+
|
13
18
|
super
|
14
19
|
@sequence_number = sequence_number!
|
15
20
|
@origination_time_token = @app.generate_ortt
|
@@ -25,9 +30,8 @@ module Pubnub
|
|
25
30
|
|
26
31
|
def fire
|
27
32
|
Pubnub.logger.debug('Pubnub::Publish') { "Fired event #{self.class}" }
|
28
|
-
|
29
33
|
if @compressed
|
30
|
-
compressed_body = Formatter.format_message(@message, @
|
34
|
+
compressed_body = Formatter.format_message(@message, @crypto_module, false)
|
31
35
|
response = send_request(compressed_body)
|
32
36
|
else
|
33
37
|
response = send_request
|
@@ -72,7 +76,7 @@ module Pubnub
|
|
72
76
|
'0',
|
73
77
|
Formatter.format_channel(@channel, true),
|
74
78
|
'0',
|
75
|
-
Formatter.format_message(@message, @
|
79
|
+
Formatter.format_message(@message, @crypto_module)
|
76
80
|
]
|
77
81
|
|
78
82
|
rpath.pop if @compressed
|
@@ -42,7 +42,7 @@ module Pubnub
|
|
42
42
|
{ uuid: { id: member } }
|
43
43
|
end
|
44
44
|
|
45
|
-
body = Formatter.format_message({ delete: members },
|
45
|
+
body = Formatter.format_message({ delete: members }, nil, false)
|
46
46
|
response = send_request(body)
|
47
47
|
|
48
48
|
envelopes = fire_callbacks(handle(response, uri))
|
@@ -83,11 +83,11 @@ module Pubnub
|
|
83
83
|
def valid_envelope(parsed_response, req_res_objects)
|
84
84
|
members = parsed_response['data'].map { |channel_member|
|
85
85
|
member = Hash.new
|
86
|
-
channel_member.each{ |k,v| member[k.to_sym] = v }
|
86
|
+
channel_member.each { |k, v| member[k.to_sym] = v }
|
87
87
|
|
88
88
|
unless member[:uuid].nil?
|
89
89
|
uuid_metadata = Hash.new
|
90
|
-
member[:uuid].each{ |k,v| uuid_metadata[k.to_sym] = v }
|
90
|
+
member[:uuid].each { |k, v| uuid_metadata[k.to_sym] = v }
|
91
91
|
uuid_metadata[:updated] = Date._parse(uuid_metadata[:updated]) unless uuid_metadata[:updated].nil?
|
92
92
|
member[:uuid] = uuid_metadata
|
93
93
|
end
|
@@ -17,7 +17,7 @@ module Pubnub
|
|
17
17
|
def fire
|
18
18
|
Pubnub.logger.debug('Pubnub::RemoveChannelMetadata') { "Fired event #{self.class}" }
|
19
19
|
|
20
|
-
body = Formatter.format_message(@data,
|
20
|
+
body = Formatter.format_message(@data, nil, false)
|
21
21
|
response = send_request(body)
|
22
22
|
|
23
23
|
envelopes = fire_callbacks(handle(response, uri))
|
@@ -42,7 +42,7 @@ module Pubnub
|
|
42
42
|
{ channel: { id: membership } }
|
43
43
|
end
|
44
44
|
|
45
|
-
body = Formatter.format_message({ delete: memberships },
|
45
|
+
body = Formatter.format_message({ delete: memberships }, nil, false)
|
46
46
|
response = send_request(body)
|
47
47
|
|
48
48
|
envelopes = fire_callbacks(handle(response, uri))
|
@@ -83,11 +83,11 @@ module Pubnub
|
|
83
83
|
def valid_envelope(parsed_response, req_res_objects)
|
84
84
|
memberships = parsed_response['data'].map { |uuid_membership|
|
85
85
|
membership = Hash.new
|
86
|
-
uuid_membership.each{ |k,v| membership[k.to_sym] = v }
|
86
|
+
uuid_membership.each { |k, v| membership[k.to_sym] = v }
|
87
87
|
|
88
88
|
unless membership[:channel].nil?
|
89
89
|
channel_metadata = Hash.new
|
90
|
-
membership[:channel].each{ |k,v| channel_metadata[k.to_sym] = v }
|
90
|
+
membership[:channel].each { |k, v| channel_metadata[k.to_sym] = v }
|
91
91
|
channel_metadata[:updated] = Date._parse(channel_metadata[:updated]) unless channel_metadata[:updated].nil?
|
92
92
|
membership[:channel] = channel_metadata
|
93
93
|
end
|
@@ -17,7 +17,7 @@ module Pubnub
|
|
17
17
|
def fire
|
18
18
|
Pubnub.logger.debug('Pubnub::RemoveUuidMetadata') { "Fired event #{self.class}" }
|
19
19
|
|
20
|
-
body = Formatter.format_message(@data,
|
20
|
+
body = Formatter.format_message(@data, nil, false)
|
21
21
|
response = send_request(body)
|
22
22
|
|
23
23
|
envelopes = fire_callbacks(handle(response, uri))
|