BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
openssl.cpp
Go to the documentation of this file.
1 #include <fc/crypto/openssl.hpp>
2 
3 #include <fc/filesystem.hpp>
4 
5 #include <boost/filesystem/path.hpp>
6 
7 #include <cstdlib>
8 #include <string>
9 #include <stdlib.h>
10 
11 namespace fc
12 {
14  {
16  {
17  static path orderindependentstorage;
18  return orderindependentstorage;
19  }
21  {
22  ERR_load_crypto_strings();
23  OpenSSL_add_all_algorithms();
24 
25  const boost::filesystem::path& boostPath = _configurationFilePath();
26  if(boostPath.empty() == false)
27  {
28  std::string varSetting("OPENSSL_CONF=");
30 #if defined(WIN32)
31  _putenv((char*)varSetting.c_str());
32 #else
33  putenv((char*)varSetting.c_str());
34 #endif
35  }
36 #if OPENSSL_VERSION_NUMBER < 0x10100000L
37  // no longer needed as of OpenSSL 1.1
38  // if special initialization is necessary in versions 1.1 and above,
39  // use OPENSSL_init_crypto
40  OPENSSL_config(nullptr);
41 #endif
42  }
43 
45  {
46 #if not defined(LIBRESSL_VERSION_NUMBER)
47  // No FIPS in LibreSSL.
48  // https://marc.info/?l=openbsd-misc&m=139819485423701&w=2
49  FIPS_mode_set(0);
50 #endif
51  CONF_modules_unload(1);
52  EVP_cleanup();
53  CRYPTO_cleanup_all_ex_data();
54  ERR_free_strings();
55  }
56  };
57 
58  void store_configuration_path(const path& filePath)
59  {
61  }
62 
64  {
65  static openssl_scope ossl;
66  return 0;
67  }
68 
69  #define SSL_TYPE_IMPL(name, ssl_type, free_func) \
70  name::name( ssl_type* obj ) : ssl_wrapper(obj) {} \
71  name::name( name&& move ) : ssl_wrapper( move.obj ) \
72  { \
73  move.obj = nullptr; \
74  } \
75  name::~name() \
76  { \
77  if( obj != nullptr ) \
78  free_func(obj); \
79  } \
80  name& name::operator=( name&& move ) \
81  { \
82  if( this != &move ) \
83  { \
84  if( obj != nullptr ) \
85  free_func(obj); \
86  obj = move.obj; \
87  move.obj = nullptr; \
88  } \
89  return *this; \
90  }
91 
92  SSL_TYPE_IMPL(ec_group, EC_GROUP, EC_GROUP_free)
93  SSL_TYPE_IMPL(ec_point, EC_POINT, EC_POINT_free)
94  SSL_TYPE_IMPL(ecdsa_sig, ECDSA_SIG, ECDSA_SIG_free)
95  SSL_TYPE_IMPL(bn_ctx, BN_CTX, BN_CTX_free)
96  SSL_TYPE_IMPL(evp_cipher_ctx, EVP_CIPHER_CTX, EVP_CIPHER_CTX_free )
97  SSL_TYPE_IMPL(ssl_dh, DH, DH_free)
98 }
SSL_TYPE_IMPL
#define SSL_TYPE_IMPL(name, ssl_type, free_func)
Definition: openssl.cpp:69
fc::openssl_scope::openssl_scope
openssl_scope()
Definition: openssl.cpp:20
openssl.hpp
fc
Definition: api.hpp:15
filesystem.hpp
fc::openssl_scope::_configurationFilePath
static path & _configurationFilePath()
Definition: openssl.cpp:15
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
fc::path::to_native_ansi_path
std::string to_native_ansi_path() const
Definition: filesystem.cpp:119
fc::init_openssl
int init_openssl()
Definition: openssl.cpp:63
fc::openssl_scope
Definition: openssl.cpp:13
fc::store_configuration_path
void store_configuration_path(const path &filePath)
Definition: openssl.cpp:58
fc::openssl_scope::~openssl_scope
~openssl_scope()
Definition: openssl.cpp:44