in src/aws_encryption_sdk/key_providers/kms.py [0:0]
def _new_master_key_impl(self, key_id):
"""Creation of new master keys. Compared to the base class, this class has smarts to use either the configured
discovery region or, if not present, the default SDK region, to create new keys.
"""
# //= compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.7
# //# In discovery mode, the requested
# //# AWS KMS key identifier MUST be a well formed AWS KMS ARN.
_key_id = to_str(key_id)
arn = arn_from_str(_key_id)
# //= compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.7
# //# In discovery mode a AWS KMS MRK Aware Master Key (aws-kms-mrk-aware-
# //# master-key.md) MUST be returned configured with
# Note that in the MRK case we ensure the key ID passed along has the discovery region,
# and in both cases _client(...) will ensure that a client is created that matches the key's region.
if not arn.resource_id.startswith("mrk"):
# //= compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.7
# //# Otherwise if the requested AWS KMS key
# //# identifier is identified as a multi-Region key (aws-kms-key-
# //# arn.md#identifying-an-aws-kms-multi-region-key), then AWS Region MUST
# //# be the region from the AWS KMS key ARN stored in the provider info
# //# from the encrypted data key.
# Note that this could return a normal KMSMasterKey and retain the same behavior,
# however we opt to follow the spec here in order to bias towards consistency between
# implementations.
return MRKAwareKMSMasterKey(
config=MRKAwareKMSMasterKeyConfig(
key_id=_key_id, client=self._client(_key_id), grant_tokens=self.config.grant_tokens
)
)
else:
# //= compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.7
# //# Otherwise if the mode is discovery then
# //# the AWS Region MUST be the discovery MRK region.
arn.region = self.config.discovery_region
new_key_id = arn.to_string()
return MRKAwareKMSMasterKey(
config=MRKAwareKMSMasterKeyConfig(
key_id=new_key_id, client=self._client(new_key_id), grant_tokens=self.config.grant_tokens
)
)