From a1563bd452acbae1697741a848c0c9b032f1770f Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Sun, 10 Dec 2017 23:45:39 -0800 Subject: [PATCH] adding handling code in MrcryptLegacyCompatibilityCryptoMaterialsManager to work properly until https://github.com/awslabs/aws-encryption-sdk-python/issues/21 is resolved --- mrcrypt/materials_manager.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mrcrypt/materials_manager.py b/mrcrypt/materials_manager.py index 44aa478..344c4d2 100644 --- a/mrcrypt/materials_manager.py +++ b/mrcrypt/materials_manager.py @@ -6,8 +6,9 @@ files created with legacy mrcrypt formatting. """ import base64 +import logging -from aws_encryption_sdk.exceptions import NotSupportedError +from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError from aws_encryption_sdk.internal.defaults import ENCODED_SIGNER_KEY from aws_encryption_sdk.materials_managers import DecryptionMaterials from aws_encryption_sdk.materials_managers.default import DefaultCryptoMaterialsManager @@ -15,6 +16,8 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicNumbers +_LOGGER = logging.getLogger('mrcrypt') + class MrcryptLegacyCompatibilityCryptoMaterialsManager(DefaultCryptoMaterialsManager): """Cryptographic materials manager that provides decrypt compatibility with the @@ -59,9 +62,15 @@ def decrypt_materials(self, request): """ try: return super(MrcryptLegacyCompatibilityCryptoMaterialsManager, self).decrypt_materials(request) - except NotSupportedError as error: - if error.args[0] != 'Uncompressed points are not supported': - raise + except (AWSEncryptionSDKClientError, KeyError) as error: + _LOGGER.debug( + 'Encountered error decrypting materials with DefaultCryptoMaterialsManager.' + ' Attempting to decrypt using uncompressed elliptic curve point.' + ) + # Once this issue is addressed, KeyError should be removed and the below check and raise uncommented. + # https://github.com/awslabs/aws-encryption-sdk-python/issues/21 + # if error.args[0] != 'Uncompressed points are not supported': + # raise data_key = self.master_key_provider.decrypt_data_key_from_list( encrypted_data_keys=request.encrypted_data_keys,