我在代码中经常使用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/