# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of # the License is located at # # http://aws.amazon.com/apache2.0/ # # or in the "license" file accompanying this file. This file is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """Unit tests for ``dynamodb_encryption_sdk.material_providers.aws_kms``.""" import base64 import boto3 import botocore import pytest from mock import MagicMock, sentinel from moto import mock_kms from pytest_mock import mocker # noqa pylint: disable=unused-import import dynamodb_encryption_sdk.material_providers.aws_kms from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey from dynamodb_encryption_sdk.exceptions import UnknownRegionError, UnwrappingError, WrappingError from dynamodb_encryption_sdk.identifiers import EncryptionKeyType, KeyEncodingType from dynamodb_encryption_sdk.material_providers.aws_kms import ( _DEFAULT_CONTENT_ENCRYPTION_ALGORITHM, _DEFAULT_SIGNING_ALGORITHM, AwsKmsCryptographicMaterialsProvider, KeyInfo, ) from dynamodb_encryption_sdk.structures import EncryptionContext from ..unit_test_utils import all_possible_combinations_kwargs pytestmark = [pytest.mark.unit, pytest.mark.local] _VALID_KEY_INFO_KWARGS = dict(description="some string", algorithm="algorithm name", length=1234) _REGION = "fake-region" _KEY_ID = "arn:aws:kms:{}:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab".format(_REGION) _DERIVED_KEYS = { "initial_material": b'\xafx2"\xb5\xd5`\xc6\x8d\xaa\xfe\xc10E3x?D\x18\x93$<\x161\xcb\x99\xef\xc0Z\x1a\x1b]', "encrypted_initial_material": ( b"\x01\x01\x02\x00x@\xf3\x8c'^1\tt\x16\xc1\x07)QPW\x19d\xad\xa3\xef\x1c!\xe9L\x8b\xa0\xbd\xbc\x9d\x0f\xb4\x14" b"\x00\x00\x00~0|\x06\t*\x86H\x86\xf7\r\x01\x07\x06\xa0o0m\x02\x01\x000h\x06\t*\x86H\x86\xf7\r\x01\x07\x010" b"\x1e\x06\t`\x86H\x01e\x03\x04\x01.0\x11\x04\x0c-\xc0&\x1f\xeb_\xdek\xca/$y\x02\x01\x10\x80;!\x99z\xbek3|\x8b" b"\x98\x1b\xba\x91H<\xb1X\x8c\xc7vGv\x84*\xe1\xf1B\xd4\xe5&\xa2\xa3)\x04\x1f\xad\t\x07\x90\x14\xbeQo\xa0\xff" b"\x1a\xc2\xa5(i\x0c4\x10\xe8\xe2\xf3\x17}\t\xd6" ), # encrypted using our public-test CMK in us-west-2 "encryption_key": b"\xb3~{,Z\x80\x7f\x82I\xe5