-
Notifications
You must be signed in to change notification settings - Fork 16
feat(dafny): use kms:GenerateDataKey
for branch key creation and version hv-2
#1478
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
Merged
josecorella
merged 8 commits into
jocorell/hv-2-version-key
from
jocorell/move-over-to-gdk
Apr 28, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0087862
feat(dafny): use kms::GenerateDataKey for hv-2 branch key creation
josecorella 429b229
use ec to kms for generate data key
josecorella 25dcfd3
work
josecorella a1efe60
move version key to use generatedatakey
josecorella e9eace8
add proof todo
josecorella 751b9ad
Update AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStor…
josecorella 079180d
Apply suggestions from code review
josecorella 0ccebe4
format
josecorella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,73 @@ module {:options "/functionSyntax:4" } KMSKeystoreOperations { | |
case kmsMRKeyArn(arn) => arn | ||
} | ||
|
||
method GetPlaintextDataKeyViaGenerateDataKey( | ||
nameonly branchKeyContext: map<string, string>, | ||
nameonly kmsConfiguration: Types.KMSConfiguration, | ||
nameonly keyManagerAndStorage: KmsUtils.KeyManagerAndStorage | ||
) | ||
returns (output: Result<seq<uint8>, Types.Error>) | ||
requires | ||
// TODO-HV2-DecryptEncrypt support Decrypt/Encrypt | ||
&& keyManagerAndStorage.keyManagerStrat.kmsSimple? | ||
&& keyManagerAndStorage.ValidState() | ||
&& HasKeyId(kmsConfiguration) | ||
&& KmsArn.ValidKmsArn?(GetKeyId(kmsConfiguration)) | ||
modifies keyManagerAndStorage.Modifies | ||
ensures keyManagerAndStorage.ValidState() | ||
ensures output.Success? | ||
==> | ||
&& var kms := keyManagerAndStorage.keyManagerStrat.kmsSimple.kmsClient; | ||
&& |kms.History.GenerateDataKey| == |old(kms.History.GenerateDataKey)| + 1 | ||
&& old(kms.History.Encrypt) == kms.History.Encrypt | ||
&& var kmsGenerateDataKeyEvent := Seq.Last(kms.History.GenerateDataKey); | ||
&& var kmsKeyArn := GetKeyId(kmsConfiguration); | ||
&& KMS.GenerateDataKeyRequest( | ||
KeyId := kmsKeyArn, | ||
NumberOfBytes := Some(32), | ||
EncryptionContext := Some(branchKeyContext), | ||
GrantTokens := Some(keyManagerAndStorage.keyManagerStrat.kmsSimple.grantTokens) | ||
) == kmsGenerateDataKeyEvent.input | ||
&& kmsGenerateDataKeyEvent.output.Success? | ||
&& kmsGenerateDataKeyEvent.output.value.Plaintext.Some? | ||
&& |kmsGenerateDataKeyEvent.output.value.Plaintext.value| == 32 | ||
&& kmsGenerateDataKeyEvent.output.value.KeyId.Some? | ||
&& kmsGenerateDataKeyEvent.output.value.KeyId.value == kmsKeyArn | ||
&& kmsGenerateDataKeyEvent.output.value.Plaintext.value == output.value | ||
{ | ||
var kmsKeyArn := GetKeyId(kmsConfiguration); | ||
var generateDataKeyInput := KMS.GenerateDataKeyRequest( | ||
KeyId := kmsKeyArn, | ||
NumberOfBytes := Some(32), | ||
EncryptionContext := Some(branchKeyContext), | ||
GrantTokens := Some(keyManagerAndStorage.keyManagerStrat.kmsSimple.grantTokens) | ||
); | ||
|
||
var generateDataKeyResponse? := keyManagerAndStorage.keyManagerStrat.kmsSimple.kmsClient.GenerateDataKey( | ||
generateDataKeyInput | ||
); | ||
|
||
var generateDataKeyResponse :- generateDataKeyResponse? | ||
.MapFailure(e => Types.ComAmazonawsKms(ComAmazonawsKms := e)); | ||
|
||
:- Need( | ||
&& generateDataKeyResponse.Plaintext.Some? | ||
&& |generateDataKeyResponse.Plaintext.value| == 32, | ||
Types.KeyManagementException( | ||
message := "Invalid response from AWS KMS GenerateDataKey: KMS response's Plaintext is invalid." | ||
) | ||
); | ||
:- Need( | ||
&& generateDataKeyResponse.KeyId.Some? | ||
&& generateDataKeyResponse.KeyId.value == kmsKeyArn, | ||
Types.KeyManagementException( | ||
message := "Invalid response from AWS KMS GenerateDataKey: KMS Key ID of response did not match request." | ||
) | ||
); | ||
|
||
output := Success(generateDataKeyResponse.Plaintext.value); | ||
} | ||
|
||
method GenerateKey( | ||
encryptionContext: Structure.BranchKeyContext, | ||
kmsConfiguration: Types.KMSConfiguration, | ||
|
@@ -341,6 +408,7 @@ module {:options "/functionSyntax:4" } KMSKeystoreOperations { | |
res.Success? | ||
==> | ||
&& |kmsClient.History.Encrypt| == |old(kmsClient.History.Encrypt)| + 1 | ||
&& kmsClient.History.GenerateDataKey == old(kmsClient.History.GenerateDataKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I know this problem; but doing this should not be required. |
||
&& var kmsKeyArn := GetKeyId(kmsConfiguration); | ||
|
||
&& var encryptInput := Seq.Last(kmsClient.History.Encrypt).input; | ||
|
@@ -940,6 +1008,7 @@ module {:options "/functionSyntax:4" } KMSKeystoreOperations { | |
&& output.Success? ==> | ||
&& var kms := cryptoAndKms.kms.kmsSimple.kmsClient; | ||
&& |kms.History.Encrypt| == |old(kms.History.Encrypt)| + 1 | ||
&& kms.History.GenerateDataKey == old(kms.History.GenerateDataKey) | ||
&& var kmsEvent := Seq.Last(kms.History.Encrypt); | ||
&& kmsEvent.output.Success? | ||
&& var kmsInput := kmsEvent.input; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.