Skip to content
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

(WIP)feat(HV-2): CreateKey #1349

Closed
wants to merge 48 commits into from

Conversation

imabhichow
Copy link
Contributor

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.

rishav-karanjit and others added 30 commits March 18, 2025 09:58
Copy link
Contributor

@texastony texastony left a comment

Choose a reason for hiding this comment

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

I think this is great progress;
we need to get some consolidation going on Monday between the various PRs to make our mile-stone.

It is too hard for me to review 48 commits of code at once;
the three of us need to work together to collapse our efforts/changes.

@@ -57,6 +57,9 @@ module {:options "/functionSyntax:4" } KeyStoreErrorMessages {
const INVALID_HIERARCHY_VERSION :=
"Invalid hierarchy version. Expected version 1 or 2."

const BRANCH_KEY_MD_DIGEST_SHA_INCORRECT_LENGTH :=
"Branch key + md digest sha is of incorrect length."
Copy link
Contributor

Choose a reason for hiding this comment

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

Blocking: No customer will know what this means.
Look at this comment on made on Rishav's PR:
#1342 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

}
var branchKeyMaterials :- Structure.ToBranchKeyMaterials(
branchKeyItemFromStorage,
plaintextBranchKey
branchKey.Plaintext.value[Structure.MD_DIGEST_LENGTH..]
Copy link
Contributor

Choose a reason for hiding this comment

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

Blocking: We need to validate the PDK is the right length before returning it.
Break the PDK out before calling Structure.ToBranchKeyMaterials.
I get that other logic in the current code path
ensures that the PDK is the right length today;
but it is fragile to assume that will always be the case.

Copy link
Member

@rishav-karanjit rishav-karanjit Mar 24, 2025

Choose a reason for hiding this comment

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

We need to validate the PDK is the right length before returning it.

This is done inside ValidateMdDigest because we also need valid length to validate MD Digest

Copy link
Member

Choose a reason for hiding this comment

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

Break the PDK out before calling Structure.ToBranchKeyMaterials.

Added a TODO

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +438 to +466
// branchKeyItemFromStorage.EncryptionContext comes from storage is not the actual EC.
// branchKeyItemFromStorage.EncryptionContext contains all the items in the dynamodb table and table name.
var hv2EC := HierarchicalVersionUtils.GetHV2EC(branchKeyItemFromStorage.EncryptionContext);
var hv2BranchKey := Types.EncryptedHierarchicalKey(
Identifier := branchKeyItemFromStorage.Identifier,
Type := branchKeyItemFromStorage.Type,
CreateTime := branchKeyItemFromStorage.CreateTime,
KmsArn := branchKeyItemFromStorage.KmsArn,
EncryptionContext := hv2EC,
CiphertextBlob := branchKeyItemFromStorage.CiphertextBlob
);
var branchKey: KMS.DecryptResponse :- KMSKeystoreOperations.DecryptKeyForHV2(
hv2BranchKey,
kmsConfiguration,
grantTokens,
kmsClient
);
var validateResult := HierarchicalVersionUtils.ValidateMdDigest(branchKey.Plaintext.value, branchKeyItemFromStorage);
if (validateResult.Failure?) {
return Failure(validateResult.error);
}
var branchKeyMaterials :- Structure.ToBranchKeyMaterials(
branchKeyItemFromStorage,
branchKey.Plaintext.value[0..Structure.AES_256_LENGTH]
);
return Success(
Types.GetBranchKeyVersionOutput(
branchKeyMaterials := branchKeyMaterials
));
Copy link
Contributor

Choose a reason for hiding this comment

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

Blocking: This looks a lot like copy-and-paste/code duplication...
Can we make a helper method in HierarchicalVersionUtils that can be used to consolidate this?

Copy link
Member

Choose a reason for hiding this comment

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

branchKeyItemFromStorage: Types.EncryptedHierarchicalKey
)
returns (output: Result<(), Types.Error>)
// The plaintext should be large enough to contain both AES key and MD digest
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The plaintext should be large enough to contain both AES key and MD digest
// The plaintext-tuple MUST be large enough to contain both AES key and MD digest

Copy link
Member

Choose a reason for hiding this comment

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

@@ -111,4 +126,59 @@ module HierarchicalVersionUtils {
assume {:axiom} fresh(Crypto) && fresh(Crypto.Modifies);
return Success(Crypto);
}

method ValidateMdDigest (
plainText: KMS.PlaintextType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: There are so many plain-texts in our lives;
plain-text messages/content,
plain-text data keys,
plain-text wrapping keys...
let's give this variable a little distinctiveness by calling it plainTextTuple;
we know it is the concatenation of the PDK + protected-MD-Digest;
we could call that concatenation a tuple for short (
it sort of is, sort of isn't, but I think tuple is good enough and better than plainText).

Suggested change
plainText: KMS.PlaintextType,
plainTextTuple: KMS.PlaintextType,

Copy link
Member

Choose a reason for hiding this comment

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

@@ -111,4 +126,59 @@ module HierarchicalVersionUtils {
assume {:axiom} fresh(Crypto) && fresh(Crypto.Modifies);
return Success(Crypto);
}

method ValidateMdDigest (
Copy link
Contributor

Choose a reason for hiding this comment

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

OK. I think see where you are going;
you are going to replace the duplicated code in GetKeys with this method,
yes?

Copy link
Member

Choose a reason for hiding this comment

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

yes

@@ -718,8 +723,82 @@ module {:options "/functionSyntax:4" } KMSKeystoreOperations {

}

ghost predicate AwsKmsBranchKeyHV2Decryption?(
versionItem: Types.EncryptedHierarchicalKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

Blocking/Question: I think just call this a branchKeyItem;
I do not see any reason to restrict it to just version types, as compared to branch:ACTIVE or beacon:ACTIVE.

Copy link
Member

Choose a reason for hiding this comment

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

Need predicate needs more update. A verification is also failing. So, I just added TODO for now.

https://github.com/aws/aws-cryptographic-material-providers-library/pull/1354/files#r2011026081

@texastony texastony deleted the branch hv-2/smithy-model March 26, 2025 02:49
@texastony texastony closed this Mar 26, 2025
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.

3 participants