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] 41daf2d86d
This commit is contained in:
Takashi Kajinami 2024-03-28 18:10:07 +09:00 committed by arp102
parent cae5747a19
commit 4d3b5a52ae
2 changed files with 17 additions and 9 deletions

View File

@ -584,13 +584,17 @@ class CryptographyEngine(api.CryptographicEngine):
"encryption.".format(padding_method) "encryption.".format(padding_method)
) )
backend = default_backend()
try: try:
public_key = backend.load_der_public_key(encryption_key) public_key = serialization.load_der_public_key(
encryption_key,
backend=default_backend()
)
except Exception: except Exception:
try: try:
public_key = backend.load_pem_public_key(encryption_key) public_key = serialization.load_pem_public_key(
encryption_key,
backend=default_backend()
)
except Exception: except Exception:
raise exceptions.CryptographicFailure( raise exceptions.CryptographicFailure(
"The public key bytes could not be loaded." "The public key bytes could not be loaded."
@ -1433,8 +1437,6 @@ class CryptographyEngine(api.CryptographicEngine):
loaded, or when the signature verification process fails loaded, or when the signature verification process fails
unexpectedly. unexpectedly.
""" """
backend = default_backend()
hash_algorithm = None hash_algorithm = None
dsa_hash_algorithm = None dsa_hash_algorithm = None
dsa_signing_algorithm = None dsa_signing_algorithm = None
@ -1488,10 +1490,16 @@ class CryptographyEngine(api.CryptographicEngine):
) )
try: try:
public_key = backend.load_der_public_key(signing_key) public_key = serialization.load_der_public_key(
signing_key,
backend=default_backend()
)
except Exception: except Exception:
try: try:
public_key = backend.load_pem_public_key(signing_key) public_key = serialization.load_pem_public_key(
signing_key,
backend=default_backend()
)
except Exception: except Exception:
raise exceptions.CryptographicFailure( raise exceptions.CryptographicFailure(
"The signing key bytes could not be loaded." "The signing key bytes could not be loaded."

View File

@ -1,4 +1,4 @@
cryptography>=1.4 cryptography>=2.5
enum-compat enum-compat
requests requests
six>=1.11.0 six>=1.11.0