@@ -745,10 +745,13 @@ def isCryptographyValid():
745745 Check if the cryptography module >= 2.0.0 is present. This is the minimum
746746 version for most usages in Scapy.
747747 """
748+ # Check import
748749 try :
749750 import cryptography
750751 except ImportError :
751752 return False
753+
754+ # Check minimum version
752755 return _version_checker (cryptography , (2 , 0 , 0 ))
753756
754757
@@ -771,6 +774,23 @@ def isCryptographyAdvanced():
771774 return True
772775
773776
777+ def isCryptographyBackendCompatible () -> bool :
778+ """
779+ Check if the cryptography backend is compatible
780+ """
781+ # Check for LibreSSL
782+ try :
783+ from cryptography .hazmat .backends import default_backend
784+ if "LibreSSL" in default_backend ().openssl_version_text ():
785+ # BUG: LibreSSL - https://marc.info/?l=libressl&m=173846028619304&w=2
786+ # It takes 5 whole minutes to import RFC3526's modp parameters. This is
787+ # not okay.
788+ return False
789+ return True
790+ except Exception :
791+ return True
792+
793+
774794def isPyPy ():
775795 # type: () -> bool
776796 """Returns either scapy is running under PyPy or not"""
@@ -1199,6 +1219,17 @@ def __getattribute__(self, attr):
11991219conf = Conf () # type: Conf
12001220
12011221
1222+ if not isCryptographyBackendCompatible ():
1223+ conf .crypto_valid = False
1224+ conf .crypto_valid_advanced = False
1225+ log_scapy .error (
1226+ "Scapy does not support LibreSSL as a backend to cryptography ! "
1227+ "See https://cryptography.io/en/latest/installation/#static-wheels "
1228+ "for instructions on how to recompile cryptography with another "
1229+ "backend."
1230+ )
1231+
1232+
12021233def crypto_validator (func ):
12031234 # type: (DecoratorCallable) -> DecoratorCallable
12041235 """
@@ -1209,7 +1240,7 @@ def func_in(*args, **kwargs):
12091240 # type: (*Any, **Any) -> Any
12101241 if not conf .crypto_valid :
12111242 raise ImportError ("Cannot execute crypto-related method! "
1212- "Please install python-cryptography v1.7 or later." ) # noqa: E501
1243+ "Please install python-cryptography v2.0 or later." ) # noqa: E501
12131244 return func (* args , ** kwargs )
12141245 return func_in
12151246
0 commit comments