Skip to content

Conversation

@rishav-karanjit
Copy link
Member

@rishav-karanjit rishav-karanjit commented Apr 22, 2025

Issue #, if available:

Description of changes:

  • Add VerifyEncryptedHierarchicalKeyForHV2 and VerifyEncryptedHierarchicalKeyForHV1
  • VerifyEncryptedHierarchicalKey now delegates to either VerifyEncryptedHierarchicalKeyForHV2 or VerifyEncryptedHierarchicalKeyForHV1
  • Add support for decrypt/encrypt strategy for mutation to hv2

Squash/merge commit message, if applicable:

feat(dafny): support decrypt/encrypt strategy for mutation to hv2 

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

@rishav-karanjit rishav-karanjit changed the title refactor(dafny): add separate method to verify encrypted hierarchical key for HV1 and HV2 refactor(dafny): add separate method to verify encrypted hierarchical key for HV1 and HV2 Apr 22, 2025
@rishav-karanjit rishav-karanjit changed the title refactor(dafny): add separate method to verify encrypted hierarchical key for HV1 and HV2 refactor(dafny): add methods to verify EncryptedHierarchicalKey for HV1 and HV2 Apr 22, 2025
@rishav-karanjit rishav-karanjit changed the title refactor(dafny): add methods to verify EncryptedHierarchicalKey for HV1 and HV2 refactor(dafny): refactor VerifyEncryptedHierarchicalKey Apr 22, 2025
@rishav-karanjit rishav-karanjit changed the title refactor(dafny): refactor VerifyEncryptedHierarchicalKey refactor(dafny): refactor VerifyEncryptedHierarchicalKey Apr 22, 2025
@rishav-karanjit rishav-karanjit changed the title refactor(dafny): refactor VerifyEncryptedHierarchicalKey refactor(dafny): refactor VerifyEncryptedHierarchicalKey Apr 22, 2025
@rishav-karanjit rishav-karanjit changed the title refactor(dafny): refactor VerifyEncryptedHierarchicalKey refactor(dafny): VerifyEncryptedHierarchicalKey Apr 22, 2025
@rishav-karanjit rishav-karanjit changed the title refactor(dafny): VerifyEncryptedHierarchicalKey refactor(dafny): Split VerifyEncryptedHierarchicalKey into version-specific implementations Apr 22, 2025
@rishav-karanjit rishav-karanjit marked this pull request as ready for review April 22, 2025 23:51
@rishav-karanjit rishav-karanjit requested a review from a team as a code owner April 22, 2025 23:51
requires mutationToApply.Terminal.hierarchyVersion.v2?
modifies keyManagerStrategy.Modifies
ensures keyManagerStrategy.ValidState()
{
Copy link
Member Author

@rishav-karanjit rishav-karanjit Apr 22, 2025

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

@rishav-karanjit rishav-karanjit changed the title refactor(dafny): Split VerifyEncryptedHierarchicalKey into version-specific implementations refactor(dafny): split VerifyEncryptedHierarchicalKey into version-specific implementations Apr 22, 2025
@rishav-karanjit
Copy link
Member Author

rishav-karanjit commented Apr 24, 2025

I am merging PR (#1472) with (#1466). The combined diff does not seem to be long.

@rishav-karanjit rishav-karanjit changed the title refactor(dafny): split VerifyEncryptedHierarchicalKey into version-specific implementations feat(dafny): support encrypt decrypt for mutation to hv2 Apr 24, 2025
@rishav-karanjit rishav-karanjit changed the title feat(dafny): support encrypt decrypt for mutation to hv2 feat(dafny): support decrypt/encrypt strategy for mutation to hv2 Apr 24, 2025
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.

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.

Comment on lines 188 to 192
if localOperation == "ApplyMutation" {
KMSTuple := KmsUtils.getEncryptKMSTuple(keyManagerStrategy);
} else {
KMSTuple := KmsUtils.getDecryptKMSTuple(keyManagerStrategy);
}
Copy link
Contributor

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.

Copy link
Member Author

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"
Copy link
Contributor

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.

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.

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 (
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise:

  1. I like how you moved the constants up
  2. I like this function

@rishav-karanjit rishav-karanjit merged commit fd4bbc2 into hv-2/hv-2 Apr 25, 2025
140 checks passed
@rishav-karanjit rishav-karanjit deleted the rishav/hv-2/M2/refactorForDecryptEncrypt branch April 25, 2025 17:37
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