From 4bdc082fc7d5a4d5f92edabcf883d28a2160f01f Mon Sep 17 00:00:00 2001 From: jnozsc Date: Sat, 16 Sep 2017 11:05:01 -0700 Subject: [PATCH] PyCrypto is dead. Switch to PyCryptodome --- .travis.yml | 2 +- docs/advanced.rst | 1 - docs/installation.rst | 2 +- jrnl/Journal.py | 6 +++--- jrnl/cli.py | 10 +++++----- jrnl/install.py | 2 +- setup.py | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8df432e..6fc71f2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ python: - "nightly" install: - "pip install -e ." - - "pip install pycrypto>=2.6" + - "pip install pycryptodome>=3.4" - "pip install -q behave" # command to run tests script: diff --git a/docs/advanced.rst b/docs/advanced.rst index ac883915..5e6b5a1e 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -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!) -- _jrnl_ relies on the `PyCrypto` package to encrypt journals, which has some known problems with installing on Windows and within virtual environments. diff --git a/docs/installation.rst b/docs/installation.rst index be015055..f6e64b49 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -28,7 +28,7 @@ to install the dependencies for encrypting journals as well. .. 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 `_ 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). diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 92a6774f..ead5c959 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -45,7 +45,7 @@ class Journal(object): 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""" if not crypto_installed: - sys.exit("Error: PyCrypto is not installed.") + sys.exit("Error: pycryptodome is not installed.") if not cipher: return "" crypto = AES.new(self.key, AES.MODE_CBC, cipher[:16]) @@ -71,8 +71,8 @@ class Journal(object): def _encrypt(self, plain): """Encrypt a plaintext string using self.key as the key""" if not crypto_installed: - sys.exit("Error: PyCrypto is not installed.") - Random.atfork() # A seed for PyCrypto + sys.exit("Error: pycryptodome is not installed.") + Random.atfork() # A seed for pycryptodome iv = Random.new().read(AES.block_size) crypto = AES.new(self.key, AES.MODE_CBC, iv) plain = plain.encode("utf-8") diff --git a/jrnl/cli.py b/jrnl/cli.py index 35764734..c2120f7d 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -21,7 +21,7 @@ import logging 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') -PYCRYPTO = install.module_exists("Crypto") +PYCRYPTODOME = install.module_exists("Crypto") log = logging.getLogger(__name__) @@ -148,8 +148,8 @@ def run(manual_args=None): log.debug('Using configuration "%s"', config) original_config = config.copy() # check if the configuration is supported by available modules - if config['encrypt'] and not PYCRYPTO: - 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.") + if config['encrypt'] and not PYCRYPTODOME: + 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) # 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: 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: - util.prompt("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.") + elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTODOME: + 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: encrypt(journal, filename=args.encrypt) diff --git a/jrnl/install.py b/jrnl/install.py index 138cb826..87067fb8 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -79,7 +79,7 @@ def install_jrnl(config_path='~/.jrnl_config'): print("Journal will be encrypted.") else: 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 try: diff --git a/setup.py b/setup.py index 851170bb..c3145ff0 100644 --- a/setup.py +++ b/setup.py @@ -149,7 +149,7 @@ setup( "keyrings.alt>=1.3", ] + [p for p, cond in conditional_dependencies.items() if cond], extras_require = { - "encrypted": "pycrypto>=2.6" + "encrypted": "pycryptodome>=3.4" }, long_description=__doc__, entry_points={