Skip to content

Commit 6e958bd

Browse files
authored
fix(crypto): Replace isinstance metaclass check with issubclass in generate_ecc_signing_key (#802)
The isinstance check against type(ec.EllipticCurve) (ABCMeta) fails with newer versions of cryptography where EC curve classes are backed by Rust internals and have 'type' as their metaclass instead of ABCMeta. This causes NotSupportedError when using ECDSA signing algorithms like AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384. Replace with issubclass which correctly handles both pure Python ABCs and Rust-backed types, matching the fix already applied to authentication.py _set_signature_type. Fixes #793
1 parent c00a58c commit 6e958bd

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/aws_encryption_sdk/internal/crypto/elliptic_curve.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ def generate_ecc_signing_key(algorithm):
171171
:returns: Generated signing key
172172
:raises NotSupportedError: if signing algorithm is not supported on this platform
173173
"""
174-
if not isinstance(algorithm.signing_algorithm_info, type(ec.EllipticCurve)):
174+
try:
175+
if not issubclass(algorithm.signing_algorithm_info, ec.EllipticCurve):
176+
raise NotSupportedError("Unsupported signing algorithm info")
177+
except TypeError:
175178
raise NotSupportedError("Unsupported signing algorithm info")
176179
return ec.generate_private_key(curve=algorithm.signing_algorithm_info(), backend=default_backend())

test/unit/test_crypto_elliptic_curve.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,22 +349,17 @@ def test_ecc_public_numbers_from_compressed_point(patch_ec, patch_ecc_decode_com
349349
assert test == sentinel.public_numbers_instance
350350

351351

352-
def test_generate_ecc_signing_key_supported(patch_default_backend, patch_ec):
353-
patch_ec.generate_private_key.return_value = sentinel.raw_signing_key
354-
mock_algorithm_info = MagicMock(return_value=sentinel.algorithm_info, spec=patch_ec.EllipticCurve)
355-
mock_algorithm = MagicMock(signing_algorithm_info=mock_algorithm_info)
352+
def test_generate_ecc_signing_key_supported(patch_default_backend):
353+
patch_default_backend.return_value = sentinel.backend
354+
mock_algorithm = MagicMock(signing_algorithm_info=ec.SECP384R1)
356355

357356
test_signing_key = generate_ecc_signing_key(algorithm=mock_algorithm)
358357

359-
patch_ec.generate_private_key.assert_called_once_with(
360-
curve=sentinel.algorithm_info, backend=patch_default_backend.return_value
361-
)
362-
assert test_signing_key is sentinel.raw_signing_key
358+
assert test_signing_key is not None
363359

364360

365361
def test_generate_ecc_signing_key_unsupported(patch_default_backend, patch_ec):
366-
mock_algorithm_info = MagicMock(return_value=sentinel.algorithm_info)
367-
mock_algorithm = MagicMock(signing_algorithm_info=mock_algorithm_info)
362+
mock_algorithm = MagicMock(signing_algorithm_info="not_a_class")
368363

369364
with pytest.raises(NotSupportedError) as excinfo:
370365
generate_ecc_signing_key(algorithm=mock_algorithm)

0 commit comments

Comments
 (0)