Skip to content

Commit 819eb68

Browse files
merge from fix-test-vectors
2 parents 00013d2 + c7e254a commit 819eb68

File tree

1 file changed

+39
-1
lines changed
  • test_vector_handlers/src/awses_test_vectors/manifests

1 file changed

+39
-1
lines changed

test_vector_handlers/src/awses_test_vectors/manifests/master_key.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import six
1010
from aws_encryption_sdk.exceptions import IncorrectMasterKeyError, InvalidKeyIdError
1111
from aws_encryption_sdk.identifiers import EncryptionKeyType, WrappingAlgorithm
12-
from aws_encryption_sdk.key_providers.base import MasterKeyProvider, MasterKeyProviderConfig # noqa pylint: disable=unused-import
12+
from aws_encryption_sdk.key_providers.base import MasterKeyProvider, MasterKeyProviderConfig
1313
from aws_encryption_sdk.key_providers.kms import ( # noqa pylint: disable=unused-import
1414
DiscoveryFilter,
1515
KMSMasterKey,
@@ -316,6 +316,44 @@ def scenario_spec(self):
316316
return spec
317317

318318

319+
class TestVectorsMultiMasterKeyProvider(MasterKeyProvider):
320+
"""
321+
Provider for other MasterKeyProviders.
322+
Acts as a "multi" MasterKeyProvider for use in test vectors.
323+
324+
There is some disagreement between the spec
325+
and how Python ESDK implements MasterKey;
326+
this class fills that gap.
327+
328+
In the ESDK-Python, MasterKey extends MasterKeyProvider;
329+
i.e. MasterKey "is a" MasterKeyProvider; isinstance(some_master_key, MasterKeyProvider) == True.
330+
331+
From AWS ESDK specification:
332+
"A master key MUST supply itself and MUST NOT supply any other master keys."
333+
https://github.com/awslabs/aws-encryption-sdk-specification/blob/master/framework/master-key-interface.md#get-master-key
334+
335+
The MasterKey class overrides MasterKeyProvider's `decrypt_data_key` method to correct this gap.
336+
However, this modification suggests that this "is a" relationship is not entirely true.
337+
338+
master_key_provider_from_master_key_specs expects to return a MasterKeyProvider, not a MasterKey.
339+
master_key_provider_from_master_key_specs uses this class to always return a MasterKeyProvider
340+
that wraps any MasterKeyProvider or MasterKey loaded from a spec.
341+
"""
342+
343+
_config_class = MasterKeyProviderConfig
344+
provider_id = "aws-test-vectors-multi-master-key-provider"
345+
_members = []
346+
347+
def add_key(self, key_provider):
348+
"""Add a MKP to the list of configured MKPs."""
349+
self._members.append(key_provider)
350+
351+
def _new_master_key(self, key_id):
352+
# This MKP does not have a key associated with it.
353+
# ESDK-Python will find keys in _members.
354+
raise InvalidKeyIdError()
355+
356+
319357
def master_key_provider_from_master_key_specs(keys, master_key_specs):
320358
# type: (KeysManifest, Iterable[MasterKeySpec]) -> MasterKeyProvider
321359
"""Build and combine all master key providers identified by the provided specs and

0 commit comments

Comments
 (0)