Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Another approach: use python-cryptography instead#1606

Closed
CdeMills wants to merge 1 commit intoros:melodic-develfrom
CdeMills:melodic-devel
Closed

Another approach: use python-cryptography instead#1606
CdeMills wants to merge 1 commit intoros:melodic-develfrom
CdeMills:melodic-devel

Conversation

@CdeMills
Copy link
Copy Markdown

This introduces a dependency w.r.t. https://cryptography.io/en/latest/

@mikepurvis
Copy link
Copy Markdown
Member

Is this fully compatible with the original approach? Either way, it doesn't seem like we're gaining much in brevity with this new dependency.

Copy link
Copy Markdown
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR aims to address #1599.

The new dependency proposed in this patch (which still needs to be added to the package manifest) is available as of Ubuntu Bionic: python-pycryptodome, python3-pycryptodome

Please describe the pros/cons over the proposed patch in #1609.

encrypted_chunk = cipher.encrypt(_add_padding(chunk))
# cipher = AES.new(self._symmetric_key, AES.MODE_CBC, iv)
cipher = Cipher(algorithms.AES(self._symmetric_key), modes.CBC(iv), backend=backend)
encryptor = cipher.encryptor()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of using this different API?

iv = Random.new().read(AES.block_size)
# iv = Random.new().read(AES.block_size)
backend = default_backend()
iv = os.urandom(AES_BLOCK_SIZE)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference of os.urandom over Random?

@CdeMills
Copy link
Copy Markdown
Author

CdeMills commented Feb 1, 2019

Hello,
pro and cons are difficult to tell. Those are two crypto lib aiming at implementing the same functionalities. pyca/cryptography is linked with OpenSSL, while cryptodome isn't. I think the choice should also rely on timing both approaches.
Regards

Pascal

@dirk-thomas
Copy link
Copy Markdown
Member

Comparing the statistics of the two GitHub repos I would think cryptography is the more mature and active project compared to pycryptodome.

Therefore I closed the other PR.

@CdeMills Please answer the pending questions when you have a chance and also update the package manifest to add the new dependency (and replace the old one).

raise ROSBagFormatException('Error in encrypted chunk size: {}'.format(len(encrypted_chunk)))
if len(encrypted_chunk) < AES.block_size:
# if len(encrypted_chunk) < AES.block_size:
if len(encrypted_chunk) < AES.BLOCK_SIZE:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AES.BLOCK_SIZE doesn't exist. Either AES_BLOCK_SIZE or AES.block_size.

return
self._symmetric_key = Random.new().read(AES.block_size)
# self._symmetric_key = Random.new().read(AES.block_size)
self._symmetric_key = os.urandom(AES.block_size)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why AES.block_size here instead of AES_BLOCK_SIZE?

cipher = Cipher(algorithms.AES(self._symmetric_key), modes.CBC(iv), backend=backend)
decryptor = cipher.decryptor()
# header = cipher.decrypt(encrypted_header)
header = decryptor_update(encrypted_header) + decryptor_finalize()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be decryptor.update(...

#from Crypto import Random
# from Crypto.Cipher import AES
# taken from Crypto.Cipher.AES.block_size
AES_BLOCK_SIZE = 16
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use this constant over AES.block_size (which is 128)?

@dirk-thomas
Copy link
Copy Markdown
Member

The passing CI clearly indicates that non of the touched code is covered by unit tests. Otherwise they would have failed due to the bugs in the current patch.

@dirk-thomas
Copy link
Copy Markdown
Member

Closing in favor of #1793 which redos this patch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants