@@ -77,128 +77,89 @@ module TestGetKeys {
77
77
{
78
78
var ddbClient :- expect DDB. DynamoDBClient ();
79
79
80
- var eastKeyStoreConfig := Types. KeyStoreConfig (
81
- id := None,
82
- kmsConfiguration := KmsConfigEast,
83
- logicalKeyStoreName := logicalKeyStoreName,
84
- storage := Some(
85
- Types.ddb(
86
- Types.DynamoDBTable(
87
- ddbTableName := branchKeyStoreName,
88
- ddbClient := Some(ddbClient)
89
- )))
80
+ var westKeyStore :- expect KeyStoreWithOptionalClient (
81
+ kmsId := MrkArnWest,
82
+ physicalName := branchKeyStoreName,
83
+ logicalName := logicalKeyStoreName,
84
+ ddbClient? := Some(ddbClient)
90
85
);
91
86
92
- var westKeyStoreConfig := Types. KeyStoreConfig (
93
- id := None,
94
- kmsConfiguration := KmsConfigWest,
95
- logicalKeyStoreName := logicalKeyStoreName,
96
- storage := Some(
97
- Types.ddb(
98
- Types.DynamoDBTable(
99
- ddbTableName := branchKeyStoreName,
100
- ddbClient := Some(ddbClient)
101
- )))
87
+ var eastKeyStore :- expect KeyStoreWithOptionalClient (
88
+ kmsId := MrkArnEast,
89
+ physicalName := branchKeyStoreName,
90
+ logicalName := logicalKeyStoreName,
91
+ ddbClient? := Some(ddbClient)
102
92
);
103
93
104
- var eastMrkKeyStoreConfig := Types. KeyStoreConfig (
105
- id := None,
106
- kmsConfiguration := KmsMrkConfigEast,
107
- logicalKeyStoreName := logicalKeyStoreName,
108
- storage := Some(
109
- Types.ddb(
110
- Types.DynamoDBTable(
111
- ddbTableName := branchKeyStoreName,
112
- ddbClient := Some(ddbClient)
113
- )))
94
+ var westMrkKeyStore :- expect KeyStoreWithOptionalClient (
95
+ kmsId := MrkArnWest,
96
+ physicalName := branchKeyStoreName,
97
+ logicalName := logicalKeyStoreName,
98
+ ddbClient? := Some(ddbClient),
99
+ srkKey := false ,
100
+ mrkKey := true
114
101
);
115
102
116
- var westMrkKeyStoreConfig := Types. KeyStoreConfig (
117
- id := None,
118
- kmsConfiguration := KmsMrkConfigWest,
119
- logicalKeyStoreName := logicalKeyStoreName,
120
- storage := Some(
121
- Types.ddb(
122
- Types.DynamoDBTable(
123
- ddbTableName := branchKeyStoreName,
124
- ddbClient := Some(ddbClient)
125
- )))
103
+ var eastMrkKeyStore :- expect KeyStoreWithOptionalClient (
104
+ kmsId := MrkArnEast,
105
+ physicalName := branchKeyStoreName,
106
+ logicalName := logicalKeyStoreName,
107
+ ddbClient? := Some(ddbClient),
108
+ srkKey := false ,
109
+ mrkKey := true
126
110
);
127
111
128
- // KmsMrkConfigAP is NOT created
129
- var apMrkKeyStoreConfig := Types. KeyStoreConfig (
130
- id := None,
131
- kmsConfiguration := KmsMrkConfigAP,
132
- logicalKeyStoreName := logicalKeyStoreName,
133
- storage := Some(
134
- Types.ddb(
135
- Types.DynamoDBTable(
136
- ddbTableName := branchKeyStoreName,
137
- ddbClient := Some(ddbClient)
138
- )))
112
+ var apMrkKeyStore :- expect KeyStoreWithOptionalClient (
113
+ kmsId := MrkArnAP,
114
+ physicalName := branchKeyStoreName,
115
+ logicalName := logicalKeyStoreName,
116
+ ddbClient? := Some(ddbClient),
117
+ srkKey := false ,
118
+ mrkKey := true
139
119
);
140
120
121
+ // All four set of keys (branch, beacon and version) should work when the regions match
122
+ testActiveBranchKeyHappyCase (westKeyStore, WestBranchKey, WestBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
123
+ testBeaconKeyHappyCase (westKeyStore, WestBranchKey);
124
+ testBranchKeyVersionHappyCase (westKeyStore, WestBranchKey, WestBranchKeyIdActiveVersion, WestBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
141
125
142
- var westKeyStore :- expect KeyStore. KeyStore (westKeyStoreConfig);
143
- var eastKeyStore :- expect KeyStore. KeyStore (eastKeyStoreConfig);
144
- var westMrkKeyStore :- expect KeyStore. KeyStore (westMrkKeyStoreConfig);
145
- var eastMrkKeyStore :- expect KeyStore. KeyStore (eastMrkKeyStoreConfig);
146
- var apMrkKeyStore :- expect KeyStore. KeyStore (apMrkKeyStoreConfig);
126
+ testActiveBranchKeyHappyCase (eastKeyStore, EastBranchKey, EastBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
127
+ testBeaconKeyHappyCase (eastKeyStore, EastBranchKey);
128
+ testBranchKeyVersionHappyCase (eastKeyStore, EastBranchKey, EastBranchKeyIdActiveVersion, EastBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
147
129
148
- // All four should work when the regions match
130
+ testActiveBranchKeyHappyCase (westMrkKeyStore, WestBranchKey, WestBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
131
+ testBeaconKeyHappyCase (westMrkKeyStore, WestBranchKey);
132
+ testBranchKeyVersionHappyCase (westMrkKeyStore, WestBranchKey, WestBranchKeyIdActiveVersion, WestBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
149
133
150
- var activeResult :- expect westKeyStore. GetActiveBranchKey (
151
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := WestBranchKey));
152
- expect activeResult. branchKeyMaterials. branchKeyIdentifier == WestBranchKey;
153
- expect |activeResult. branchKeyMaterials. branchKey| == 32;
154
-
155
- activeResult :- expect eastKeyStore. GetActiveBranchKey (
156
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := EastBranchKey));
157
- expect activeResult. branchKeyMaterials. branchKeyIdentifier == EastBranchKey;
158
- expect |activeResult. branchKeyMaterials. branchKey| == 32;
159
-
160
- activeResult :- expect westMrkKeyStore. GetActiveBranchKey (
161
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := WestBranchKey));
162
- expect activeResult. branchKeyMaterials. branchKeyIdentifier == WestBranchKey;
163
- expect |activeResult. branchKeyMaterials. branchKey| == 32;
164
-
165
- activeResult :- expect eastMrkKeyStore. GetActiveBranchKey (
166
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := EastBranchKey));
167
- expect activeResult. branchKeyMaterials. branchKeyIdentifier == EastBranchKey;
168
- expect |activeResult. branchKeyMaterials. branchKey| == 32;
134
+ testActiveBranchKeyHappyCase (eastMrkKeyStore, EastBranchKey, EastBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
135
+ testBeaconKeyHappyCase (eastMrkKeyStore, EastBranchKey);
136
+ testBranchKeyVersionHappyCase (eastMrkKeyStore, EastBranchKey, EastBranchKeyIdActiveVersion, EastBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
169
137
170
138
// MRK Configuration should work with the other region
171
139
172
- activeResult :- expect westMrkKeyStore. GetActiveBranchKey (
173
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := EastBranchKey));
174
- expect activeResult. branchKeyMaterials. branchKeyIdentifier == EastBranchKey;
175
- expect |activeResult. branchKeyMaterials. branchKey| == 32;
140
+ testActiveBranchKeyHappyCase (westMrkKeyStore, EastBranchKey, EastBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
141
+ testBeaconKeyHappyCase (westMrkKeyStore, EastBranchKey);
142
+ testBranchKeyVersionHappyCase (westMrkKeyStore, EastBranchKey, EastBranchKeyIdActiveVersion, EastBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
176
143
177
- activeResult :- expect eastMrkKeyStore. GetActiveBranchKey (
178
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := WestBranchKey));
179
- expect activeResult. branchKeyMaterials. branchKeyIdentifier == WestBranchKey;
180
- expect |activeResult. branchKeyMaterials. branchKey| == 32;
144
+ testActiveBranchKeyHappyCase (eastMrkKeyStore, WestBranchKey, WestBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
145
+ testBeaconKeyHappyCase (eastMrkKeyStore, WestBranchKey);
146
+ testBranchKeyVersionHappyCase (eastMrkKeyStore, WestBranchKey, WestBranchKeyIdActiveVersion, WestBranchKeyBranchKeyIdActiveVersionUtf8Bytes);
181
147
182
148
// Plain Configuration should fail with the other region
183
149
184
- var badResult := westKeyStore. GetActiveBranchKey (
185
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := EastBranchKey));
186
- expect badResult. Failure?;
187
- expect badResult. error == Types. Error. KeyStoreException (message := ErrorMessages.GET_KEY_ARN_DISAGREEMENT);
150
+ GetActiveKeyWithIncorrectKmsKeyArnHelper (westKeyStore, EastBranchKey);
151
+ GetBeaconKeyWithIncorrectKmsKeyArnHelper (westKeyStore, EastBranchKey);
152
+ GetBranchKeyVersionWithIncorrectKmsKeyArnHelper (westKeyStore, EastBranchKey, EastBranchKeyIdActiveVersion);
188
153
189
- badResult := eastKeyStore. GetActiveBranchKey (
190
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := WestBranchKey));
191
- expect badResult. Failure?;
192
- expect badResult. error == Types. Error. KeyStoreException (message := ErrorMessages.GET_KEY_ARN_DISAGREEMENT);
154
+ GetActiveKeyWithIncorrectKmsKeyArnHelper (eastKeyStore, WestBranchKey);
155
+ GetBeaconKeyWithIncorrectKmsKeyArnHelper (eastKeyStore, WestBranchKey);
156
+ GetBranchKeyVersionWithIncorrectKmsKeyArnHelper (eastKeyStore, WestBranchKey, WestBranchKeyIdActiveVersion);
193
157
194
158
// apMrkKeyStore should always fail
195
159
196
- badResult := apMrkKeyStore. GetActiveBranchKey (
197
- Types.GetActiveBranchKeyInput(branchKeyIdentifier := WestBranchKey));
198
- expect badResult. Failure?;
199
- expect badResult. error. ComAmazonawsKms?;
200
- expect badResult. error. ComAmazonawsKms. OpaqueWithText?;
201
- // it's an opaque error, so I can't test its contents
160
+ testActiveBranchKeyKMSFailureCase (apMrkKeyStore, WestBranchKey);
161
+ testBranchKeyVersionKMSFailureCase (apMrkKeyStore, WestBranchKey, WestBranchKeyIdActiveVersion);
162
+ testBeaconKeyKMSFailureCase (apMrkKeyStore, WestBranchKey);
202
163
}
203
164
204
165
method {:test} TestKeyWithIncorrectKmsKeyArn () {
@@ -246,7 +207,7 @@ module TestGetKeys {
246
207
method {:test} TestGetKeysWithNoClients () {
247
208
var kmsConfig := Types. KMSConfiguration. kmsKeyArn (keyArn);
248
209
249
- var keyStore :- expect KeyStoreWithNoClient (kmsId:=keyArn, physicalName:=branchKeyStoreName, logicalName := logicalKeyStoreName);
210
+ var keyStore :- expect KeyStoreWithOptionalClient (kmsId:=keyArn, physicalName:=branchKeyStoreName, logicalName := logicalKeyStoreName);
250
211
251
212
testActiveBranchKeyHappyCase (keyStore, branchKeyId, branchKeyIdActiveVersionUtf8Bytes);
252
213
testActiveBranchKeyHappyCase (keyStore, hv2BranchKeyId, hv2BranchKeyIdActiveVersionUtf8Bytes);
@@ -462,6 +423,46 @@ module TestGetKeys {
462
423
&& |versionResult. branchKeyMaterials. branchKey| == 32
463
424
}
464
425
426
+ method testActiveBranchKeyKMSFailureCase (keyStore: Types .IKeyStoreClient, branchKeyId: string )
427
+ requires keyStore. ValidState ()
428
+ modifies keyStore. Modifies
429
+ {
430
+ var branchKeyResult := keyStore. GetActiveBranchKey (
431
+ Types.GetActiveBranchKeyInput(
432
+ branchKeyIdentifier := branchKeyId
433
+ ));
434
+ expect branchKeyResult. Failure?;
435
+ expect branchKeyResult. error. ComAmazonawsKms?;
436
+ expect branchKeyResult. error. ComAmazonawsKms. OpaqueWithText?;
437
+ }
438
+
439
+ method testBranchKeyVersionKMSFailureCase (keyStore: Types .IKeyStoreClient, branchKeyId: string , branchKeyIdActiveVersion: string )
440
+ requires keyStore. ValidState ()
441
+ modifies keyStore. Modifies
442
+ {
443
+ var versionResult := keyStore. GetBranchKeyVersion (
444
+ Types.GetBranchKeyVersionInput(
445
+ branchKeyIdentifier := branchKeyId,
446
+ branchKeyVersion := branchKeyIdActiveVersion
447
+ ));
448
+ expect versionResult. Failure?;
449
+ expect versionResult. error. ComAmazonawsKms?;
450
+ expect versionResult. error. ComAmazonawsKms. OpaqueWithText?;
451
+ }
452
+
453
+ method testBeaconKeyKMSFailureCase (keyStore: Types .IKeyStoreClient, branchKeyId: string )
454
+ requires keyStore. ValidState ()
455
+ modifies keyStore. Modifies
456
+ {
457
+ var beaconKeyResult := keyStore. GetBeaconKey (
458
+ Types.GetBeaconKeyInput(
459
+ branchKeyIdentifier := branchKeyId
460
+ ));
461
+ expect beaconKeyResult. Failure?;
462
+ expect beaconKeyResult. error. ComAmazonawsKms?;
463
+ expect beaconKeyResult. error. ComAmazonawsKms. OpaqueWithText?;
464
+ }
465
+
465
466
method VerifyGetKeysFromStorage (
466
467
identifier : string ,
467
468
storage : Types .IKeyStorageInterface
0 commit comments