Skip to content

feat(dafny): Branch Key Store without modifying Encryption Context #1416

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

Draft
wants to merge 65 commits into
base: mutations/mutations
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e17db6f
chore: fix CI for HV-2 (#1353)
imabhichow Mar 25, 2025
51c7198
chore: move ProvideCryptoClient to HierarchicalVersionUtils in KeySto…
rishav-karanjit Mar 25, 2025
5e55f9c
ci(Go, Rust): disable for current HV-2 work (#1360)
texastony Mar 25, 2025
faf9622
feat(BKS & BKSA)!: Smithy Model for HV-2 (#1350)
texastony Mar 25, 2025
db67136
chore(BKS): pack & unpack plainTextTuple (#1362)
texastony Mar 26, 2025
1328a4e
chore(BKS): Add Helper functions to select KMS Encryption Context for…
imabhichow Mar 26, 2025
c35f991
chore: refactor hv1 functions and methods (#1367)
rishav-karanjit Mar 26, 2025
de7ef56
chore(bks): Add createMdDigest in hvutils (#1361)
rishav-karanjit Mar 27, 2025
9274827
chore(BKS): add decrypt hook For Hv2 (#1368)
rishav-karanjit Mar 28, 2025
18e1075
chore(dafny): Add todo for test (#1377)
rishav-karanjit Mar 31, 2025
f378730
chore(dafny): BranchKeyContext for HV-2 (#1381)
imabhichow Mar 31, 2025
b8802b9
chore(dafny): KS Refactor KeyStoreException (#1383)
imabhichow Mar 31, 2025
95c62f8
chore(dafny): BKS Encrypt Key for HV-1 & HV-2 (#1372)
imabhichow Apr 1, 2025
ef37253
chore(dafny): wire get keys with the decrypt hook (#1376)
rishav-karanjit Apr 1, 2025
8bd469d
chore(dafny): BKS Refactor GetKeys (#1389)
imabhichow Apr 2, 2025
29f7b9f
chore(dafny): add test for get keys (#1388)
rishav-karanjit Apr 3, 2025
73bb512
chore(dafny): add VerifyGetKeysFromStorage to test (#1392)
rishav-karanjit Apr 3, 2025
c5f51ab
chore(dafny): Add helper function to VerifyGetKeys (#1396)
rishav-karanjit Apr 4, 2025
545885f
feat(dafny): KSA Create Key Operation for HV-2 (#1374)
imabhichow Apr 4, 2025
8ea5cbe
test(dafny): no touching the static branch-key-id in the dev branch (…
texastony Apr 4, 2025
83211d8
test(dafny): restore static test branch key id (#1403)
texastony Apr 4, 2025
63b6409
chore(dafny): refactor HV1 MRK test to use helper methods (#1399)
rishav-karanjit Apr 5, 2025
f5f1de3
chore(dafny): KSA Add test coverage for creating a hv-2 branch key. (…
imabhichow Apr 8, 2025
6d1db95
chore: disable duvet (#1414)
texastony Apr 9, 2025
8d61b10
chore(java): create key example for HV-2 branch key (#1425)
imabhichow Apr 11, 2025
be086cd
refactor(dafny): rename BKS Error Messages class for legibility (#1429)
texastony Apr 14, 2025
999ae15
chore(dafny): Add helper method to decrypt branch key item (#1439)
rishav-karanjit Apr 14, 2025
cad6d00
chore(dafny): add checks and tests to fail on EC collision on init mu…
rishav-karanjit Apr 14, 2025
43a87ba
fix(dafny): BKSA CreateKey formal verification (#1427)
texastony Apr 15, 2025
a10d064
refactor(java): Move examples to new project to depend on ESDK (#1441)
texastony Apr 15, 2025
5fee8f0
chore(dafny): BKS HierarchyVersionToString (#1430)
texastony Apr 15, 2025
df977d3
refactor(dafny): prepare MutateItem for wiring of hv1 and hv2 (#1446)
rishav-karanjit Apr 15, 2025
e7f880c
test(dafny): BKSA errors if terminal HV is 1 (#1431)
texastony Apr 16, 2025
4d85523
feat(dafny): BKSA Mutation Commitment includes HV (#1432)
texastony Apr 16, 2025
c5d6038
chore(dafny): verify branch key item when terminal hv is 2 (#1442)
rishav-karanjit Apr 16, 2025
1b5be56
chore(dafny): add method to Mutate to HV2 without wiring (#1445)
rishav-karanjit Apr 16, 2025
354bca2
chore(dafny): refactor VersionActiveBranchKey to support multiple hi…
josecorella Apr 17, 2025
8939be9
fix(dafny): BKS Mutation Items treat `hierarchy-version` as schema ve…
texastony Apr 17, 2025
500b96d
test(dafny): ensures lying branch keys throws exception (#1422)
imabhichow Apr 17, 2025
ae81599
chore(dafny): BKSA Mutate from HV-1 to HV-2 only Simple (#1458)
texastony Apr 21, 2025
20cfd18
chore(dafny): BKSA test pre-HV-2 static branch keys for in-flight mut…
imabhichow Apr 21, 2025
49bb228
chore(dafny): move static branch keys to static key store table (#1459)
imabhichow Apr 21, 2025
cd3cafd
chore: refactor helper methods for copy & delete branch keys (#1462)
imabhichow Apr 22, 2025
4867143
chore(dafny): Test hv1 to hv2 mutation (#1461)
rishav-karanjit Apr 22, 2025
0379078
refactor(dafny): move TestMutateToHV2FromHV1 to mutation directory (…
rishav-karanjit Apr 22, 2025
f7f093a
chore(dafny): Add TODO to support terminal hv-1 but not downgrading f…
rishav-karanjit Apr 24, 2025
fd4bbc2
feat(dafny): support decrypt/encrypt strategy for mutation to hv2 (#…
rishav-karanjit Apr 25, 2025
1ec8cda
feat(dafny): mutate HV-2 to HV-2 without new version (#1474)
imabhichow Apr 25, 2025
63b1008
chore(java): add examples for mutation to hv-2 (#1477)
rishav-karanjit Apr 28, 2025
d3b94a4
test(java): BKSA in-flight mutations access denied (#1480)
imabhichow Apr 29, 2025
e3eacb5
feat(dafny): support hv-2 versionKey in KeyStoreAdmin (#1455)
josecorella Apr 30, 2025
3b74ecf
chore(dafny): add version on mutate functionality (#1485)
josecorella Apr 30, 2025
92b6258
chore(dafny): fix verification in kms keyring ondecrypt (#1489)
josecorella May 2, 2025
bd5c1b8
chore(dafny): BKSA Mutations Tests for HV-1 to HV-1 (#1482)
imabhichow May 2, 2025
42612ab
chore(dafny): Complete Strategy Support for BKSA VersionKey & CreateK…
imabhichow May 5, 2025
e8e869f
chore(dafny): add hv-2 create key proofs (#1499)
josecorella May 6, 2025
0fe76f7
chore(dafny): support kms simple for v1 to v1 mutations (#1491)
imabhichow May 6, 2025
ac1d634
chore(dafny): add version key hv-2 proofs (#1504)
josecorella May 8, 2025
66ae3df
chore(dafny): BKS CreateKey remove redundant EC checks for HV-2 (#1508)
texastony May 9, 2025
4f6887f
chore(dafny): BKSA refine KMS Error mapping to MutationTo/From except…
imabhichow May 9, 2025
8f822b4
chore(dafny): BKSA Tests for Restarting Mutations (#1501)
imabhichow May 10, 2025
70bf132
chore(dafny): cleanup todos in hv-2 (#1511)
rishav-karanjit May 13, 2025
61406ea
chore(dafny): add failure for unexpected attribute in EC on HV-2 (#1516)
rishav-karanjit May 16, 2025
7e0ed9e
test(dafny): some testing on EC transforms (#1521)
texastony May 16, 2025
268ffd7
chore(dafny): remove duplicate proof in kms keyring (#1526)
josecorella May 19, 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
11 changes: 6 additions & 5 deletions .github/workflows/duvet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# with respect to the specification
name: Duvet report

on:
pull_request:
push:
branches:
- main
# TODO-HV-2 : Re-Enable Duvet once mutations/mutations Duvet is healthy
# on:
# pull_request:
# push:
# branches:
# - main

jobs:
duvet:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/library_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ jobs:
# This works because `node` is installed by default on GHA runners
CORES=$(node -e 'console.log(os.cpus().length)')
make build_java CORES=$CORES
make mvn_local_deploy

- name: Test AwsCryptographicMaterialProviders Java Examples
working-directory: ./AwsCryptographicMaterialProviders
working-directory: ./Examples
run: |
make test_example_java
make test_java

# These tests are "flacky" and not really neccessary,
# we created them in re-action to a user error with local caches and DDB
# - name: Test AwsCryptographicMaterialProviders Java Concurrent
# working-directory: ./Examples
# run: |
# make test_java_concurrent
3 changes: 2 additions & 1 deletion .github/workflows/library_interop_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
strategy:
matrix:
library: [TestVectorsAwsCryptographicMaterialProviders]
os: [
os:
[
# https://taskei.amazon.dev/tasks/CrypTool-5283
# windows-latest,
ubuntu-22.04,
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ jobs:
with:
dafny: ${{ inputs.dafny }}
regenerate-code: ${{ inputs.regenerate-code }}
manual-ci-rust:
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: ${{ inputs.dafny }}
regenerate-code: ${{ inputs.regenerate-code }}
# TODO-HV-2-Rust: Removing Rust Runtimes until the underlying issue resolved.
# manual-ci-rust:
# uses: ./.github/workflows/library_rust_tests.yml
# with:
# dafny: ${{ inputs.dafny }}
# regenerate-code: ${{ inputs.regenerate-code }}
manual-ci-python:
uses: ./.github/workflows/library_python_tests.yml
with:
dafny: ${{ inputs.dafny }}
regenerate-code: ${{ inputs.regenerate-code }}
manual-ci-go:
uses: ./.github/workflows/library_go_tests.yml
with:
dafny: ${{ inputs.dafny }}
regenerate-code: ${{ inputs.regenerate-code }}
# TODO-HV-2-Go: Removing Go CI until we rebase or need it
# manual-ci-go:
# uses: ./.github/workflows/library_go_tests.yml
# with:
# dafny: ${{ inputs.dafny }}
# regenerate-code: ${{ inputs.regenerate-code }}
manual-interop-test:
uses: ./.github/workflows/library_interop_tests.yml
with:
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ jobs:
uses: ./.github/workflows/library_net_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
# TODO-HV-2-Rust: Removing Rust until we rebase or need it
# pr-ci-rust:
# needs: getVersion
# uses: ./.github/workflows/library_rust_tests.yml
# with:
# dafny: ${{needs.getVersion.outputs.version}}
pr-ci-python:
needs: getVersion
uses: ./.github/workflows/library_python_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
# TODO-HV-2-Python: Removing Python until we fix bugs in Dafny/Python transpilation
# pr-ci-python:
# needs: getVersion
# uses: ./.github/workflows/library_python_tests.yml
# with:
# dafny: ${{needs.getVersion.outputs.version}}
# TODO-HV-2-Go: Removing Go CI until we rebase or need it
# pr-ci-go:
# needs: getVersion
# uses: ./.github/workflows/library_go_tests.yml
Expand All @@ -70,12 +73,15 @@ jobs:
- pr-ci-verification
- pr-ci-java
- pr-ci-net
- pr-ci-python
# TODO-HV-2-Python: Removing Python until we fix bugs in Dafny/Python transpilation
# - pr-ci-python
# TODO-HV-2-Go: Removing Go CI until we rebase or need it
# - pr-ci-go
# TODO-HV-2-Rust: Removing Rust until we rebase or need it
# - pr-ci-rust
- pr-interop-test
- pr-ci-examples
runs-on: ubuntu--22.04
runs-on: ubuntu-22.04
steps:
- name: Verify all required jobs passed
uses: re-actors/alls-green@release/v1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
uses: ./.github/workflows/library_net_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
# TODO-HV-2-Rust: Removing Rust until we rebase or need it.
# push-ci-rust:
# needs: getVersion
# uses: ./.github/workflows/library_rust_tests.yml
Expand All @@ -46,6 +47,7 @@ jobs:
uses: ./.github/workflows/library_python_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
# TODO-HV-2-Go: Removing Go CI until we rebase or need it
# push-ci-go:
# needs: getVersion
# uses: ./.github/workflows/library_go_tests.yml
Expand Down
3 changes: 0 additions & 3 deletions AwsCryptographicMaterialProviders/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,3 @@ PYTHON_DEPENDENCY_MODULE_NAMES := \
--dependency-library-name=aws.cryptography.materialProviders=aws_cryptographic_material_providers \
--dependency-library-name=aws.cryptography.keyStore=aws_cryptographic_material_providers \
--dependency-library-name=aws.cryptography.keyStoreAdmin=aws_cryptographic_material_providers \

test_example_java:
$(GRADLEW) -p runtimes/java cleanTestExamples testExamples
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,75 @@ module CanonicalEncryptionContext {
else Failure(Types.AwsCryptographicMaterialProvidersException( message := "Unable to serialize encryption context"))
}

// @texastony had a dream of using this predicates to
// remove duplicate code in HVUtils
// and CreateKeyHV2.dfy but has given up on the dream for now.
// TODO-HV-2-FOLLOW : Complete Dream or Kill this
// predicate digestSHA384ContextPostConditions(
// nameonly content: seq<uint8>,
// nameonly digest: seq<uint8>,
// nameonly digestEvent: AtomicPrimitives.Types.DafnyCallEvent<AtomicPrimitives.Types.DigestInput, Result<seq<uint8>, AtomicPrimitives.Types.Error>>
// )
// {
// var input := digestEvent.input;
// var output := digestEvent.output;
// && input.digestAlgorithm == AtomicPrimitives.Types.SHA_384
// && input.message == content
// && output.Success?
// ==>
// && |output.value| == 48 // 384 bits / 8 bits per byte == 48 bytes
// && output.value == digest
// }

// twostate predicate encryptionContextDigestPostConditions(
// crypto: AtomicPrimitives.AtomicPrimitivesClient,
// encryptionContext: Types.EncryptionContext,
// digest: seq<uint8>
// )
// reads crypto.History
// {
// && var content? := EncryptionContextToAAD(encryptionContext);
// && content?.Success?
// && |crypto.History.Digest| == |old(crypto.History.Digest)| + 1
// && var digestEvent := Seq.Last(crypto.History.Digest);
// && digestSHA384ContextPostConditions(
// content := content?.value,
// digest := digest,
// digestEvent := digestEvent)
// }

method EncryptionContextDigest(
Crypto: AtomicPrimitives.AtomicPrimitivesClient,
crypto: AtomicPrimitives.AtomicPrimitivesClient,
encryptionContext: Types.EncryptionContext
)
returns (output: Result<seq<uint8>, CanonizeDigestError>)
requires Crypto.ValidState()
modifies Crypto.Modifies
ensures Crypto.ValidState()
ensures output.Success? ==>
&& 0 < |Crypto.History.Digest|
&& Seq.Last(Crypto.History.Digest).output.Success?
&& var DigestInput := Seq.Last(Crypto.History.Digest).input;
&& var DigestOutput := Seq.Last(Crypto.History.Digest).output;
&& DigestInput.digestAlgorithm == AtomicPrimitives.Types.SHA_384
&& DigestOutput.value == output.value
requires crypto.ValidState()
modifies crypto.Modifies
ensures crypto.ValidState()
// We tried to collapse all of this post condition into a common predicate.
// We failed; we will have to copy and paste it.
// @texastony thinks reason is that is very difficult to keep track of the input.
ensures
&& output.Success?
==>
&& var content? := EncryptionContextToAAD(encryptionContext);
&& content?.Success?
&& |crypto.History.Digest| == |old(crypto.History.Digest)| + 1
&& old(crypto.History.Digest) < crypto.History.Digest
&& var digestEvent := Seq.Last(crypto.History.Digest);
&& digestEvent.input.digestAlgorithm == AtomicPrimitives.Types.SHA_384
&& digestEvent.input.message == content?.value
&& digestEvent.output.Success?
&& |digestEvent.output.value| == 48 // 384 bits / 8 bits per byte == 48 bytes
&& digestEvent.output.value == output.value
{
var canonicalEC :- EncryptionContextToAAD(encryptionContext);

var DigestInput := AtomicPrimitives.Types.DigestInput(
digestAlgorithm := AtomicPrimitives.Types.SHA_384,
message := canonicalEC
);
var maybeDigest := Crypto.Digest(DigestInput);
var maybeDigest := crypto.Digest(DigestInput);
var digest :- maybeDigest.MapFailure(e => Types.AwsCryptographyPrimitives(e));

// The digest is not truncated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ module AwsKmsKeyring {
));
}

AnEdkExistsLemma(edksToAttempt);

//= aws-encryption-sdk-specification/framework/aws-kms/aws-kms-keyring.md#ondecrypt
//# For each encrypted data key in the filtered set, one at a time, the
//# OnDecrypt MUST attempt to decrypt the data key.
Expand Down Expand Up @@ -548,13 +550,28 @@ module AwsKmsKeyring {
list := errors,
message := "No Configured KMS Key was able to decrypt the Data Key. The list of encountered Exceptions is available via `list`."));

assert exists edk | edk in edksToAttempt
::
&& var maybeWrappedMaterial :=
EdkWrapping.GetProviderWrappedMaterial(edk.ciphertext, input.materials.algorithmSuite);
&& maybeWrappedMaterial.Success?
&& KMS.IsValid_CiphertextType(maybeWrappedMaterial.value);

assert decryptClosure.Ensures(Last(attempts).input, Success(SealedDecryptionMaterials), DropLast(attempts));
return Success(Types.OnDecryptOutput(
materials := SealedDecryptionMaterials
));
}
}

lemma AnEdkExistsLemma(edksToAttempt: seq<Types.EncryptedDataKey>)
requires |edksToAttempt| > 0
ensures exists edk | edk in edksToAttempt :: true
{
var edk := edksToAttempt[0];
assert edk in edksToAttempt;
}

class OnDecryptEncryptedDataKeyFilter
extends DeterministicActionWithResult<Types.EncryptedDataKey, bool, Types.Error>
{
Expand All @@ -571,8 +588,8 @@ module AwsKmsKeyring {
&& (
&& res.Success?
&& res.value
==>
edk.keyProviderId == PROVIDER_ID)
==> exists edk' | edk' == edk
:: edk'.keyProviderId == PROVIDER_ID)
}

method Invoke(edk: Types.EncryptedDataKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// SPDX-License-Identifier: Apache-2.0
// Do not modify this file. This file is machine generated, and any changes to it will be overwritten.
include "../../../../StandardLibrary/src/Index.dfy"
include "../../../../AwsCryptographyPrimitives/src/Index.dfy"
include "../../../../ComAmazonawsDynamodb/src/Index.dfy"
include "../../../../ComAmazonawsKms/src/Index.dfy"
module {:extern "software.amazon.cryptography.keystore.internaldafny.types" } AwsCryptographyKeyStoreTypes
{
import opened Wrappers
import opened StandardLibrary.UInt
import opened UTF8
import AwsCryptographyPrimitivesTypes
import ComAmazonawsDynamodbTypes
import ComAmazonawsKmsTypes
// Generic helpers for verification of mock/unit tests.
Expand Down Expand Up @@ -151,6 +153,9 @@ module {:extern "software.amazon.cryptography.keystore.internaldafny.types" } Aw
datatype HierarchicalSymmetric = | HierarchicalSymmetric (
nameonly Version: string
)
datatype HierarchyVersion =
| v1
| v2
type HmacKeyMap = map<string, Secret>
datatype KeyManagement =
| kms(kms: AwsKms)
Expand Down Expand Up @@ -924,6 +929,9 @@ module {:extern "software.amazon.cryptography.keystore.internaldafny.types" } Aw
| BranchKeyCiphertextException (
nameonly message: string
)
| HierarchyVersionException (
nameonly message: string
)
| KeyManagementException (
nameonly message: string
)
Expand All @@ -946,6 +954,7 @@ module {:extern "software.amazon.cryptography.keystore.internaldafny.types" } Aw
nameonly message: string
)
// Any dependent models are listed here
| AwsCryptographyPrimitives(AwsCryptographyPrimitives: AwsCryptographyPrimitivesTypes.Error)
| ComAmazonawsDynamodb(ComAmazonawsDynamodb: ComAmazonawsDynamodbTypes.Error)
| ComAmazonawsKms(ComAmazonawsKms: ComAmazonawsKmsTypes.Error)
// The Collection error is used to collect several errors together
Expand Down
Loading