Skip to content

Commit 1ddbb7e

Browse files
ajewellamzseebees
authored andcommitted
feat: add expected context cmm (#146)
* feat: add expected context cmm * another polymorph run for test vectors --------- Co-authored-by: seebees <[email protected]>
1 parent 840f3e7 commit 1ddbb7e

File tree

14 files changed

+562
-124
lines changed

14 files changed

+562
-124
lines changed

AwsCryptographicMaterialProviders/Model/AwsCryptographyMaterialProvidersTypes.dfy

+100
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ include "../../StandardLibrary/src/Index.dfy"
5454
CreateRawRsaKeyring := [];
5555
CreateAwsKmsRsaKeyring := [];
5656
CreateDefaultCryptographicMaterialsManager := [];
57+
CreateExpectedEncryptionContextCMM := [];
5758
CreateCryptographicMaterialsCache := [];
5859
CreateDefaultClientSupplier := [];
5960
InitializeEncryptionMaterials := [];
@@ -81,6 +82,7 @@ include "../../StandardLibrary/src/Index.dfy"
8182
ghost var CreateRawRsaKeyring: seq<DafnyCallEvent<CreateRawRsaKeyringInput, Result<IKeyring, Error>>>
8283
ghost var CreateAwsKmsRsaKeyring: seq<DafnyCallEvent<CreateAwsKmsRsaKeyringInput, Result<IKeyring, Error>>>
8384
ghost var CreateDefaultCryptographicMaterialsManager: seq<DafnyCallEvent<CreateDefaultCryptographicMaterialsManagerInput, Result<ICryptographicMaterialsManager, Error>>>
85+
ghost var CreateExpectedEncryptionContextCMM: seq<DafnyCallEvent<CreateExpectedEncryptionContextCMMInput, Result<ICryptographicMaterialsManager, Error>>>
8486
ghost var CreateCryptographicMaterialsCache: seq<DafnyCallEvent<CreateCryptographicMaterialsCacheInput, Result<ICryptographicMaterialsCache, Error>>>
8587
ghost var CreateDefaultClientSupplier: seq<DafnyCallEvent<CreateDefaultClientSupplierInput, Result<IClientSupplier, Error>>>
8688
ghost var InitializeEncryptionMaterials: seq<DafnyCallEvent<InitializeEncryptionMaterialsInput, Result<EncryptionMaterials, Error>>>
@@ -464,6 +466,36 @@ include "../../StandardLibrary/src/Index.dfy"
464466
ensures CreateDefaultCryptographicMaterialsManagerEnsuresPublicly(input, output)
465467
ensures History.CreateDefaultCryptographicMaterialsManager == old(History.CreateDefaultCryptographicMaterialsManager) + [DafnyCallEvent(input, output)]
466468

469+
predicate CreateExpectedEncryptionContextCMMEnsuresPublicly(input: CreateExpectedEncryptionContextCMMInput , output: Result<ICryptographicMaterialsManager, Error>)
470+
// The public method to be called by library consumers
471+
method CreateExpectedEncryptionContextCMM ( input: CreateExpectedEncryptionContextCMMInput )
472+
returns (output: Result<ICryptographicMaterialsManager, Error>)
473+
requires
474+
&& ValidState() && ( input.underlyingCMM.Some? ==>
475+
&& input.underlyingCMM.value.ValidState()
476+
&& input.underlyingCMM.value.Modifies !! {History}
477+
) && ( input.keyring.Some? ==>
478+
&& input.keyring.value.ValidState()
479+
&& input.keyring.value.Modifies !! {History}
480+
)
481+
modifies Modifies - {History} ,
482+
(if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) ,
483+
(if input.keyring.Some? then input.keyring.value.Modifies else {}) ,
484+
History`CreateExpectedEncryptionContextCMM
485+
// Dafny will skip type parameters when generating a default decreases clause.
486+
decreases Modifies - {History} ,
487+
(if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) ,
488+
(if input.keyring.Some? then input.keyring.value.Modifies else {})
489+
ensures
490+
&& ValidState()
491+
&& ( output.Success? ==>
492+
&& output.value.ValidState()
493+
&& output.value.Modifies !! {History}
494+
&& fresh(output.value)
495+
&& fresh ( output.value.Modifies - Modifies - {History} - (if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) - (if input.keyring.Some? then input.keyring.value.Modifies else {}) ) )
496+
ensures CreateExpectedEncryptionContextCMMEnsuresPublicly(input, output)
497+
ensures History.CreateExpectedEncryptionContextCMM == old(History.CreateExpectedEncryptionContextCMM) + [DafnyCallEvent(input, output)]
498+
467499
predicate CreateCryptographicMaterialsCacheEnsuresPublicly(input: CreateCryptographicMaterialsCacheInput , output: Result<ICryptographicMaterialsCache, Error>)
468500
// The public method to be called by library consumers
469501
method CreateCryptographicMaterialsCache ( input: CreateCryptographicMaterialsCacheInput )
@@ -715,6 +747,11 @@ include "../../StandardLibrary/src/Index.dfy"
715747
datatype CreateDefaultCryptographicMaterialsManagerInput = | CreateDefaultCryptographicMaterialsManagerInput (
716748
nameonly keyring: IKeyring
717749
)
750+
datatype CreateExpectedEncryptionContextCMMInput = | CreateExpectedEncryptionContextCMMInput (
751+
nameonly underlyingCMM: Option<ICryptographicMaterialsManager> ,
752+
nameonly keyring: Option<IKeyring> ,
753+
nameonly requiredEncryptionContextKeys: EncryptionContextKeys
754+
)
718755
datatype CreateMultiKeyringInput = | CreateMultiKeyringInput (
719756
nameonly generator: Option<IKeyring> ,
720757
nameonly childKeyrings: KeyringList
@@ -1825,6 +1862,41 @@ include "../../StandardLibrary/src/Index.dfy"
18251862
History.CreateDefaultCryptographicMaterialsManager := History.CreateDefaultCryptographicMaterialsManager + [DafnyCallEvent(input, output)];
18261863
}
18271864

1865+
predicate CreateExpectedEncryptionContextCMMEnsuresPublicly(input: CreateExpectedEncryptionContextCMMInput , output: Result<ICryptographicMaterialsManager, Error>)
1866+
{Operations.CreateExpectedEncryptionContextCMMEnsuresPublicly(input, output)}
1867+
// The public method to be called by library consumers
1868+
method CreateExpectedEncryptionContextCMM ( input: CreateExpectedEncryptionContextCMMInput )
1869+
returns (output: Result<ICryptographicMaterialsManager, Error>)
1870+
requires
1871+
&& ValidState() && ( input.underlyingCMM.Some? ==>
1872+
&& input.underlyingCMM.value.ValidState()
1873+
&& input.underlyingCMM.value.Modifies !! {History}
1874+
) && ( input.keyring.Some? ==>
1875+
&& input.keyring.value.ValidState()
1876+
&& input.keyring.value.Modifies !! {History}
1877+
)
1878+
modifies Modifies - {History} ,
1879+
(if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) ,
1880+
(if input.keyring.Some? then input.keyring.value.Modifies else {}) ,
1881+
History`CreateExpectedEncryptionContextCMM
1882+
// Dafny will skip type parameters when generating a default decreases clause.
1883+
decreases Modifies - {History} ,
1884+
(if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) ,
1885+
(if input.keyring.Some? then input.keyring.value.Modifies else {})
1886+
ensures
1887+
&& ValidState()
1888+
&& ( output.Success? ==>
1889+
&& output.value.ValidState()
1890+
&& output.value.Modifies !! {History}
1891+
&& fresh(output.value)
1892+
&& fresh ( output.value.Modifies - Modifies - {History} - (if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) - (if input.keyring.Some? then input.keyring.value.Modifies else {}) ) )
1893+
ensures CreateExpectedEncryptionContextCMMEnsuresPublicly(input, output)
1894+
ensures History.CreateExpectedEncryptionContextCMM == old(History.CreateExpectedEncryptionContextCMM) + [DafnyCallEvent(input, output)]
1895+
{
1896+
output := Operations.CreateExpectedEncryptionContextCMM(config, input);
1897+
History.CreateExpectedEncryptionContextCMM := History.CreateExpectedEncryptionContextCMM + [DafnyCallEvent(input, output)];
1898+
}
1899+
18281900
predicate CreateCryptographicMaterialsCacheEnsuresPublicly(input: CreateCryptographicMaterialsCacheInput , output: Result<ICryptographicMaterialsCache, Error>)
18291901
{Operations.CreateCryptographicMaterialsCacheEnsuresPublicly(input, output)}
18301902
// The public method to be called by library consumers
@@ -2304,6 +2376,34 @@ include "../../StandardLibrary/src/Index.dfy"
23042376
ensures CreateDefaultCryptographicMaterialsManagerEnsuresPublicly(input, output)
23052377

23062378

2379+
predicate CreateExpectedEncryptionContextCMMEnsuresPublicly(input: CreateExpectedEncryptionContextCMMInput , output: Result<ICryptographicMaterialsManager, Error>)
2380+
// The private method to be refined by the library developer
2381+
2382+
2383+
method CreateExpectedEncryptionContextCMM ( config: InternalConfig , input: CreateExpectedEncryptionContextCMMInput )
2384+
returns (output: Result<ICryptographicMaterialsManager, Error>)
2385+
requires
2386+
&& ValidInternalConfig?(config) && ( input.underlyingCMM.Some? ==>
2387+
&& input.underlyingCMM.value.ValidState()
2388+
) && ( input.keyring.Some? ==>
2389+
&& input.keyring.value.ValidState()
2390+
)
2391+
modifies ModifiesInternalConfig(config) ,
2392+
(if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) ,
2393+
(if input.keyring.Some? then input.keyring.value.Modifies else {})
2394+
// Dafny will skip type parameters when generating a default decreases clause.
2395+
decreases ModifiesInternalConfig(config) ,
2396+
(if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) ,
2397+
(if input.keyring.Some? then input.keyring.value.Modifies else {})
2398+
ensures
2399+
&& ValidInternalConfig?(config)
2400+
&& ( output.Success? ==>
2401+
&& output.value.ValidState()
2402+
&& fresh(output.value)
2403+
&& fresh ( output.value.Modifies - ModifiesInternalConfig(config) - (if input.underlyingCMM.Some? then input.underlyingCMM.value.Modifies else {}) - (if input.keyring.Some? then input.keyring.value.Modifies else {}) ) )
2404+
ensures CreateExpectedEncryptionContextCMMEnsuresPublicly(input, output)
2405+
2406+
23072407
predicate CreateCryptographicMaterialsCacheEnsuresPublicly(input: CreateCryptographicMaterialsCacheInput , output: Result<ICryptographicMaterialsCache, Error>)
23082408
// The private method to be refined by the library developer
23092409

AwsCryptographicMaterialProviders/Model/cmms.smithy

+18
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,21 @@ structure CreateDefaultCryptographicMaterialsManagerInput {
131131
@required
132132
keyring: KeyringReference
133133
}
134+
135+
@positional
136+
structure CreateExpectedEncryptionContextCMMOutput {
137+
@required
138+
materialsManager: CryptographicMaterialsManagerReference
139+
}
140+
141+
operation CreateExpectedEncryptionContextCMM {
142+
input: CreateExpectedEncryptionContextCMMInput,
143+
output: CreateExpectedEncryptionContextCMMOutput,
144+
}
145+
146+
structure CreateExpectedEncryptionContextCMMInput {
147+
underlyingCMM: CryptographicMaterialsManagerReference,
148+
keyring: KeyringReference,
149+
@required
150+
requiredEncryptionContextKeys: EncryptionContextKeys
151+
}

AwsCryptographicMaterialProviders/Model/material-provider.smithy

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ service AwsCryptographicMaterialProviders {
3434

3535
// CMMs
3636
CreateDefaultCryptographicMaterialsManager,
37+
CreateExpectedEncryptionContextCMM,
3738

3839
// CMCs
3940
CreateCryptographicMaterialsCache,

AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialProviders/MaterialProviders.java

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import software.amazon.cryptography.materialProviders.model.CreateCryptographicMaterialsCacheInput;
2929
import software.amazon.cryptography.materialProviders.model.CreateDefaultClientSupplierInput;
3030
import software.amazon.cryptography.materialProviders.model.CreateDefaultCryptographicMaterialsManagerInput;
31+
import software.amazon.cryptography.materialProviders.model.CreateExpectedEncryptionContextCMMInput;
3132
import software.amazon.cryptography.materialProviders.model.CreateMultiKeyringInput;
3233
import software.amazon.cryptography.materialProviders.model.CreateRawAesKeyringInput;
3334
import software.amazon.cryptography.materialProviders.model.CreateRawRsaKeyringInput;
@@ -234,6 +235,16 @@ public ICryptographicMaterialsManager CreateDefaultCryptographicMaterialsManager
234235
return CryptographicMaterialsManager.wrap(result.dtor_value());
235236
}
236237

238+
public ICryptographicMaterialsManager CreateExpectedEncryptionContextCMM(
239+
CreateExpectedEncryptionContextCMMInput nativeValue) {
240+
Dafny.Aws.Cryptography.MaterialProviders.Types.CreateExpectedEncryptionContextCMMInput dafnyValue = ToDafny.CreateExpectedEncryptionContextCMMInput(nativeValue);
241+
Result<Dafny.Aws.Cryptography.MaterialProviders.Types.ICryptographicMaterialsManager, Error> result = this._impl.CreateExpectedEncryptionContextCMM(dafnyValue);
242+
if (result.is_Failure()) {
243+
throw ToNative.Error(result.dtor_error());
244+
}
245+
return CryptographicMaterialsManager.wrap(result.dtor_value());
246+
}
247+
237248
public ICryptographicMaterialsCache CreateCryptographicMaterialsCache(
238249
CreateCryptographicMaterialsCacheInput nativeValue) {
239250
Dafny.Aws.Cryptography.MaterialProviders.Types.CreateCryptographicMaterialsCacheInput dafnyValue = ToDafny.CreateCryptographicMaterialsCacheInput(nativeValue);

AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialProviders/ToDafny.java

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateCryptographicMaterialsCacheInput;
2121
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateDefaultClientSupplierInput;
2222
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateDefaultCryptographicMaterialsManagerInput;
23+
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateExpectedEncryptionContextCMMInput;
2324
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateMultiKeyringInput;
2425
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateRawAesKeyringInput;
2526
import Dafny.Aws.Cryptography.MaterialProviders.Types.CreateRawRsaKeyringInput;
@@ -610,6 +611,21 @@ public static GetEncryptionMaterialsInput GetEncryptionMaterialsInput(
610611
return new GetEncryptionMaterialsInput(encryptionContext, commitmentPolicy, algorithmSuiteId, maxPlaintextLength, requiredEncryptionContextKeys);
611612
}
612613

614+
public static CreateExpectedEncryptionContextCMMInput CreateExpectedEncryptionContextCMMInput(
615+
software.amazon.cryptography.materialProviders.model.CreateExpectedEncryptionContextCMMInput nativeValue) {
616+
Option<Dafny.Aws.Cryptography.MaterialProviders.Types.ICryptographicMaterialsManager> underlyingCMM;
617+
underlyingCMM = Objects.nonNull(nativeValue.underlyingCMM()) ?
618+
Option.create_Some(ToDafny.CryptographicMaterialsManager(nativeValue.underlyingCMM()))
619+
: Option.create_None();
620+
Option<Dafny.Aws.Cryptography.MaterialProviders.Types.IKeyring> keyring;
621+
keyring = Objects.nonNull(nativeValue.keyring()) ?
622+
Option.create_Some(ToDafny.Keyring(nativeValue.keyring()))
623+
: Option.create_None();
624+
DafnySequence<? extends DafnySequence<? extends Byte>> requiredEncryptionContextKeys;
625+
requiredEncryptionContextKeys = ToDafny.EncryptionContextKeys(nativeValue.requiredEncryptionContextKeys());
626+
return new CreateExpectedEncryptionContextCMMInput(underlyingCMM, keyring, requiredEncryptionContextKeys);
627+
}
628+
613629
public static InitializeDecryptionMaterialsInput InitializeDecryptionMaterialsInput(
614630
software.amazon.cryptography.materialProviders.model.InitializeDecryptionMaterialsInput nativeValue) {
615631
AlgorithmSuiteId algorithmSuiteId;

AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialProviders/ToNative.java

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import software.amazon.cryptography.materialProviders.model.CreateCryptographicMaterialsCacheInput;
5050
import software.amazon.cryptography.materialProviders.model.CreateDefaultClientSupplierInput;
5151
import software.amazon.cryptography.materialProviders.model.CreateDefaultCryptographicMaterialsManagerInput;
52+
import software.amazon.cryptography.materialProviders.model.CreateExpectedEncryptionContextCMMInput;
5253
import software.amazon.cryptography.materialProviders.model.CreateMultiKeyringInput;
5354
import software.amazon.cryptography.materialProviders.model.CreateRawAesKeyringInput;
5455
import software.amazon.cryptography.materialProviders.model.CreateRawRsaKeyringInput;
@@ -606,6 +607,19 @@ public static GetEncryptionMaterialsInput GetEncryptionMaterialsInput(
606607
return nativeBuilder.build();
607608
}
608609

610+
public static CreateExpectedEncryptionContextCMMInput CreateExpectedEncryptionContextCMMInput(
611+
Dafny.Aws.Cryptography.MaterialProviders.Types.CreateExpectedEncryptionContextCMMInput dafnyValue) {
612+
CreateExpectedEncryptionContextCMMInput.Builder nativeBuilder = CreateExpectedEncryptionContextCMMInput.builder();
613+
if (dafnyValue.dtor_underlyingCMM().is_Some()) {
614+
nativeBuilder.underlyingCMM(ToNative.CryptographicMaterialsManager(dafnyValue.dtor_underlyingCMM().dtor_value()));
615+
}
616+
if (dafnyValue.dtor_keyring().is_Some()) {
617+
nativeBuilder.keyring(ToNative.Keyring(dafnyValue.dtor_keyring().dtor_value()));
618+
}
619+
nativeBuilder.requiredEncryptionContextKeys(ToNative.EncryptionContextKeys(dafnyValue.dtor_requiredEncryptionContextKeys()));
620+
return nativeBuilder.build();
621+
}
622+
609623
public static InitializeDecryptionMaterialsInput InitializeDecryptionMaterialsInput(
610624
Dafny.Aws.Cryptography.MaterialProviders.Types.InitializeDecryptionMaterialsInput dafnyValue) {
611625
InitializeDecryptionMaterialsInput.Builder nativeBuilder = InitializeDecryptionMaterialsInput.builder();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
// Do not modify this file. This file is machine generated, and any changes to it will be overwritten.
4+
package software.amazon.cryptography.materialProviders.model;
5+
6+
import java.util.List;
7+
import java.util.Objects;
8+
import software.amazon.cryptography.materialProviders.CryptographicMaterialsManager;
9+
import software.amazon.cryptography.materialProviders.ICryptographicMaterialsManager;
10+
import software.amazon.cryptography.materialProviders.IKeyring;
11+
import software.amazon.cryptography.materialProviders.Keyring;
12+
13+
public class CreateExpectedEncryptionContextCMMInput {
14+
private final CryptographicMaterialsManager underlyingCMM;
15+
16+
private final Keyring keyring;
17+
18+
private final List<String> requiredEncryptionContextKeys;
19+
20+
protected CreateExpectedEncryptionContextCMMInput(BuilderImpl builder) {
21+
this.underlyingCMM = builder.underlyingCMM();
22+
this.keyring = builder.keyring();
23+
this.requiredEncryptionContextKeys = builder.requiredEncryptionContextKeys();
24+
}
25+
26+
public CryptographicMaterialsManager underlyingCMM() {
27+
return this.underlyingCMM;
28+
}
29+
30+
public Keyring keyring() {
31+
return this.keyring;
32+
}
33+
34+
public List<String> requiredEncryptionContextKeys() {
35+
return this.requiredEncryptionContextKeys;
36+
}
37+
38+
public Builder toBuilder() {
39+
return new BuilderImpl(this);
40+
}
41+
42+
public static Builder builder() {
43+
return new BuilderImpl();
44+
}
45+
46+
public interface Builder {
47+
Builder underlyingCMM(ICryptographicMaterialsManager underlyingCMM);
48+
49+
CryptographicMaterialsManager underlyingCMM();
50+
51+
Builder keyring(IKeyring keyring);
52+
53+
Keyring keyring();
54+
55+
Builder requiredEncryptionContextKeys(List<String> requiredEncryptionContextKeys);
56+
57+
List<String> requiredEncryptionContextKeys();
58+
59+
CreateExpectedEncryptionContextCMMInput build();
60+
}
61+
62+
static class BuilderImpl implements Builder {
63+
protected CryptographicMaterialsManager underlyingCMM;
64+
65+
protected Keyring keyring;
66+
67+
protected List<String> requiredEncryptionContextKeys;
68+
69+
protected BuilderImpl() {
70+
}
71+
72+
protected BuilderImpl(CreateExpectedEncryptionContextCMMInput model) {
73+
this.underlyingCMM = model.underlyingCMM();
74+
this.keyring = model.keyring();
75+
this.requiredEncryptionContextKeys = model.requiredEncryptionContextKeys();
76+
}
77+
78+
public Builder underlyingCMM(ICryptographicMaterialsManager underlyingCMM) {
79+
this.underlyingCMM = CryptographicMaterialsManager.wrap(underlyingCMM);
80+
return this;
81+
}
82+
83+
public CryptographicMaterialsManager underlyingCMM() {
84+
return this.underlyingCMM;
85+
}
86+
87+
public Builder keyring(IKeyring keyring) {
88+
this.keyring = Keyring.wrap(keyring);
89+
return this;
90+
}
91+
92+
public Keyring keyring() {
93+
return this.keyring;
94+
}
95+
96+
public Builder requiredEncryptionContextKeys(List<String> requiredEncryptionContextKeys) {
97+
this.requiredEncryptionContextKeys = requiredEncryptionContextKeys;
98+
return this;
99+
}
100+
101+
public List<String> requiredEncryptionContextKeys() {
102+
return this.requiredEncryptionContextKeys;
103+
}
104+
105+
public CreateExpectedEncryptionContextCMMInput build() {
106+
if (Objects.isNull(this.requiredEncryptionContextKeys())) {
107+
throw new IllegalArgumentException("Missing value for required field `requiredEncryptionContextKeys`");
108+
}
109+
return new CreateExpectedEncryptionContextCMMInput(this);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)