PyCrypto is dead. Switch to PyCryptodome

This commit is contained in:
jnozsc 2017-09-16 11:05:01 -07:00
parent 9ffca1a7a6
commit 4bdc082fc7
7 changed files with 12 additions and 13 deletions

View file

@ -10,7 +10,7 @@ python:
- "nightly" - "nightly"
install: install:
- "pip install -e ." - "pip install -e ."
- "pip install pycrypto>=2.6" - "pip install pycryptodome>=3.4"
- "pip install -q behave" - "pip install -q behave"
# command to run tests # command to run tests
script: script:

View file

@ -119,4 +119,3 @@ Known Issues
~~~~~~~~~~~~ ~~~~~~~~~~~~
- The Windows shell prior to Windows 7 has issues with unicode encoding. If you want to use non-ascii characters, change the codepage with ``chcp 1252`` before using `jrnl` (Thanks to Yves Pouplard for solving this!) - The Windows shell prior to Windows 7 has issues with unicode encoding. If you want to use non-ascii characters, change the codepage with ``chcp 1252`` before using `jrnl` (Thanks to Yves Pouplard for solving this!)
- _jrnl_ relies on the `PyCrypto` package to encrypt journals, which has some known problems with installing on Windows and within virtual environments.

View file

@ -28,7 +28,7 @@ to install the dependencies for encrypting journals as well.
.. note:: .. note::
Installing the encryption library, `pycrypto`, requires a `gcc` compiler. For this reason, jrnl will not install `pycrypto` unless explicitly told so like this. You can `install PyCrypto manually <https://www.dlitz.net/software/pycrypto/>`_ first or install it with ``pip install pycrypto`` if you have a `gcc` compiler. Installing the encryption library, `pycryptodome`, requires a `gcc` compiler. For this reason, jrnl will not install `pycryptodome` unless explicitly told so like this. You can install it with ``pip install pycryptodome`` if you have a `gcc` compiler.
Also note that when using zsh, the correct syntax is ``pip install "jrnl[encrypted]"`` (note the quotes). Also note that when using zsh, the correct syntax is ``pip install "jrnl[encrypted]"`` (note the quotes).

View file

@ -45,7 +45,7 @@ class Journal(object):
def _decrypt(self, cipher): def _decrypt(self, cipher):
"""Decrypts a cipher string using self.key as the key and the first 16 byte of the cipher as the IV""" """Decrypts a cipher string using self.key as the key and the first 16 byte of the cipher as the IV"""
if not crypto_installed: if not crypto_installed:
sys.exit("Error: PyCrypto is not installed.") sys.exit("Error: pycryptodome is not installed.")
if not cipher: if not cipher:
return "" return ""
crypto = AES.new(self.key, AES.MODE_CBC, cipher[:16]) crypto = AES.new(self.key, AES.MODE_CBC, cipher[:16])
@ -71,8 +71,8 @@ class Journal(object):
def _encrypt(self, plain): def _encrypt(self, plain):
"""Encrypt a plaintext string using self.key as the key""" """Encrypt a plaintext string using self.key as the key"""
if not crypto_installed: if not crypto_installed:
sys.exit("Error: PyCrypto is not installed.") sys.exit("Error: pycryptodome is not installed.")
Random.atfork() # A seed for PyCrypto Random.atfork() # A seed for pycryptodome
iv = Random.new().read(AES.block_size) iv = Random.new().read(AES.block_size)
crypto = AES.new(self.key, AES.MODE_CBC, iv) crypto = AES.new(self.key, AES.MODE_CBC, iv)
plain = plain.encode("utf-8") plain = plain.encode("utf-8")

View file

@ -21,7 +21,7 @@ import logging
xdg_config = os.environ.get('XDG_CONFIG_HOME') xdg_config = os.environ.get('XDG_CONFIG_HOME')
CONFIG_PATH = os.path.join(xdg_config, "jrnl") if xdg_config else os.path.expanduser('~/.jrnl_config') CONFIG_PATH = os.path.join(xdg_config, "jrnl") if xdg_config else os.path.expanduser('~/.jrnl_config')
PYCRYPTO = install.module_exists("Crypto") PYCRYPTODOME = install.module_exists("Crypto")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -148,8 +148,8 @@ def run(manual_args=None):
log.debug('Using configuration "%s"', config) log.debug('Using configuration "%s"', config)
original_config = config.copy() original_config = config.copy()
# check if the configuration is supported by available modules # check if the configuration is supported by available modules
if config['encrypt'] and not PYCRYPTO: if config['encrypt'] and not PYCRYPTODOME:
util.prompt("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.") util.prompt("According to your jrnl_conf, your journal is encrypted, however pycryptodome was not found. To open your journal, install the pycryptodome package from https://www.pycryptodome.org .")
sys.exit(1) sys.exit(1)
# If the first textual argument points to a journal file, # If the first textual argument points to a journal file,
@ -250,8 +250,8 @@ def run(manual_args=None):
elif args.export is not False: elif args.export is not False:
print(util.py2encode(exporters.export(journal, args.export, args.output))) print(util.py2encode(exporters.export(journal, args.export, args.output)))
elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO: elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTODOME:
util.prompt("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.") util.prompt("pycryptodome not found. To encrypt or decrypt your journal, install the pycryptodome package from https://www.pycryptodome.org .")
elif args.encrypt is not False: elif args.encrypt is not False:
encrypt(journal, filename=args.encrypt) encrypt(journal, filename=args.encrypt)

View file

@ -79,7 +79,7 @@ def install_jrnl(config_path='~/.jrnl_config'):
print("Journal will be encrypted.") print("Journal will be encrypted.")
else: else:
password = None password = None
print("PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.") print("pycryptodome not found. To encrypt your journal, install the pycryptodome package from https://www.pycryptodome.org or with 'pip install pycryptodome' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.")
path = os.path.split(default_config['journals']['default'])[0] # If the folder doesn't exist, create it path = os.path.split(default_config['journals']['default'])[0] # If the folder doesn't exist, create it
try: try:

View file

@ -149,7 +149,7 @@ setup(
"keyrings.alt>=1.3", "keyrings.alt>=1.3",
] + [p for p, cond in conditional_dependencies.items() if cond], ] + [p for p, cond in conditional_dependencies.items() if cond],
extras_require = { extras_require = {
"encrypted": "pycrypto>=2.6" "encrypted": "pycryptodome>=3.4"
}, },
long_description=__doc__, long_description=__doc__,
entry_points={ entry_points={