|
9 | 9 | import six |
10 | 10 | from aws_encryption_sdk.exceptions import IncorrectMasterKeyError, InvalidKeyIdError |
11 | 11 | 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 |
13 | 13 | from aws_encryption_sdk.key_providers.kms import ( # noqa pylint: disable=unused-import |
14 | 14 | DiscoveryFilter, |
15 | 15 | KMSMasterKey, |
@@ -316,6 +316,44 @@ def scenario_spec(self): |
316 | 316 | return spec |
317 | 317 |
|
318 | 318 |
|
| 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 | + |
319 | 357 | def master_key_provider_from_master_key_specs(keys, master_key_specs): |
320 | 358 | # type: (KeysManifest, Iterable[MasterKeySpec]) -> MasterKeyProvider |
321 | 359 | """Build and combine all master key providers identified by the provided specs and |
|
0 commit comments