Skip to content
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

Raw AES Keyring zeros out passed in unwrappedMasterKey #970

Open
lavaleri opened this issue Jul 22, 2022 · 0 comments
Open

Raw AES Keyring zeros out passed in unwrappedMasterKey #970

lavaleri opened this issue Jul 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@lavaleri
Copy link
Contributor

Problem:

The materials manager zeros out the dataKey in the processing of creating wrapping key material during construction:

export function wrapWithKeyObjectIfSupported(
dataKey: Uint8Array | AwsEsdkKeyObject
): Uint8Array | AwsEsdkKeyObject {
if (supportsKeyObject) {
if (dataKey instanceof Uint8Array) {
const ko = supportsKeyObject.createSecretKey(dataKey)
/* Postcondition: Zero the secret. It is now inside the KeyObject. */
dataKey.fill(0)
return ko
}
if (dataKey instanceof supportsKeyObject.KeyObject) return dataKey
} else if (dataKey instanceof Uint8Array) {
return dataKey
}
throw new Error('Unsupported dataKey type')
}

This is normally good practice. However in the case where the buffer has been passed in by the customer via Keyring creation, for example in the Raw AES Keyring case, this leads to surprising behavior.

The Raw AES Keyrings does not make a defensive copy of the key material before creating this material: https://github.com/aws/aws-encryption-sdk-javascript/blob/master/modules/raw-aes-keyring-node/src/raw_aes_keyring_node.ts#L63

And thus the "unwrappedMasterKey" that the customer passed in looks like it gets "consumed." This is surprising to the customer, especially since our docs have no indication of this behavior.

Solution:

The Raw AES Keyring should make a defensive copy of the "unwrappedMasterKey" in it's constructor. It is the responsibility of the customer to zero out the "unwrappedMasterKey" in their application after creation of the Keyring if it is no longer needed, in order to minimize the time the data key exists in plaintext in memory.

Out of scope:

Is there anything the solution will intentionally NOT address?

@lavaleri lavaleri added the bug Something isn't working label Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant