Skip to content

Commit 8f64de2

Browse files
m
1 parent f3fa225 commit 8f64de2

File tree

2 files changed

+42
-8
lines changed
  • src/aws_encryption_sdk/key_providers
  • test_vector_handlers/src/awses_test_vectors/manifests

2 files changed

+42
-8
lines changed

src/aws_encryption_sdk/key_providers/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ConfigMismatchError,
1313
DecryptKeyError,
1414
IncorrectMasterKeyError,
15+
InvalidDataKeyError,
1516
InvalidKeyIdError,
1617
MasterKeyProviderError,
1718
)
@@ -256,7 +257,7 @@ def decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context):
256257
# //# input encryption context.
257258

258259
data_key = master_key.decrypt_data_key(encrypted_data_key, algorithm, encryption_context)
259-
except (IncorrectMasterKeyError, DecryptKeyError) as error:
260+
except (IncorrectMasterKeyError, DecryptKeyError, InvalidDataKeyError) as error:
260261
_LOGGER.debug(
261262
"%s raised when attempting to decrypt data key with master key %s",
262263
repr(error),
@@ -304,8 +305,8 @@ def decrypt_data_key_from_list(self, encrypted_data_keys, algorithm, encryption_
304305
try:
305306
data_key = self.decrypt_data_key(encrypted_data_key, algorithm, encryption_context)
306307
# MasterKeyProvider.decrypt_data_key throws DecryptKeyError
307-
# but MasterKey.decrypt_data_key throws IncorrectMasterKeyError
308-
except (DecryptKeyError, IncorrectMasterKeyError):
308+
# but MasterKey.decrypt_data_key throws IncorrectMasterKeyError and InvalidDataKeyError
309+
except (DecryptKeyError, IncorrectMasterKeyError, InvalidDataKeyError):
309310
continue
310311
else:
311312
break

test_vector_handlers/src/awses_test_vectors/manifests/master_key.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,40 @@ def scenario_spec(self):
290290
return spec
291291

292292

293+
class TestVectorsMultiMasterKeyProvider(MasterKeyProvider):
294+
"""
295+
Provider for other MasterKeyProviders.
296+
Acts as a "multi" MasterKeyProvider for use in test vectors.
297+
298+
There is some disagreement between the spec
299+
and how Python ESDK implements MasterKey;
300+
this class fills that gap.
301+
302+
In the ESDK-Python, MasterKey extends MasterKeyProvider;
303+
i.e. MasterKey "is a" MasterKeyProvider; isinstance(some_master_key, MasterKeyProvider) == True.
304+
305+
However, MasterKey overrides MasterKeyProvider's `decrypt_data_key` method.
306+
From AWS ESDK specification:
307+
"A master key MUST supply itself and MUST NOT supply any other master keys."
308+
https://github.com/awslabs/aws-encryption-sdk-specification/blob/master/framework/master-key-interface.md#get-master-key
309+
310+
This suggests that this "is a" relationship is not entirely true.
311+
312+
master_key_provider_from_master_key_specs uses this class to provide all loaded MasterKeyProviders (or MasterKeys)
313+
from an interface that supports supplying other master keys.
314+
"""
315+
316+
_config_class = MasterKeyProviderConfig
317+
provider_id = "aws-test-vectors-multi-master-key-provider"
318+
319+
def add_key(self, key_provider):
320+
self._members.append(key_provider)
321+
322+
def _new_master_key(self, key_id):
323+
# This MKP does not have a key associated with it.
324+
raise InvalidKeyIdError()
325+
326+
293327
def master_key_provider_from_master_key_specs(keys, master_key_specs):
294328
# type: (KeysManifest, Iterable[MasterKeySpec]) -> MasterKeyProvider
295329
"""Build and combine all master key providers identified by the provided specs and
@@ -302,8 +336,7 @@ def master_key_provider_from_master_key_specs(keys, master_key_specs):
302336
:rtype: MasterKeyProvider
303337
"""
304338
master_keys = [spec.master_key(keys) for spec in master_key_specs]
305-
primary = master_keys[0]
306-
others = master_keys[1:]
307-
for master_key in others:
308-
primary.add_master_key_provider(master_key)
309-
return primary
339+
mkp = TestVectorsMultiMasterKeyProvider()
340+
for master_key in master_keys:
341+
mkp.add_key(master_key)
342+
return mkp

0 commit comments

Comments
 (0)