Skip to content

Commit 0acb1d8

Browse files
authored
Return unencrypted data (#156)
refactor(crypto): return unencrypted data Return source event data when a client configured with crypto is unable to decrypt it (can be not encrypted data or encrypted with different options)
1 parent e553ac2 commit 0acb1d8

File tree

13 files changed

+535
-212
lines changed

13 files changed

+535
-212
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
2-
version: "5.3.1"
2+
version: "5.3.2"
33
changelog:
4+
- date: 2023-11-23
5+
version: v5.3.2
6+
changes:
7+
- type: improvement
8+
text: "Return source event data when a client configured with crypto is unable to decrypt it (can be not encrypted data or encrypted with different options)."
49
- date: 2023-11-03
510
version: v5.3.1
611
changes:
@@ -675,7 +680,7 @@ sdks:
675680
- x86-64
676681
- distribution-type: package
677682
distribution-repository: RubyGems
678-
package-name: pubnub-5.3.1.gem
683+
package-name: pubnub-5.3.2.gem
679684
location: https://rubygems.org/gems/pubnub
680685
requires:
681686
- name: addressable
@@ -780,8 +785,8 @@ sdks:
780785
- x86-64
781786
- distribution-type: library
782787
distribution-repository: GitHub release
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
788+
package-name: pubnub-5.3.2.gem
789+
location: https://github.com/pubnub/ruby/releases/download/v5.3.2/pubnub-5.3.2.gem
785790
requires:
786791
- name: addressable
787792
min-version: 2.0.0

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v5.3.2
2+
November 23 2023
3+
4+
#### Modified
5+
- Return source event data when a client configured with crypto is unable to decrypt it (can be not encrypted data or encrypted with different options).
6+
17
## v5.3.1
28
November 03 2023
39

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pubnub (5.3.1)
4+
pubnub (5.3.2)
55
addressable (>= 2.0.0)
66
concurrent-ruby (~> 1.1.5)
77
concurrent-ruby-edge (~> 0.5.0)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.3.1
1+
5.3.2

fixtures/vcr_cassettes/examples/history/crypto_1.yml

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/vcr_cassettes/examples/history/crypto_2.yml

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/vcr_cassettes/examples/history/crypto_3.yml

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pubnub/events/history.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,26 @@ def parameters(*_args)
6868

6969
def decrypt_history(message, crypto)
7070
if @include_token || @include_meta
71-
encrypted_message = Base64.decode64(message['message'])
71+
encrypted_message = Base64.strict_decode64(message['message'])
7272
message['message'] = JSON.parse(crypto.decrypt(encrypted_message), quirks_mode: true)
73-
7473
message
7574
else
76-
encrypted_message = Base64.decode64(message)
75+
encrypted_message = Base64.strict_decode64(message)
7776
JSON.parse(crypto.decrypt(encrypted_message), quirks_mode: true)
7877
end
78+
rescue StandardError => e
79+
puts "Pubnub :: DECRYPTION ERROR: #{e}"
80+
message['decrypt_error'] = true if @include_token || @include_meta
81+
message
7982
end
8083

8184
def valid_envelope(parsed_response, req_res_objects)
8285
messages = parsed_response[0]
8386

84-
# TODO: Uncomment code below when cryptor implementations will be added.
8587
if crypto_module && messages
8688
crypto = crypto_module
8789
messages = messages.map { |message| decrypt_history(message, crypto) }
8890
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
9591

9692
start = parsed_response[1]
9793
finish = parsed_response[2]

lib/pubnub/formatter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def format_uuid(uuids, should_encode = true)
4141
end
4242
end
4343

44-
# TODO: Uncomment code below when cryptor implementations will be added.
4544
# Transforms message to json and encode it.
4645
#
4746
# @param message [Hash, String, Integer, Boolean] Message data which

lib/pubnub/subscribe_event/formatter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ def build_error_envelopes(_parsed_response, error, req_res_objects)
3333
end
3434

3535
def decipher_payload(message)
36-
# TODO: Uncomment code below when cryptor implementations will be added.
3736
return message[:payload] if message[:channel].end_with?('-pnpres') || crypto_module.nil?
3837

39-
encrypted_message = Base64.decode64(message[:payload])
38+
encrypted_message = Base64.strict_decode64(message[:payload])
4039
JSON.parse(crypto_module.decrypt(encrypted_message), quirks_mode: true)
4140
rescue StandardError, UnknownCryptorError
4241
message[:payload]

0 commit comments

Comments
 (0)