-
Notifications
You must be signed in to change notification settings - Fork 20
feat(dafny): support decrypt/encrypt strategy for mutation to hv2 #1466
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
feat(dafny): support decrypt/encrypt strategy for mutation to hv2 #1466
Conversation
…thub.com/aws/aws-cryptographic-material-providers-library into rishav/hv-2/M2/refactorForDecryptEncrypt
| requires mutationToApply.Terminal.hierarchyVersion.v2? | ||
| modifies keyManagerStrategy.Modifies | ||
| ensures keyManagerStrategy.ValidState() | ||
| { |
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.
We don't need :- Need(keyManagerStrategy.kmsSimple?, Types.UnsupportedFeatureException(message:=KeyStoreAdminErrorMessages.UNSUPPORTED_KEY_MANAGEMENT_STRATEGY_HV_2)); because its already done by upstream method.
Post Pre condition requires KmsUtils.IsSupportedKeyManagerStrategy(mutationToApply.Terminal.hierarchyVersion, keyManagerStrategy) requires it to be done
AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStoreAdmin/src/Mutations.dfy
Show resolved
Hide resolved
texastony
left a comment
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.
99%.
I am a bad engineer and started this "string" for control trend.
But we can use formal verification to bound the possible values for the string,
which makes it marginally better.
So, let's do that.
AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStoreAdmin/src/KmsUtils.dfy
Show resolved
Hide resolved
AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStoreAdmin/src/Mutations.dfy
Show resolved
Hide resolved
| if localOperation == "ApplyMutation" { | ||
| KMSTuple := KmsUtils.getEncryptKMSTuple(keyManagerStrategy); | ||
| } else { | ||
| KMSTuple := KmsUtils.getDecryptKMSTuple(keyManagerStrategy); | ||
| } |
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.
Using a string for control is a little fragile... I know I started this trend, but it would be better to create a type.
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.
Added if..else-if..else with else having failing case.
|
|
||
| requires item.KmsArn == mutationToApply.Original.kmsArn | ||
| requires Structure.EncryptedHierarchicalKeyFromStorage?(item) | ||
| requires localOperation == "ApplyMutation" || localOperation == "InitializeMutation" |
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 what I am saying for above, or we could replace all of these with a type.
texastony
left a comment
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.
LGTM
| const INVALID_COMMITMENT_UTF8 := "Mutation Commitment read from storage contains invalid UTF-8." | ||
| const INVALID_INDEX_UTF8 := "Mutation Index read from storage contains invalid UTF-8." | ||
| const INVALID_COMMITMENT_UUID := "Mutation Commitment read from storage has an invalid UUID." | ||
| function UnsupportedLocalOperation ( |
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.
Praise:
- I like how you moved the constants up
- I like this function
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.