Skip to content
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 pycryptodome as default on melodic #1609

Merged
merged 1 commit into from Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/rosbag/package.xml
Expand Up @@ -30,7 +30,7 @@
<run_depend>boost</run_depend>
<run_depend>genmsg</run_depend>
<run_depend>genpy</run_depend>
<run_depend>python-crypto</run_depend>
<run_depend>python-pycryptodome</run_depend>
Copy link
Member

Choose a reason for hiding this comment

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

There needs to be a rosdep key created for this: https://github.com/ros/rosdistro/blob/master/rosdep/python.yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

<run_depend>python-gnupg</run_depend>
<run_depend>python-rospkg</run_depend>
<run_depend>rosbag_storage</run_depend>
Expand Down
11 changes: 6 additions & 5 deletions tools/rosbag/src/rosbag/bag.py
Expand Up @@ -50,8 +50,9 @@
import time
import yaml

from Crypto import Random
from Crypto.Cipher import AES
from Cryptodome.Cipher import AES
from Cryptodome.Random import random

import gnupg

try:
Expand Down Expand Up @@ -221,7 +222,7 @@ def encrypt_chunk(self, chunk_size, chunk_data_pos, f):
f.seek(chunk_data_pos)
chunk = _read(f, chunk_size)
# Encrypt chunk
iv = Random.new().read(AES.block_size)
iv = random.getrandbits(AES.block_size)
dirk-thomas marked this conversation as resolved.
Show resolved Hide resolved
f.seek(chunk_data_pos)
f.write(iv)
cipher = AES.new(self._symmetric_key, AES.MODE_CBC, iv)
Expand Down Expand Up @@ -299,7 +300,7 @@ def write_encrypted_header(self, _, f, header):
v = v.encode()
header_str += _pack_uint32(len(k) + 1 + len(v)) + k + equal + v

iv = Random.new().read(AES.block_size)
iv = random.getrandbits(AES.block_size)
enc_str = iv
cipher = AES.new(self._symmetric_key, AES.MODE_CBC, iv)
enc_str += cipher.encrypt(_add_padding(header_str))
Expand Down Expand Up @@ -345,7 +346,7 @@ def get_info_str(self):
def _build_symmetric_key(self):
if not self._gpg_key_user:
return
self._symmetric_key = Random.new().read(AES.block_size)
self._symmetric_key = random.getrandbits(AES.block_size)
self._encrypted_symmetric_key = _encrypt_string_gpg(self._gpg_key_user, self._symmetric_key)

def _decrypt_encrypted_header(self, f):
Expand Down