c - 清除 OpenSSL secret 的正确方法是什么?

标签 c security openssl

我在代码中经常使用OpenSSL资源:RSA、EC_KEY、EVP_PPKEY等。我知道有用于创建和删除它们的指定函数:

RSA_new()
RSA_free(RSA*)

但是,这些功能是否足以确保 secret 不会保留在内存中 - 例如内存被删除/归零 - 如果,比如说,攻击者会扫描进来?

换句话说,OpenSSL 从内存中删除 secret 的正确方法是什么?

(任何文档链接都很棒,我正在阅读源代码,但官方声明会有所帮助)

最佳答案

In other words, what is the proper way in OpenSSL to remove secrets from memory?

OPENSSL_cleanse

$ cd openssl-1.0.2a
$ grep -R OPENSSL_cleanse *
...
apps/apps.c:    OPENSSL_cleanse(buff, (unsigned int)bufsiz);
apps/apps.c:    OPENSSL_cleanse(buf, (unsigned int)bufsiz);
apps/apps.c:    OPENSSL_cleanse(buf, (unsigned int)bufsiz);
apps/ca.c:    OPENSSL_cleanse(key, strlen(key));
apps/dgst.c:    OPENSSL_cleanse(buf, BUFSIZE);
apps/enc.c:    OPENSSL_cleanse(str, SIZE);
apps/enc.c:    OPENSSL_cleanse(str, strlen(str));
...

据我所知,所有 *_free 函数在删除对象时(需要时)都在内部使用它。

不过,我认为 OpenSSL 不使用换行。为 key 包装或 secret 包装存储 key 是无人值守 key 存储问题。这是一个没有解决方案的问题。参见格特曼的 Engineering Security了解详情。

相关:Why does OPENSSL_cleanse look so complex and thread-unsafe?Secure memory block in openssl .

关于c - 清除 OpenSSL secret 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30234787/

相关文章:

c - Getopt 和 Optarg

java - 从 Javascript 调用的 Applet 方法

python - 安全地存储密码以在 python 脚本中使用

不能对 'double' 数字进行乘法运算

c++ - 计算中常用值的预定义 - 它会改变什么吗?

linux - 删除 .htpasswd 密码保护 .(Nginx)

java - 如何使用 EVP_Sign 函数计算签名

c - OpenSSL RSA-2048 未加密 block 比应有的长度长

由于 openldap 和 openssl makefile 错误,iOS 应用存档失败

c - 如何将元素移动到 c 中动态分配的 char ** 指针的右侧?我在正确的轨道上吗?