2013-08-13 16:58:55 +00:00
|
|
|
#include <fc/crypto/openssl.hpp>
|
2014-06-02 15:31:28 +00:00
|
|
|
|
|
|
|
|
#include <fc/filesystem.hpp>
|
|
|
|
|
|
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
|
2014-06-03 15:03:28 +00:00
|
|
|
#include <cstdlib>
|
2014-06-02 15:31:28 +00:00
|
|
|
#include <string>
|
2014-06-03 15:16:29 +00:00
|
|
|
#include <stdlib.h>
|
2014-06-02 15:31:28 +00:00
|
|
|
|
2013-08-13 16:58:55 +00:00
|
|
|
namespace fc
|
|
|
|
|
{
|
|
|
|
|
struct openssl_scope
|
|
|
|
|
{
|
2014-06-03 15:16:29 +00:00
|
|
|
static path _configurationFilePath;
|
2013-08-13 16:58:55 +00:00
|
|
|
openssl_scope()
|
|
|
|
|
{
|
|
|
|
|
ERR_load_crypto_strings();
|
|
|
|
|
OpenSSL_add_all_algorithms();
|
2014-06-03 15:03:28 +00:00
|
|
|
|
2014-06-02 15:31:28 +00:00
|
|
|
const boost::filesystem::path& boostPath = _configurationFilePath;
|
2014-06-03 15:03:28 +00:00
|
|
|
if(boostPath.empty() == false)
|
2014-06-03 15:16:29 +00:00
|
|
|
{
|
2014-06-05 08:00:50 +00:00
|
|
|
std::string varSetting("OPENSSL_CONF=");
|
|
|
|
|
varSetting += _configurationFilePath.to_native_ansi_path();
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
|
_putenv((char*)varSetting.c_str());
|
|
|
|
|
#else
|
|
|
|
|
putenv((char*)varSetting.c_str());
|
|
|
|
|
#endif
|
2014-06-03 15:16:29 +00:00
|
|
|
}
|
2018-10-22 12:38:08 +00:00
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
|
|
|
// no longer needed as of OpenSSL 1.1
|
|
|
|
|
// if special initialization is necessary in versions 1.1 and above,
|
|
|
|
|
// use OPENSSL_init_crypto
|
2014-06-03 15:03:28 +00:00
|
|
|
OPENSSL_config(nullptr);
|
2018-10-22 12:38:08 +00:00
|
|
|
#endif
|
2013-08-13 16:58:55 +00:00
|
|
|
}
|
2014-06-02 15:31:28 +00:00
|
|
|
|
2013-08-13 16:58:55 +00:00
|
|
|
~openssl_scope()
|
|
|
|
|
{
|
|
|
|
|
EVP_cleanup();
|
|
|
|
|
ERR_free_strings();
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-06-02 15:31:28 +00:00
|
|
|
|
|
|
|
|
path openssl_scope::_configurationFilePath;
|
|
|
|
|
|
|
|
|
|
void store_configuration_path(const path& filePath)
|
2014-06-03 15:16:29 +00:00
|
|
|
{
|
2014-06-02 15:31:28 +00:00
|
|
|
openssl_scope::_configurationFilePath = filePath;
|
2014-06-03 15:16:29 +00:00
|
|
|
}
|
2013-08-13 16:58:55 +00:00
|
|
|
|
|
|
|
|
int init_openssl()
|
|
|
|
|
{
|
2014-07-22 22:18:09 +00:00
|
|
|
static openssl_scope ossl;
|
|
|
|
|
return 0;
|
2013-08-13 16:58:55 +00:00
|
|
|
}
|
|
|
|
|
}
|