gpt4 book ai didi

javascript - Node : AWS KMS erasing public key from memory

转载 作者:行者123 更新时间:2023-12-01 00:35:23 25 4
gpt4 key购买 nike

来自 KMS 操作的文档 GenerateDataKey https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html

We recommend that you use the following pattern to encrypt data locally in your application:

Use the GenerateDataKey operation to get a data encryption key.

Use the plaintext data key (returned in the Plaintext field of the response) to encrypt data locally, then erase the plaintext data key from memory.

此代码是否足以确保明文 key 在使用完毕后已从内存中删除。

const aws = require("aws-sdk");
const kms = new aws.KMS({...config});

(async () => {

/** {Plaintext: Buffer, CiphertextBlob: Buffer} **/
let dataKey = await kms.generateDataKey({...options}).promise();

let encryptedString = MyEncryptionFunction(dataKey.Plaintext, "Hello World");

dataKey.Plaintext.fill(0); //overwrite the buffer with zeroes to erase from memory;
})();

function MyEncryptionFunction(key, dataString) {
let iv = crypto.randomBytes(16);
let cipher = crypto.createCipheriv("aes256", key, iv);
return cipher.update(dataString, "utf8", "hex") + cipher.final("hex");
}

是否可以安全地假设 aws sdk 不会将 key 泄漏/复制到内存的其他部分,并且与内置加密库的 createCipheriv 函数相同,因此只需覆盖带有零的纯文本缓冲区应该足以从内存中删除 key ?

最佳答案

这就是适用于 JavaScript 的 AWS 加密开发工具包的作用 [1]。事实上,如果加密SDK提供了您需要的功能,我建议只使用它。

aws-sdk 将此值视为敏感值并在 Node.js[2] 中创建一个隔离的缓冲区。这意味着明文 key 的作用域为该函数只要它不分享它,没有其他副本,也没有人可以访问。(通常的“没有坏人可以对您的服务器进行根访问”适用)

跟踪 Node [3]..[4] 中的 createCipheriv 调用它提供了 openSSL key 的引用,而不是副本。

[1] https://github.com/aws/aws-encryption-sdk-javascript/blob/master/modules/material-management/src/cryptographic_material.ts#L343

[2] https://github.com/aws/aws-sdk-js/pull/2622/files

[3] https://github.com/nodejs/node/blob/master/lib/crypto.js#L114

[4] https://github.com/nodejs/node/blob/master/src/node_crypto.cc#L4099

关于javascript - Node : AWS KMS erasing public key from memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58177036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com