OpenSSL 更新到较新版本:已弃用的 `OPENSSL_config` 的替代方案
OpenSSL update into newer version: Alternative for the deprecated `OPENSSL_config`
在我的 C 项目中,我将 OpenSSl 库 1.0.2g 更新为较新的版本(1.1.x 版本),同时我在编译代码时抛出了以下警告:
main.c:40:3: warning: ‘OPENSSL_config’ is deprecated [-Wdeprecated-declarations]
OPENSSL_config(NULL);
抛出此错误的代码是:
#include <stdio.h>
// Openssl
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
int main(int argc, char *argv[]) {
/* Load the human readable error strings for libcrypto */
ERR_load_crypto_strings();
/* Load all digest and cipher algorithms */
OpenSSL_add_all_algorithms();
/* Load config file, and other important initialisation */
OPENSSL_config(NULL);
//Come code here
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
return 0;
}
因此,根据最佳实践的规定,我应该避免并在我的案例中对已弃用的函数使用替代方法,我应该使用哪种方法?
OPENSSL_config 说明了一切:
This function is deprecated and its use should be avoided.
Applications should instead call CONF_modules_load() during
initialization (that is before starting any threads).
另外 SSL_load_error_strings and OpenSSL_add_all_algorithms 也已弃用。
对于 openssl >= 1.1,您可以删除上面的整个启动和清理代码,因为不再需要它了。现在都自动为您完成了。
在我的 C 项目中,我将 OpenSSl 库 1.0.2g 更新为较新的版本(1.1.x 版本),同时我在编译代码时抛出了以下警告:
main.c:40:3: warning: ‘OPENSSL_config’ is deprecated [-Wdeprecated-declarations] OPENSSL_config(NULL);
抛出此错误的代码是:
#include <stdio.h>
// Openssl
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
int main(int argc, char *argv[]) {
/* Load the human readable error strings for libcrypto */
ERR_load_crypto_strings();
/* Load all digest and cipher algorithms */
OpenSSL_add_all_algorithms();
/* Load config file, and other important initialisation */
OPENSSL_config(NULL);
//Come code here
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
return 0;
}
因此,根据最佳实践的规定,我应该避免并在我的案例中对已弃用的函数使用替代方法,我应该使用哪种方法?
OPENSSL_config 说明了一切:
This function is deprecated and its use should be avoided. Applications should instead call CONF_modules_load() during initialization (that is before starting any threads).
另外 SSL_load_error_strings and OpenSSL_add_all_algorithms 也已弃用。
对于 openssl >= 1.1,您可以删除上面的整个启动和清理代码,因为不再需要它了。现在都自动为您完成了。