Skip to content

Commit 4d3b5a5

Browse files
kajinamitarp102
authored andcommitted
Fix compatibility with cryptography >= 42.0.0
The load_der_public_key method and the load_pem_private_key method were removed from Backend class in cryptography 42.0.0[1]. Closes #713 [1] pyca/cryptography@41daf2d
1 parent cae5747 commit 4d3b5a5

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

kmip/services/server/crypto/engine.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,17 @@ def _encrypt_asymmetric(self,
584584
"encryption.".format(padding_method)
585585
)
586586

587-
backend = default_backend()
588-
589587
try:
590-
public_key = backend.load_der_public_key(encryption_key)
588+
public_key = serialization.load_der_public_key(
589+
encryption_key,
590+
backend=default_backend()
591+
)
591592
except Exception:
592593
try:
593-
public_key = backend.load_pem_public_key(encryption_key)
594+
public_key = serialization.load_pem_public_key(
595+
encryption_key,
596+
backend=default_backend()
597+
)
594598
except Exception:
595599
raise exceptions.CryptographicFailure(
596600
"The public key bytes could not be loaded."
@@ -1433,8 +1437,6 @@ def verify_signature(self,
14331437
loaded, or when the signature verification process fails
14341438
unexpectedly.
14351439
"""
1436-
backend = default_backend()
1437-
14381440
hash_algorithm = None
14391441
dsa_hash_algorithm = None
14401442
dsa_signing_algorithm = None
@@ -1488,10 +1490,16 @@ def verify_signature(self,
14881490
)
14891491

14901492
try:
1491-
public_key = backend.load_der_public_key(signing_key)
1493+
public_key = serialization.load_der_public_key(
1494+
signing_key,
1495+
backend=default_backend()
1496+
)
14921497
except Exception:
14931498
try:
1494-
public_key = backend.load_pem_public_key(signing_key)
1499+
public_key = serialization.load_pem_public_key(
1500+
signing_key,
1501+
backend=default_backend()
1502+
)
14951503
except Exception:
14961504
raise exceptions.CryptographicFailure(
14971505
"The signing key bytes could not be loaded."

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cryptography>=1.4
1+
cryptography>=2.5
22
enum-compat
33
requests
44
six>=1.11.0

0 commit comments

Comments
 (0)