Skip to content

master key provider keyring #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

master key provider keyring #209

wants to merge 6 commits into from

Conversation

mattsb42-aws
Copy link
Member

Issue #, if available: #146

Description of changes:

This adds MasterKeyProviderKeyring as an abstraction layer on top of master key providers (MKPs). This allows us to isolate MKP logic within this specific keyring so that everything upstream only ever needs to deal in keyrings and the keyring interface.

This gives us two benefits over leaving this logic in the default CMM:

  1. It isolates MKP-specific logic. This makes the default CMM simpler and whenever we eventually remove MKPs, it will reduce the impact of that code change.
  2. It lets us inject keyring trace entries for known MKPs.

DefaultCryptoMaterialsManager and CachingCryptoMaterialsManager also now accept a keyring in addition to a MKP (and a CMM in the case of the caching CMM).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

@mattsb42-aws mattsb42-aws mentioned this pull request Feb 14, 2020
10 tasks
@mattsb42-aws mattsb42-aws requested a review from a team February 14, 2020 23:44
Copy link
Contributor

@WesleyRosenblum WesleyRosenblum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the logic, not the syntax

@@ -0,0 +1,222 @@
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This date is wrong, but according to yesterday's communication we can remove the date anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I think what I'll do here is update the date here, then in a separate PR update all the copyright notices per aws/crypto-tools#15

:raises NotImplementedError: if method is not implemented
"""
primary_master_key, master_keys = self._master_key_provider.master_keys_for_encryption(
encryption_context=encryption_materials.encryption_context, plaintext_rostream=None, plaintext_length=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same issue that prevented the Java ESDK from using a MasterKeyProviderKeyring? You aren't providing the plaintext_rostream or plaintext_length to the MKP, but the Default CMM used to. I think we may have discussed this, but why isn't that a potential breaking change for customers who have written custom MKPs and used the plaintext_rostream or plaintext_length inputs?

Comment on lines +124 to +126
"Unable to use master keys with encryption materials that already contain a data key."
" You are probably trying to mix master key providers and keyrings."
" If you want to do that, the master key provider MUST be the generator."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the multi keyring validate that the children keyrings are not MKP keyrings upon creation? This behavior is different than all the other keyrings, so it might be confusing

# not the provider info, which is what is in the returned data key.
try:
decrypting_master_key = list(self._master_key_provider.master_keys_for_data_key(decrypted_data_key))[0]
except IndexError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would cause this to happen, a buggy MKP?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, yes.

Comment on lines -78 to -80
encryption_context=encryption_context,
plaintext_rostream=request.plaintext_rostream,
plaintext_length=request.plaintext_length,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on master_key.py, its ok for plaintext_rostream and plaintext_length to not be passed to master_keys_for_encryption()?

@mattsb42-aws
Copy link
Member Author

I've been thinking about this and discussing the problem offline with @WesleyRosenblum. I think that the best answer we can get here is the same as we arrived at for Java; the master key provider and keyring APIs are just too different, in too many subtle ways, for this sort of abstraction layer to work without breaking people. :(

I'm going to close this and change tack to instead have the default CMM directly handle both keyrings and MKPs.

@mattsb42-aws mattsb42-aws deleted the mkp-keyring branch March 9, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants