Skip to content

Commit

Permalink
Fix cryptography > 43.0 deprecation warning in TLS (#4383)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed May 12, 2024
1 parent ecfeb14 commit f17e8da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
25 changes: 18 additions & 7 deletions scapy/layers/tls/crypto/cipher_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@
from cryptography.utils import (
CryptographyDeprecationWarning,
)
from cryptography.hazmat.primitives.ciphers import (Cipher, algorithms, modes, # noqa: E501
BlockCipherAlgorithm,
CipherAlgorithm)
from cryptography.hazmat.primitives.ciphers import (
BlockCipherAlgorithm,
Cipher,
CipherAlgorithm,
algorithms,
modes,
)
from cryptography.hazmat.backends.openssl.backend import backend
try:
# cryptography > 43.0
from cryptography.hazmat.decrepit.ciphers import (
algorithms as decrepit_algorithms,
)
except ImportError:
decrepit_algorithms = algorithms


_tls_block_cipher_algs = {}
Expand Down Expand Up @@ -133,7 +144,7 @@ class Cipher_CAMELLIA_256_CBC(Cipher_CAMELLIA_128_CBC):

if conf.crypto_valid:
class Cipher_DES_CBC(_BlockCipher):
pc_cls = algorithms.TripleDES
pc_cls = decrepit_algorithms.TripleDES
pc_cls_mode = modes.CBC
block_size = 8
key_len = 8
Expand All @@ -151,7 +162,7 @@ class Cipher_DES40_CBC(Cipher_DES_CBC):
key_len = 5

class Cipher_3DES_EDE_CBC(_BlockCipher):
pc_cls = algorithms.TripleDES
pc_cls = decrepit_algorithms.TripleDES
pc_cls_mode = modes.CBC
block_size = 8
key_len = 24
Expand All @@ -165,13 +176,13 @@ class Cipher_3DES_EDE_CBC(_BlockCipher):
category=CryptographyDeprecationWarning)

class Cipher_IDEA_CBC(_BlockCipher):
pc_cls = algorithms.IDEA
pc_cls = decrepit_algorithms.IDEA
pc_cls_mode = modes.CBC
block_size = 8
key_len = 16

class Cipher_SEED_CBC(_BlockCipher):
pc_cls = algorithms.SEED
pc_cls = decrepit_algorithms.SEED
pc_cls_mode = modes.CBC
block_size = 16
key_len = 16
Expand Down
9 changes: 8 additions & 1 deletion scapy/layers/tls/crypto/cipher_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
if conf.crypto_valid:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms
from cryptography.hazmat.backends import default_backend
try:
# cryptography > 43.0
from cryptography.hazmat.decrepit.ciphers import (
algorithms as decrepit_algorithms,
)
except ImportError:
decrepit_algorithms = algorithms


_tls_stream_cipher_algs = {}
Expand Down Expand Up @@ -103,7 +110,7 @@ def snapshot(self):

if conf.crypto_valid:
class Cipher_RC4_128(_StreamCipher):
pc_cls = algorithms.ARC4
pc_cls = decrepit_algorithms.ARC4
key_len = 16

class Cipher_RC4_40(Cipher_RC4_128):
Expand Down

0 comments on commit f17e8da

Please sign in to comment.