清除 OpenSSL 机密的正确方法是什么?
What is the proper way of clearing OpenSSL secrets?
在代码中我经常使用OpenSSL资源:RSA、EC_KEY、EVP_PPKEY等。我知道有指定的函数来创建和删除它们:
RSA_new()
RSA_free(RSA*)
但是,这些功能是否足以确保秘密不会保留在内存中 - 例如内存是 scrubbed/zeroed - 如果,比方说,攻击者会扫描?
换句话说,在 OpenSSL 中从内存中删除秘密的正确方法是什么?
(任何文档链接都很棒,我正在阅读源代码,但有点官方的声明会有所帮助)
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 使用换行。存储密钥包装或秘密包装的密钥是 无人值守密钥存储 问题。这是一个没有解决方案的问题。有关详细信息,请参阅 Guttman 的 Engineering Security。
相关:Why does OPENSSL_cleanse look so complex and thread-unsafe? and .
在代码中我经常使用OpenSSL资源:RSA、EC_KEY、EVP_PPKEY等。我知道有指定的函数来创建和删除它们:
RSA_new()
RSA_free(RSA*)
但是,这些功能是否足以确保秘密不会保留在内存中 - 例如内存是 scrubbed/zeroed - 如果,比方说,攻击者会扫描?
换句话说,在 OpenSSL 中从内存中删除秘密的正确方法是什么?
(任何文档链接都很棒,我正在阅读源代码,但有点官方的声明会有所帮助)
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 使用换行。存储密钥包装或秘密包装的密钥是 无人值守密钥存储 问题。这是一个没有解决方案的问题。有关详细信息,请参阅 Guttman 的 Engineering Security。
相关:Why does OPENSSL_cleanse look so complex and thread-unsafe? and