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

Fix compatibility with cryptography >= 42.0.0 #714

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 16 additions & 8 deletions kmip/services/server/crypto/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,17 @@ def _encrypt_asymmetric(self,
"encryption.".format(padding_method)
)

backend = default_backend()

try:
public_key = backend.load_der_public_key(encryption_key)
public_key = serialization.load_der_public_key(
encryption_key,
backend=default_backend()
)
except Exception:
try:
public_key = backend.load_pem_public_key(encryption_key)
public_key = serialization.load_pem_public_key(
encryption_key,
backend=default_backend()
)
except Exception:
raise exceptions.CryptographicFailure(
"The public key bytes could not be loaded."
Expand Down Expand Up @@ -1433,8 +1437,6 @@ def verify_signature(self,
loaded, or when the signature verification process fails
unexpectedly.
"""
backend = default_backend()

hash_algorithm = None
dsa_hash_algorithm = None
dsa_signing_algorithm = None
Expand Down Expand Up @@ -1488,10 +1490,16 @@ def verify_signature(self,
)

try:
public_key = backend.load_der_public_key(signing_key)
public_key = serialization.load_der_public_key(
signing_key,
backend=default_backend()
)
except Exception:
try:
public_key = backend.load_pem_public_key(signing_key)
public_key = serialization.load_pem_public_key(
signing_key,
backend=default_backend()
)
except Exception:
raise exceptions.CryptographicFailure(
"The signing key bytes could not be loaded."
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cryptography>=1.4
cryptography>=2.5
enum-compat
requests
six>=1.11.0
Expand Down
Loading