-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add crypto module #151
Add crypto module #151
Conversation
Decouple code which works with data encryption and decryption into separate module.
Move old crypto code to specs for tests purpose only. test(contract): add steps definitions for crypto module fix(crypto): decrypt empty return immediately Return empty data from `decrypt` methods immediately if encrypted data is empty.
encrypted_message = Base64.decode64(message[:payload]) | ||
JSON.parse(crypto_module.decrypt(encrypted_message), quirks_mode: true) | ||
# | ||
# return message[:payload] if message[:channel].end_with?('-pnpres') || (@app.env[:cipher_key].nil? && @cipher_key.nil? && @cipher_key_selector.nil? && @env[:cipher_key_selector].nil?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this stays commented or to be deleted?
lib/pubnub/formatter.rb
Outdated
else | ||
message = message.to_json | ||
message = Formatter.encode(message) if uri_escape | ||
# def format_message(message, cipher_key = '', use_random_iv = false, uri_escape = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about this commented code. It stays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seba-aln good catch! I forgot to clean it up.
if cryptor.nil? | ||
identifier = header.identifier || 'UNKN' | ||
raise UnknownCryptorError, { | ||
message: "Decrypting data created by unknown cryptor. Please make sure to register |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a Ruby formatting thing or a typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seba-aln what typo?
# Legacy payload doesn't have header. | ||
return 0 if @data.nil? | ||
|
||
9 + (data_size < 255 ? 1 : 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall header size doesn't return the header size + data length? or the docs are misleading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns the size of the header (how many bytes encode header information) – it used to compute offsets in data and pull out crypto-defined data followed by encrypted data.
…ruby into CLEN-1588/decouple-crypto-module
@pubnub-release-bot release |
🚀 Release successfully completed 🚀 |
feat(crypto): add crypto module
Add crypto module that allows to configure SDK to encrypt and decrypt messages.
fix(crypto): fix legacy cryptor
Improved security of crypto implementation by adding enhanced AES-CBC cryptor.