SendSafely / Python-Client-API

SendSafely API for Python
Apache License 2.0
6 stars 6 forks source link

cryptography package breaking change: AttributeError: module ‘cryptography.utils’ has no attribute ‘register_interface’ #4

Open brenthc opened 2 years ago

brenthc commented 2 years ago

The issue is described in full here:

https://jasonralph.org/?p=997

As a workaround that worked for me, as described in the article:

sudo python3 -m pip install PGPy
sudo python3 -m pip uninstall -y cryptography
sudo python3 -m pip install cryptography==37.0.4

Full traceback from use of zdgrab, which uses ssgrab, which uses sendsafely:

Traceback (most recent call last):
  File "/Users/brent/.pyenv/versions/3.10.3/bin/zdgrab", line 33, in <module>
    sys.exit(load_entry_point('zdgrab', 'console_scripts', 'zdgrab')())
  File "/Users/brent/.pyenv/versions/3.10.3/bin/zdgrab", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/brent/code/zdgrab/zdgrab.py", line 22, in <module>
    from ssgrab import ssgrab
  File "/Users/brent/code/ssgrab/ssgrab.py", line 16, in <module>
    import sendsafely
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sendsafely-1.0.1-py3.10.egg/sendsafely/__init__.py", line 1, in <module>
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sendsafely-1.0.1-py3.10.egg/sendsafely/SendSafely.py", line 4, in <module>
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PGPy-0.5.4-py3.10.egg/pgpy/__init__.py", line 4, in <module>
    from .pgp import PGPKey
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PGPy-0.5.4-py3.10.egg/pgpy/pgp.py", line 27, in <module>
    from .constants import CompressionAlgorithm
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PGPy-0.5.4-py3.10.egg/pgpy/constants.py", line 23, in <module>
    from ._curves import BrainpoolP256R1, BrainpoolP384R1, BrainpoolP512R1, X25519, Ed25519
  File "/Users/brent/.pyenv/versions/3.10.3/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PGPy-0.5.4-py3.10.egg/pgpy/_curves.py", line 37, in <module>
    @utils.register_interface(ec.EllipticCurve)
AttributeError: module 'cryptography.utils' has no attribute 'register_interface'. Did you mean: 'verify_interface'?
eshabhide commented 1 year ago

Running into the same issue. Can the mods address?

SendSafely-GitHub commented 1 year ago

Hi Folks --

Based on our analysis, this issue appears to be due to a breaking change in the cryptography module (v38.0.x) that is impacting the PGPy library that we rely on for OpenPGP encryption. There is currently an open issue in the PGPy repo tracking a fix: https://github.com/SecurityInnovation/PGPy/issues/402

Once the issue has been fixed, the breaking change should no longer affect the SendSafely Python API. Until then, we recommend using the workaround below (until the PGPy library is updated):

pip uninstall -y cryptography
pip install cryptography==37.0.4

We will leave this issue open until we can confirm that the PGPy fix has been released.

klabarge commented 1 year ago

I wanted to add an additional error that I received when using cryptography version > 37.0.4

I had cryptography version 41.0.2 and the error I received was ImportError: cannot import name 'CryptographyDeprecationWarning' from 'cryptography'

Installing version 37.0.4 fixes this problem.

python3 sendsafely_python_example.py
Traceback (most recent call last):
  File "/Users/kyle/git/my_project/Python-Client-API/scripts/sendsafely_python_example.py", line 3, in <module>
    from sendsafely import SendSafely, Package
  File "/Users/kyle/git/my_project/sendsafely/lib/python3.11/site-packages/sendsafely/__init__.py", line 1, in <module>
    from sendsafely.SendSafely import SendSafely
  File "/Users/kyle/git/my_project/sendsafely/lib/python3.11/site-packages/sendsafely/SendSafely.py", line 7, in <module>
    from cryptography import CryptographyDeprecationWarning
ImportError: cannot import name 'CryptographyDeprecationWarning' from 'cryptography' (/Users/kyle/git/my_project/sendsafely/lib/python3.11/site-packages/cryptography/__init__.py)