1
1
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- import { isKmsConfig , KmsConfig , RegionalKmsConfig } from './kms_config'
4
+ import { KmsConfig , KmsKeyConfig } from './kms_config'
5
5
import { KMSClient } from '@aws-sdk/client-kms'
6
6
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
7
7
import {
@@ -62,12 +62,12 @@ export interface KeyStoreInfoOutput {
62
62
}
63
63
64
64
export class BranchKeyStoreNode implements IBranchKeyStoreNode {
65
- public declare logicalKeyStoreName : string
66
- public declare kmsConfiguration : Readonly < KmsConfig >
67
- public declare kmsClient : KMSClient
68
- public declare keyStoreId : string
69
- public declare grantTokens ?: ReadonlyArray < string >
70
- public declare storage : IBranchKeyStorage
65
+ public declare readonly logicalKeyStoreName : string
66
+ public declare readonly kmsConfiguration : Readonly < KmsKeyConfig >
67
+ public declare readonly kmsClient : KMSClient
68
+ public declare readonly keyStoreId : string
69
+ public declare readonly grantTokens ?: ReadonlyArray < string >
70
+ public declare readonly storage : IBranchKeyStorage
71
71
72
72
constructor ( {
73
73
logicalKeyStoreName,
@@ -82,8 +82,12 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
82
82
'Logical keystore name must be a string'
83
83
)
84
84
85
- /* Precondition: KMS Configuration must be SRK */
86
- needs ( isKmsConfig ( kmsConfiguration ) , 'KMS Configuration must be SRK' )
85
+ needs ( kmsConfiguration , 'AWS KMS Configuration required' )
86
+ readOnlyProperty (
87
+ this ,
88
+ 'kmsConfiguration' ,
89
+ new KmsKeyConfig ( kmsConfiguration )
90
+ )
87
91
88
92
/* Precondition: KMS client must be a KMSClient */
89
93
if ( keyManagement ?. kmsClient ) {
@@ -131,7 +135,16 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
131
135
storage . ddbClient instanceof DynamoDBClient
132
136
? storage . ddbClient
133
137
: new DynamoDBClient ( {
134
- region : ( kmsConfiguration as RegionalKmsConfig ) . getRegion ( ) ,
138
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
139
+ //# If a DDB client needs to be constructed and the AWS KMS Configuration is KMS Key ARN or KMS MRKey ARN,
140
+ //# a new DynamoDb client MUST be created with the region of the supplied KMS ARN.
141
+ //#
142
+ //# If a DDB client needs to be constructed and the AWS KMS Configuration is Discovery,
143
+ //# a new DynamoDb client MUST be created with the default configuration.
144
+ //#
145
+ //# If a DDB client needs to be constructed and the AWS KMS Configuration is MRDiscovery,
146
+ //# a new DynamoDb client MUST be created with the region configured in the MRDiscovery.
147
+ region : this . kmsConfiguration . getRegion ( ) ,
135
148
} ) ,
136
149
} )
137
150
}
@@ -176,9 +189,6 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
176
189
)
177
190
/* Postcondition: If unprovided, the grant tokens are undefined */
178
191
179
- needs ( kmsConfiguration , 'AWS KMS Configuration required' )
180
- readOnlyProperty ( this , 'kmsConfiguration' , Object . freeze ( kmsConfiguration ) )
181
-
182
192
// TODO: when other KMS configuration types/classes are supported for the keystore,
183
193
// verify the configuration object type to determine how we instantiate the
184
194
// KMS client. This will ensure safe type casting.
@@ -189,7 +199,16 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
189
199
//# If no AWS KMS client is provided one MUST be constructed.
190
200
keyManagement ?. kmsClient ||
191
201
new KMSClient ( {
192
- region : ( this . kmsConfiguration as RegionalKmsConfig ) . getRegion ( ) ,
202
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
203
+ //# If AWS KMS client needs to be constructed and the AWS KMS Configuration is KMS Key ARN or KMS MRKey ARN,
204
+ //# a new AWS KMS client MUST be created with the region of the supplied KMS ARN.
205
+ //#
206
+ //# If AWS KMS client needs to be constructed and the AWS KMS Configuration is Discovery,
207
+ //# a new AWS KMS client MUST be created with the default configuration.
208
+ //#
209
+ //# If AWS KMS client needs to be constructed and the AWS KMS Configuration is MRDiscovery,
210
+ //# a new AWS KMS client MUST be created with the region configured in the MRDiscovery.
211
+ region : this . kmsConfiguration . getRegion ( ) ,
193
212
//= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
194
213
//# On initialization the KeyStore SHOULD
195
214
//# append a user agent string to the AWS KMS SDK Client with
@@ -375,7 +394,7 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
375
394
keystoreTableName : this . storage . getKeyStorageInfo ( ) . name ,
376
395
logicalKeyStoreName : this . logicalKeyStoreName ,
377
396
grantTokens : ! ! this . grantTokens ? this . grantTokens . slice ( ) : [ ] ,
378
- kmsConfiguration : this . kmsConfiguration ,
397
+ kmsConfiguration : this . kmsConfiguration . _config ,
379
398
}
380
399
}
381
400
}
@@ -650,25 +669,25 @@ export function isIBranchKeyStoreNode(
650
669
//= aws-encryption-sdk-specification/framework/branch-key-store.md#getbeaconkey
651
670
//= type=exception
652
671
//# On invocation, the caller:
653
- //#
672
+ //#
654
673
//# - MUST supply a `branch-key-id`
655
- //#
674
+ //#
656
675
//# GetBeaconKey MUST get the requested beacon key from the keystore
657
676
//# by calling the configured [KeyStorage interface's](./key-store/key-storage.md#interface)
658
677
//# [GetEncryptedBeaconKey](./key-store/key-storage.md#getencryptedbeaconkey)
659
678
//# using the supplied `branch-key-id`.
660
- //#
679
+ //#
661
680
//# Because the storage interface can be a custom implementation the key store needs to verify correctness.
662
- //#
681
+ //#
663
682
//# GetBeaconKey MUST verify that the returned EncryptedHierarchicalKey MUST have the requested `branch-key-id`.
664
683
//# GetBeaconKey MUST verify that the returned EncryptedHierarchicalKey is an ActiveHierarchicalSymmetricBeacon.
665
684
//# GetBeaconKey MUST verify that the returned EncryptedHierarchicalKey MUST have a logical table name equal to the configured logical table name.
666
- //#
685
+ //#
667
686
//# The operation MUST decrypt the beacon key according to the [AWS KMS Branch Key Decryption](#aws-kms-branch-key-decryption) section.
668
- //#
687
+ //#
669
688
//# If the beacon key fails to decrypt, this operation MUST fail.
670
- //#
689
+ //#
671
690
//# This GetBeaconKey MUST construct [beacon key materials](./structures.md#beacon-key-materials) from the decrypted branch key material
672
691
//# and the `branchKeyId` from the returned `branch-key-id` field.
673
- //#
674
- //# This operation MUST return the constructed [beacon key materials](./structures.md#beacon-key-materials).
692
+ //#
693
+ //# This operation MUST return the constructed [beacon key materials](./structures.md#beacon-key-materials).
0 commit comments