pyca / cryptography

cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.
https://cryptography.io
Other
6.57k stars 1.51k forks source link

AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' #10337

Closed SatyanarayanaHouji closed 7 months ago

SatyanarayanaHouji commented 7 months ago

from OpenSSL import crypto from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization

I am currently using cryptography v42.0.2 & pyOpenSSL v24.0.0 trying to run from the script by importing as above end up with below errors:

  1. AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes'
  2. ImportError: cannot import name 'exceptions' from 'cryptography.hazmat.bindings._rust' (unknown location)

please help us to suggest how to fix this error?

reaperhulk commented 7 months ago

Please give us instructions on how to reproduce this in a clean virtual environment.

SatyanarayanaHouji commented 7 months ago

I am trying to Authenticate one module using some code end up with below errors in bazel environment: ERROR: Loading module scapy.layers.dcerpc Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\dcerpc.py", line 31, in from scapy.layers.ntlm import NTLM_Header File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.dot11 Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib__init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\dot11.py", line 65, in from cryptography.hazmat.primitives.ciphers import Cipher, algorithms File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\ciphers__init.py", line 11, in from cryptography.hazmat.primitives.ciphers.base import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\ciphers\base.py", line 10, in from cryptography.exceptions import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\exceptions.py", line 9, in from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions ImportError: cannot import name 'exceptions' from 'cryptography.hazmat.bindings._rust' (unknown location) ERROR: Loading module scapy.layers.ipsec Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib__init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ipsec.py", line 161, in from cryptography.exceptions import InvalidTag File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\exceptions.py", line 9, in from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions ImportError: cannot import name 'exceptions' from 'cryptography.hazmat.bindings._rust' (unknown location) ERROR: Loading module scapy.layers.ldap Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib__init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ldap.py", line 33, in from scapy.layers.ntlm import NTLM_Client File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.mspac Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib\init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\mspac.py", line 38, in from scapy.layers.dcerpc import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\dcerpc.py", line 31, in from scapy.layers.ntlm import NTLM_Header File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.ntlm Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib\init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.smb Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib\init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\smb.py", line 42, in from scapy.layers.gssapi import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\gssapi.py", line 57, in from scapy.layers.ntlm import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.smb2 Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib\init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\smb2.py", line 52, in from scapy.layers.gssapi import GSSAPI_BLOB File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\gssapi.py", line 57, in from scapy.layers.ntlm import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.smbclient Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib\init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\smbclient.py", line 11, in from scapy.layers.ntlm import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' ERROR: Loading module scapy.layers.smbserver Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\main.py", line 156, in _load mod = importlib.import_module(module) File "C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\python39_windows\lib\importlib\init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\smbserver.py", line 13, in from scapy.layers.ntlm import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\scapy_taf\scapy\layers\ntlm.py", line 74, in from cryptography.hazmat.primitives import hashes, hmac File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\primitives\hashes.py", line 87, in Hash = rust_openssl.hashes.Hash AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' Traceback (most recent call last): File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\ddad\platform\tools\avf\cli_code\test_with_HW.py", line 34, in from main import taf_tester,taf_tester_mpad_2 File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\ddad\platform\tools\avf\cli_code\test\main.py", line 35, in from adaptive_platform_services_verification.msm import msm_kx_mpad1_doip File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\ddad\platform\tools\avf\cli_code\test\adaptive_platform_services_verification\msm.py", line 22, in from src.dosoad.Dosoad_Commands import SOAD File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\ddad\platform\tools\avf\cli_code\src\dosoad\Dosoad_Commands.py", line 5, in from OpenSSL import crypto File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\pyOpenSSL_taf_windows\OpenSSL\init__.py", line 8, in from OpenSSL import SSL, crypto File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\pyOpenSSL_taf_windows\OpenSSL\SSL.py", line 10, in from OpenSSL._util import ( File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\pyOpenSSL_taf_windows\OpenSSL_util.py", line 6, in from cryptography.hazmat.bindings.openssl.binding import Binding File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\hazmat\bindings\openssl\binding.py", line 15, in from cryptography.exceptions import InternalError File "\?\C:\Users\ \AppData\Local\Temp\Bazel.runfiles_rdzb_ukn\runfiles\cryptography_taf_windows\cryptography\exceptions.py", line 9, in from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions ImportError: cannot import name 'exceptions' from 'cryptography.hazmat.bindings._rust' (unknown location)

reaperhulk commented 7 months ago

We need a way to reproduce this in a fresh virtual environment. Otherwise it's highly likely that there's something specific to your environment that is causing problems.

github-actions[bot] commented 7 months ago

This issue has been waiting for a reporter response for 3 days. It will be auto-closed if no activity occurs in the next 5 days.

github-actions[bot] commented 7 months ago

This issue has not received a reporter response and has been auto-closed. If the issue is still relevant please leave a comment and we can reopen it.