-
Notifications
You must be signed in to change notification settings - Fork 16
chore(java): demo hv-2 does not send prefixed EC in examples #1529
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
base: hv-2/hv-2
Are you sure you want to change the base?
Conversation
...ples/java/src/main/java/software/amazon/cryptography/example/hierarchy/CreateKeyExample.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really good, but let's simplify the CreateKey example and retain this integ test, by moving the integ test to the test directory.
// HV2 sends the encryption context without any transformation. | ||
// We have a kms key `Fixtures.KMS_KEY_FOR_HV2_ONLY`, that requires EC to be exactly {"Robbie": "Is a Dog."} in its key policy. | ||
// For demostration, we will create a key with a different EC then the one that is expected and see it fail. | ||
final Map<String, String> encryptionContextFailingCase = | ||
Collections.singletonMap("I", "am not a Dog."); | ||
boolean exceptionThrown = false; | ||
try { | ||
_admin | ||
.CreateKey( | ||
CreateKeyInput | ||
.builder() | ||
// This is the KMS ARN that will be used to protect the Branch Key. | ||
// It is a required argument. | ||
.KmsArn(KmsSymmetricKeyArn.builder().KmsKeyArn(kmsKeyArn).build()) | ||
// If you need to specify the Identifier for a Branch Key, you may. | ||
// This is an optional argument. | ||
.Identifier(branchKeyId) | ||
// If a branch key Identifier is provided, | ||
// custom encryption context MUST be provided as well. | ||
.EncryptionContext(encryptionContextFailingCase) | ||
// The Branch Key Store Admin can create HV-1 or HV-2 Branch Keys | ||
.HierarchyVersion(_hierarchyVersion) | ||
// But the Strategy MUST support the Hierarchy Version | ||
.Strategy(strategy) | ||
.build() | ||
) | ||
.Identifier(); | ||
} catch (KmsException e) { | ||
exceptionThrown = true; | ||
} | ||
assert exceptionThrown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking: Just move all of this to a Test.
Do not keep it in line with the examples, that confuses customers, and complicates this CreateKey
method that we use through out the Example Testing.
Issue #, if available:
Description of changes:
Squash/merge commit message, if applicable:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.