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

"TypeError: Expected instance of hashes.HashAlgorithm." when using cryptography>=41.0.0 #100

Open
hoelsner opened this issue Jul 5, 2023 · 1 comment

Comments

@hoelsner
Copy link

hoelsner commented Jul 5, 2023

Hello,

I updated to cryptograpy 41.0.0 which breaks django-cryptography for me with the following exception (together with django 4.1.9 and python3.11):

  File "/home/vscode/.local/lib/python3.11/site-packages/django_cryptography/fields.py", line 9, in <module>
    from django_cryptography.core.signing import SignatureExpired
  File "/home/vscode/.local/lib/python3.11/site-packages/django_cryptography/core/signing.py", line 23, in <module>
    from ..utils.crypto import constant_time_compare, salted_hmac
  File "/home/vscode/.local/lib/python3.11/site-packages/django_cryptography/utils/crypto.py", line 12, in <module>
    from ..conf import CryptographyConf
  File "/home/vscode/.local/lib/python3.11/site-packages/django_cryptography/conf.py", line 9, in <module>
    class CryptographyConf(AppConf):
  File "/home/vscode/.local/lib/python3.11/site-packages/appconf/base.py", line 73, in __new__
    new_class._configure()
  File "/home/vscode/.local/lib/python3.11/site-packages/appconf/base.py", line 104, in _configure
    cls._meta.configured_data = obj.configure()
                                ^^^^^^^^^^^^^^^
  File "/home/vscode/.local/lib/python3.11/site-packages/django_cryptography/conf.py", line 34, in configure
    self.configured_data['KEY'] = kdf.derive(
                                  ^^^^^^^^^^^
  File "/home/vscode/.local/lib/python3.11/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py", line 53, in derive
    return rust_openssl.kdf.derive_pbkdf2_hmac(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Expected instance of hashes.HashAlgorithm.

My Django project uses the following settings:

CRYPTOGRAPHY_BACKEND = cryptography.hazmat.backends.default_backend()
CRYPTOGRAPHY_DIGEST = cryptography.hazmat.primitives.hashes.SHA256

I have tried multiple hash algorithms and different combinations, but I always get this issue. Do you have any ideas on how to fix it? If I downgrade to 40.0.2, it's works again.

Thank you in advance.

@Nasjoe
Copy link

Nasjoe commented Aug 24, 2023

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants