Skip to content

Commit 40fc5ec

Browse files
authored
OpenBSD: fix tests and disallow LibreSSL (#4888)
1 parent 9c3d51c commit 40fc5ec

File tree

11 files changed

+59
-14
lines changed

11 files changed

+59
-14
lines changed

scapy/config.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
774794
def isPyPy():
775795
# type: () -> bool
776796
"""Returns either scapy is running under PyPy or not"""
@@ -1199,6 +1219,17 @@ def __getattribute__(self, attr):
11991219
conf = 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+
12021233
def 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

scapy/contrib/automotive/autosar/secoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from cryptography.hazmat.primitives import cmac
1717
from cryptography.hazmat.primitives.ciphers import algorithms
1818
else:
19-
log_loading.info("Can't import python-cryptography v1.7+. "
19+
log_loading.info("Can't import python-cryptography v2.0+. "
2020
"Disabled SecOC calculate_cmac.")
2121

2222
from scapy.config import conf

scapy/contrib/macsec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
modes,
3434
)
3535
else:
36-
log_loading.info("Can't import python-cryptography v1.7+. "
36+
log_loading.info("Can't import python-cryptography v2.0+. "
3737
"Disabled MACsec encryption/authentication.")
3838

3939

scapy/contrib/psp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
aead,
6666
)
6767
else:
68-
log_loading.info("Can't import python-cryptography v1.7+. "
68+
log_loading.info("Can't import python-cryptography v2.0+. "
6969
"Disabled PSP encryption/authentication.")
7070

7171
###############################################################################

scapy/layers/dot11.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
decrepit_algorithms = algorithms
7474
else:
7575
default_backend = Ciphers = algorithms = decrepit_algorithms = None
76-
log_loading.info("Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)") # noqa: E501
76+
log_loading.info("Can't import python-cryptography v2.0+. Disabled WEP decryption/encryption. (Dot11)") # noqa: E501
7777

7878

7979
#########

scapy/layers/inet.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@
1919
linehexdump, strxor, whois, colgen
2020
from scapy.ansmachine import AnsweringMachine
2121
from scapy.base_classes import Gen, Net, _ScopedIP
22-
from scapy.data import ETH_P_IP, ETH_P_ALL, DLT_RAW, DLT_RAW_ALT, DLT_IPV4, \
23-
IP_PROTOS, TCP_SERVICES, UDP_SERVICES
22+
from scapy.consts import OPENBSD
23+
from scapy.data import (
24+
ETH_P_IP,
25+
ETH_P_ALL,
26+
DLT_RAW,
27+
DLT_RAW_ALT,
28+
DLT_IPV4,
29+
IP_PROTOS,
30+
TCP_SERVICES,
31+
UDP_SERVICES,
32+
)
2433
from scapy.layers.l2 import (
2534
CookedLinux,
2635
Dot3,
@@ -1358,6 +1367,8 @@ def mysummary(self):
13581367
conf.l2types.register(DLT_RAW, IP)
13591368
conf.l2types.register_num2layer(DLT_RAW_ALT, IP)
13601369
conf.l2types.register(DLT_IPV4, IP)
1370+
if OPENBSD:
1371+
conf.l2types.register_num2layer(228, IP)
13611372

13621373
conf.l3types.register(ETH_P_IP, IP)
13631374
conf.l3types.register_num2layer(ETH_P_ALL, IP)

scapy/layers/inet6.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from scapy.as_resolvers import AS_resolver_riswhois
2323
from scapy.base_classes import Gen, _ScopedIP
2424
from scapy.compat import chb, orb, raw, plain_str, bytes_encode
25-
from scapy.consts import WINDOWS
25+
from scapy.consts import WINDOWS, OPENBSD
2626
from scapy.config import conf
2727
from scapy.data import (
2828
DLT_IPV6,
@@ -4213,6 +4213,8 @@ def _load_dict(d):
42134213
conf.l2types.register(DLT_IPV6, IPv6)
42144214
conf.l2types.register(DLT_RAW, IPv46)
42154215
conf.l2types.register_num2layer(DLT_RAW_ALT, IPv46)
4216+
if OPENBSD:
4217+
conf.l2types.register_num2layer(229, IPv6)
42164218

42174219
bind_layers(Ether, IPv6, type=0x86dd)
42184220
bind_layers(CookedLinux, IPv6, proto=0x86dd)

scapy/layers/ipsec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def data_for_encryption(self):
221221
DES.key_sizes = decrepit_algorithms.TripleDES.key_sizes
222222
DES.block_size = decrepit_algorithms.TripleDES.block_size
223223
else:
224-
log_loading.info("Can't import python-cryptography v1.7+. "
224+
log_loading.info("Can't import python-cryptography v2.0+. "
225225
"Disabled IPsec encryption/authentication.")
226226
default_backend = None
227227
InvalidTag = Exception

scapy/layers/tls/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@
9191
if not conf.crypto_valid:
9292
import logging
9393
log_loading = logging.getLogger("scapy.loading")
94-
log_loading.info("Can't import python-cryptography v1.7+. "
94+
log_loading.info("Can't import python-cryptography v2.0+. "
9595
"Disabled PKI & TLS crypto-related features.")

test/regression.uts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ if len(routes6) > 2 and not WINDOWS:
533533
# Identify routes to fe80::/64
534534
assert sum(1 for r in routes6 if r[0] == "::1" and r[4] == ["::1"]) >= 1
535535
if len(iflist) >= 2:
536-
assert sum(1 for r in routes6 if ll_route.match(r[0]) and r[1] == 64) >= 1
536+
assert sum(1 for r in routes6 if ll_route.match(r[0])) >= 1
537537
try:
538538
# Identify a route to a node IPv6 link-local address
539539
assert sum(1 for r in routes6 if in6_islladdr(r[0]) and r[1] == 128) >= 1
@@ -2941,11 +2941,12 @@ class BSDLoader:
29412941
for p in self.patches:
29422942
p.start()
29432943
return pfroute
2944-
def __exit__(self, *args, **kwargs):
2944+
def __exit__(self, type, value, traceback):
29452945
for p in self.loadpatches:
29462946
p.stop()
29472947
for p in self.patches:
29482948
p.stop()
2949+
importlib.reload(scapy.arch.bpf.pfroute)
29492950

29502951

29512952
= OpenBSD 7.5 amd64 - read_routes()

0 commit comments

Comments
 (0)