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

feat(BKS): Get* HV-2 Branch Keys #1342

Draft
wants to merge 61 commits into
base: hv-2/hv-2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
11687e8
chore(Java): version by properties file only
texastony Nov 14, 2024
e4b5a58
feat: Adding a storage option to the KeyStore (#594)
seebees Sep 18, 2024
d1c3075
chore(KSA-Model): more Mutation Operation changes (#955)
texastony Sep 18, 2024
c4af12f
fix(Mutations): KMS Exception improvements
texastony Nov 12, 2024
f8e91e7
feat(KSA): Describe Mutation
texastony Nov 13, 2024
8795bf5
feat(KSA): KMS Decrypt/Encrypt Strategy (#1020)
texastony Nov 25, 2024
0f0ede0
feat(KSA): System Key (#1021) (#1055)
texastony Nov 25, 2024
c44f328
chore: percolate changes from HEAD to mutations branch
texastony Nov 26, 2024
5896cf8
fix(KS-Smithy): explicit error for tampered Branch Key (#1058)
texastony Nov 26, 2024
621116e
chore: fix decrypt encrypt strategy (#1059)
josecorella Nov 26, 2024
34683eb
fix(KSA): Describe Mutation bugs (#1062)
texastony Nov 27, 2024
9d66289
chore: error refinement improvements decrypt/encrypt strategy (#1061)
josecorella Nov 27, 2024
63fa534
fix(KSA-Dafny): break up Mutations, other fixes, more tests (#1069)
texastony Dec 2, 2024
5b2f851
fix: use correct client depending on operation (#1084)
josecorella Dec 4, 2024
6714c65
test(KSA-Java): assert deletion of Index/Commitment at end of Mutatio…
texastony Dec 4, 2024
42149ec
docs: update documentation for Key Store Admin Errors (#1086)
josecorella Dec 5, 2024
b26fbb3
test(KSA): Utilize Limit KMS Clients in Mutation D/E test (#1089)
texastony Dec 5, 2024
a914309
feat(KSA): DoNotVersion for Initialize Mutation (#1082)
texastony Dec 6, 2024
15f1cf0
feat(KSA): require System Key + doc polish + tests (#1092)
texastony Dec 9, 2024
3f9f7d7
fix(MPL): remove un-used imports (#1103)
texastony Dec 10, 2024
180a7d8
chore(Rust): fix Rust import of the KSA (#1110)
texastony Dec 11, 2024
528d8f0
docs(KSA): clarify mutation behvior (#1112)
texastony Dec 12, 2024
90a390e
chore(Smithy): remove Smithy trait un-supported by Smithy-Dafny (#1134)
texastony Dec 17, 2024
2fc52ac
test: add concurrency testing for storage operations (#1132)
josecorella Dec 23, 2024
af0078d
fix(KeyStoreAdmin): Go support (#1242)
texastony Jan 22, 2025
eb56365
fix(GHW): Library Example (#1269)
texastony Jan 31, 2025
0c5cfa7
fix(KeyStoreAdmin): Exceptions for Mutations when KMS Key is Disabled…
texastony Feb 16, 2025
53abc2c
Add GetEncryptionContextHV1 and GetEncryptionContextHV2
rishav-karanjit Mar 18, 2025
64f45de
Add INVALID_HIERARCHY_VERSION error message
rishav-karanjit Mar 18, 2025
c769619
Add need for H version check
rishav-karanjit Mar 18, 2025
5d59de7
Revert "Add GetEncryptionContextHV1 and GetEncryptionContextHV2"
rishav-karanjit Mar 18, 2025
d29744f
hv2 changes
rishav-karanjit Mar 18, 2025
0f05c52
add constant for HIERARCHY_VERSION number
rishav-karanjit Mar 18, 2025
44cfb48
ToHV2EC method
rishav-karanjit Mar 18, 2025
ef18557
rough sha impl
rishav-karanjit Mar 19, 2025
bcd0a8c
hv2 getkey rought sketch
rishav-karanjit Mar 19, 2025
108284c
Some clean ups
rishav-karanjit Mar 19, 2025
02c3898
formatting
rishav-karanjit Mar 19, 2025
e1db473
Add HierarchicalVersionUtils utils
rishav-karanjit Mar 19, 2025
304c832
refactoring
rishav-karanjit Mar 19, 2025
11e266a
revert storage helper
rishav-karanjit Mar 19, 2025
dfac4ae
fix GetMdDigestFromEC
rishav-karanjit Mar 19, 2025
c8052ba
MD_DIGEST_LENGTH and AES_256_LENGTH
rishav-karanjit Mar 20, 2025
d80676a
chores in get key
rishav-karanjit Mar 20, 2025
7dbeabb
rename to DecryptKeyForHV1
rishav-karanjit Mar 20, 2025
1aa9758
rename predicate AttemptKmsOperation? to AttemptKmsOperationForHV1?
rishav-karanjit Mar 20, 2025
35333e1
rename AttemptKmsOperation? to AttemptKmsOperationForHV1?
rishav-karanjit Mar 20, 2025
045a853
Revert "rename AttemptKmsOperation? to AttemptKmsOperationForHV1?"
rishav-karanjit Mar 20, 2025
aa6e810
Revert "rename predicate AttemptKmsOperation? to AttemptKmsOperationF…
rishav-karanjit Mar 20, 2025
d0c1f23
Add DecryptKeyForHV2
rishav-karanjit Mar 20, 2025
84a5829
use DecryptKeyForHV2
rishav-karanjit Mar 20, 2025
8c53237
Add Hv2EncryptionContext?
rishav-karanjit Mar 20, 2025
9348860
fix path to predicates
rishav-karanjit Mar 20, 2025
45efb9c
Update AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStor…
rishav-karanjit Mar 20, 2025
da2be20
Add KMS_DECRYPT_INVALID_KEY_LENGTH_HV2
rishav-karanjit Mar 20, 2025
af9c4a5
Add INVALID_BRANCH_KEY_CONTEXT
rishav-karanjit Mar 20, 2025
bbfab39
refactoring for verification
rishav-karanjit Mar 21, 2025
6cd7f44
Add AwsKmsBranchKeyHV2Decryption?
rishav-karanjit Mar 21, 2025
159aaa9
Add ValidateMdDigest
rishav-karanjit Mar 21, 2025
67de9db
beacon and branch key version
rishav-karanjit Mar 21, 2025
32df5db
fix
rishav-karanjit Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ module {:options "/functionSyntax:4" } KeyStoreErrorMessages {

const INVALID_HIERARCHY_VERSION :=
"Invalid hierarchy version. Expected version 1 or 2."

const MD_DIGEST_SHA_NOT_MATCHED :=
"Decrypted md digest SHA does not match md digest sha from the table."
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,6 @@ module GetKeys {
message := ErrorMessages.INVALID_HIERARCHY_VERSION
)
);
var a := ToHV2EC(branchKeyItem.EncryptionContext);
print(a);
print("\n");
var b :- ParseEncryptionContext(a);
print(b);
var crypto := ProvideCryptoClient();
if (crypto.Failure?) {
var e := Types.KeyStoreException(
message :=
"yo");
return Failure(e);
}
var c := CanonicalEncryptionContext.EncryptionContextDigest(crypto.value, b);
if (c.Failure?) {
var e := Types.KeyStoreException(
message :=
"yo");
return Failure(e);
}
print(c.value);
if (branchKeyItem.EncryptionContext[Structure.HIERARCHY_VERSION] == Structure.HIERARCHY_VERSION_1) {
var branchKey: KMS.DecryptResponse :- KMSKeystoreOperations.DecryptKey(
branchKeyItem,
Expand All @@ -205,22 +185,49 @@ module GetKeys {
branchKeyMaterials := branchKeyMaterials
));
} else if (branchKeyItem.EncryptionContext[Structure.HIERARCHY_VERSION] == Structure.HIERARCHY_VERSION_2) {
// print(branchKeyItem.EncryptionContext);
// print(ToHV2EC(branchKeyItem.EncryptionContext));
var hv2EC := getHV2EC(branchKeyItem.EncryptionContext);
var hv2BranchKey := Types.EncryptedHierarchicalKey(
Identifier := branchKeyItem.Identifier,
Type := branchKeyItem.Type,
CreateTime := branchKeyItem.CreateTime,
KmsArn := branchKeyItem.KmsArn,
EncryptionContext := hv2EC,
CiphertextBlob := branchKeyItem.CiphertextBlob
);
var branchKey: KMS.DecryptResponse :- KMSKeystoreOperations.DecryptKey(
branchKeyItem,
hv2BranchKey,
kmsConfiguration,
grantTokens,
kmsClient
);

mdDigestFromTable := getMdDigestFromEC(branchKeyItem.EncryptionContext)
var utf8MdDigest :- UnstringifyEncryptionContext(mdDigestFromTable);
var crypto := ProvideCryptoClient();
if (crypto.Failure?) {
var e := Types.KeyStoreException(
message :=
"Local Cryptography error: " + AtomicPrimitives.ErrorUtils.MessageOrUnknown(crypto.error));
return Failure(e);
}
var mdDigestShaFromTable := CanonicalEncryptionContext.EncryptionContextDigest(crypto.value, utf8MdDigest);
if (ecDigest.Failure?) {
var e := Types.KeyStoreException(
message :=
"Failed to create mdDigest");
return Failure(e);
}
var plaintextBranchKeyWithMdDigest := branchKey.Plaintext.value;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
var plaintextBranchKeyWithMdDigest := branchKey.Plaintext.value;
var plaintextBranchKeyWithMdDigest := kmsDecryptRes.Plaintext.value;

var plaintextBranchKey := plaintextBranchKeyWithMdDigest[0..|plaintextBranchKeyWithMdDigest|-48];
var mdDigest := plaintextBranchKeyWithMdDigest[|plaintextBranchKeyWithMdDigest|-48..];

var decryptedMdDigest := plaintextBranchKeyWithMdDigest[|plaintextBranchKeyWithMdDigest|-48..];
if (decryptedMdDigest != mdDigestShaFromTable) {
var e := Types.KeyStoreException(
message :=
ErrorMessages.MD_DIGEST_SHA_NOT_MATCHED);
return Failure(e);
}
var branchKeyMaterials :- Structure.ToBranchKeyMaterials(
branchKeyItem,
branchKey.Plaintext.value
plaintextBranchKey
);
return Success(
Types.GetActiveBranchKeyOutput(
Expand All @@ -230,7 +237,14 @@ module GetKeys {

}

method ToHV2EC(
method getMdDigestFromEC(
item: Types.EncryptionContextString
) returns (output: Types.EncryptionContextString)
{
mdDigest := map k | k in Structure.BRANCH_KEY_RESTRICTED_FIELD_NAMES && k in item :: item[k];
}

method getHV2EC(
item: Types.EncryptionContextString
) returns (output: Types.EncryptionContextString)
{
Expand All @@ -253,13 +267,13 @@ module GetKeys {
return newMap;
}

function method ParseEncryptionContext(stringEncCtx: Types.EncryptionContextString) : (res: Result<Types.EncryptionContext, Types.Error>)
function method UnstringifyEncryptionContext(stringEncCtx: Types.EncryptionContextString) : (res: Result<Types.EncryptionContext, Types.Error>)
{
if |stringEncCtx| == 0 then
Success(map[])
else
var parseResults: map<string, Result<(UTF8.ValidUTF8Bytes, UTF8.ValidUTF8Bytes), Types.Error>> :=
map strKey | strKey in stringEncCtx.Keys :: strKey := ParseEncryptionContextPair(strKey, stringEncCtx[strKey]);
map strKey | strKey in stringEncCtx.Keys :: strKey := UnstringifyEncryptionContextPair(strKey, stringEncCtx[strKey]);
if exists r | r in parseResults.Values :: r.Failure?
then Failure(
Types.KeyStoreException(message := "Encryption context contains invalid UTF8")
Expand All @@ -273,7 +287,7 @@ module GetKeys {
else Success(map r | r in parseResults.Values :: r.value.0 := r.value.1)
}

function method ParseEncryptionContextPair(strKey: string, strValue: string) : (res: Result<(UTF8.ValidUTF8Bytes, UTF8.ValidUTF8Bytes), Types.Error>)
function method UnstringifyEncryptionContextPair(strKey: string, strValue: string) : (res: Result<(UTF8.ValidUTF8Bytes, UTF8.ValidUTF8Bytes), Types.Error>)
ensures (UTF8.Encode(strKey).Success? && UTF8.Encode(strValue).Success?) <==> res.Success?
{
var key :- UTF8
Expand Down
Loading