Skip to content

Commit 1639ef4

Browse files
feat(kms-keyring-node): add AWS KMS Hierarchical keyring (#632)
* hkr * remove timeouts * fix test timeout issues * add an additional verification check * set up mocking * document mock mechanism * hkr * remove timeouts * fix test timeout issues * add an additional verification check * set up mocking * document mock mechanism * added runtime type checks to constructor * try fixing dep errors * fixes * add notice * renaming and modified preconditions Number attributes like TTL and max cache size can only be stored with precision if they are under JavaScript's Number.MAX_SAFE_INTEGER. In the MPL, TTL can be a non-negative signed 64-bit integer. However, JavaScript numbers cannot safely store integers beyond Number.MAX_SAFE_INTEGER. Thus, we will cap TTL in seconds such that TTL in ms is <= Number.MAX_SAFE_INTEGER. TTL could be a JS BigInt type but this would require casting back to a number in order to configure the CMC (which only deals with number types not BigInt), which leads to a lossy conversion. This same reasoning is applied to max cache size. Preconditions and tests for these preconditions are updated. * change in wrapping AAD logic * Update modules/kms-keyring-node/src/constants.ts add comment about encrypted key length in the ciphertext Co-authored-by: Rishav karanjit <karanjitrishav4@gmail.com> * update constants change name of the kdf digest algorithm constant to specify sha256. Increases readability * update constants change provider id constant name to specify hierarchy --------- Co-authored-by: Rishav karanjit <karanjitrishav4@gmail.com>
1 parent 406dee7 commit 1639ef4

13 files changed

+3259
-2
lines changed

modules/kms-keyring-node/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@
1919
},
2020
"license": "Apache-2.0",
2121
"dependencies": {
22+
"@aws-crypto/branch-keystore-node": "file:../branch-keystore-node",
23+
"@aws-crypto/cache-material": "file:../cache-material",
24+
"@aws-crypto/kdf-ctr-mode-node": "file:../kdf-ctr-mode-node",
2225
"@aws-crypto/kms-keyring": "file:../kms-keyring",
2326
"@aws-crypto/material-management-node": "file:../material-management-node",
27+
"@aws-crypto/serialize": "file:../serialize",
28+
"@aws-sdk/client-dynamodb": "^3.621.0",
2429
"@aws-sdk/client-kms": "^3.362.0",
30+
"sinon": "^18.0.0",
2531
"tslib": "^2.2.0"
2632
},
2733
"sideEffects": false,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { KeyringTraceFlag } from '@aws-crypto/material-management'
5+
6+
export const ACTIVE_AS_BYTES = Buffer.from('ACTIVE', 'utf-8')
7+
export const CACHE_ENTRY_ID_DIGEST_ALGORITHM = 'sha512'
8+
export const KDF_DIGEST_ALGORITHM_SHA_256 = 'sha256'
9+
export const ENCRYPT_FLAGS =
10+
KeyringTraceFlag.WRAPPING_KEY_ENCRYPTED_DATA_KEY |
11+
KeyringTraceFlag.WRAPPING_KEY_SIGNED_ENC_CTX
12+
export const DECRYPT_FLAGS =
13+
KeyringTraceFlag.WRAPPING_KEY_DECRYPTED_DATA_KEY |
14+
KeyringTraceFlag.WRAPPING_KEY_VERIFIED_ENC_CTX
15+
export const PROVIDER_ID_HIERARCHY = 'aws-kms-hierarchy'
16+
export const PROVIDER_ID_HIERARCHY_AS_BYTES = Buffer.from(
17+
PROVIDER_ID_HIERARCHY,
18+
'utf-8'
19+
)
20+
export const DERIVED_BRANCH_KEY_LENGTH = 32
21+
export const CACHE_ENTRY_ID_LENGTH = 32
22+
export const KEY_DERIVATION_LABEL = Buffer.from(PROVIDER_ID_HIERARCHY, 'utf-8')
23+
export const CIPHERTEXT_STRUCTURE = {
24+
saltLength: 16,
25+
ivLength: 12,
26+
branchKeyVersionCompressedLength: 16,
27+
// Encrypted Key is of variable length
28+
authTagLength: 16,
29+
}

modules/kms-keyring-node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './kms_mrk_keyring_node'
66
export * from './kms_mrk_discovery_keyring_node'
77
export * from './kms_mrk_strict_multi_keyring_node'
88
export * from './kms_mrk_discovery_multi_keyring_node'
9+
export * from './kms_hkeyring_node'

0 commit comments

Comments
 (0)