Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor(pyavd): Suppress warnings for cryptography >=43.0.0 #4235

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions python-avd/pyavd/_utils/password_utils/password_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
import base64

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.ciphers import Cipher, modes

# Starting cyryptography 43.0.0, TripleDES cipher has been moved to cryptography.hazmat.decrepit module
try:
from cryptography.hazmat.decrepit.ciphers.algorithms import TripleDES
except ImportError:
from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES

SEED = b"\xd5\xa8\xc9\x1e\xf5\xd5\x8a\x23"

Expand Down Expand Up @@ -186,7 +192,7 @@ def cbc_encrypt(key: bytes, data: bytes) -> bytes:
ciphertext = ENC_SIG + bytes([padding * 16 + 0xE]) + data + bytes(padding)

# Accepting SonarLint issue: The insecure algorithm is ok since this simply matches the algorithm of EOS.
cipher = Cipher(algorithms.TripleDES(hashed_key), modes.CBC(bytes(8)), default_backend()) # NOSONAR
cipher = Cipher(TripleDES(hashed_key), modes.CBC(bytes(8)), default_backend()) # NOSONAR
encryptor = cipher.encryptor()
result = encryptor.update(ciphertext)
encryptor.finalize()
Expand All @@ -213,7 +219,7 @@ def cbc_decrypt(key: bytes, data: bytes) -> bytes:
hashed_key = hashkey(key)

# Accepting SonarLint issue: Insecure algorithm is ok since this is simply matching the algorithm of EOS.
cipher = Cipher(algorithms.TripleDES(hashed_key), modes.CBC(bytes(8)), default_backend()) # NOSONAR
cipher = Cipher(TripleDES(hashed_key), modes.CBC(bytes(8)), default_backend()) # NOSONAR
decryptor = cipher.decryptor()
result = decryptor.update(data)
decryptor.finalize()
Expand Down
Loading