Skip to content

Usage of RAND_bytes breaks with cryptography>=45.0 #380

@mweinelt

Description

@mweinelt

With python-jose 3.4.0 and cryptography 45.0.1 I encounter the following error when running the test suite. Versions of cryptography before 45.0 are fine.

The relevant change is in here: pyca/cryptography@fc00112

python-jose> num_bytes = 64
python-jose> 
python-jose>     def get_random_bytes(num_bytes):
python-jose>         """
python-jose>         Get random bytes
python-jose>     
python-jose>         Currently, Cryptography returns OS random bytes. If you want OpenSSL
python-jose>         generated random bytes, you'll have to switch the RAND engine after
python-jose>         initializing the OpenSSL backend
python-jose>         Args:
python-jose>             num_bytes (int): Number of random bytes to generate and return
python-jose>         Returns:
python-jose>             bytes: Random bytes
python-jose>         """
python-jose>         global _binding
python-jose>     
python-jose>         if _binding is None:
python-jose>             _binding = Binding()
python-jose>     
python-jose>         buf = _binding.ffi.new("char[]", num_bytes)
python-jose> >       _binding.lib.RAND_bytes(buf, num_bytes)
python-jose> E       AttributeError: module 'lib' has no attribute 'RAND_bytes'. Did you mean: 'RAND_status'?
python-jose> 
python-jose> jose/backends/cryptography_backend.py:51: AttributeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions