changeset 2677:0196d07a900f jobs

migrate OpenSSL initialization to Toolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 15 Jun 2018 11:16:37 +0200
parents d2f70c8f8bfd
children e0476e8cb73d
files Core/HttpClient.cpp Core/HttpClient.h Core/Toolbox.cpp Core/Toolbox.h OrthancServer/OrthancInitialization.cpp
diffstat 5 files changed, 46 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpClient.cpp	Tue Jun 12 16:22:07 2018 +0200
+++ b/Core/HttpClient.cpp	Fri Jun 15 11:16:37 2018 +0200
@@ -46,16 +46,6 @@
 #include <boost/thread/mutex.hpp>
 
 
-#if ORTHANC_ENABLE_SSL == 1
-// For OpenSSL initialization and finalization
-#  include <openssl/conf.h>
-#  include <openssl/engine.h>
-#  include <openssl/err.h>
-#  include <openssl/evp.h>
-#  include <openssl/ssl.h>
-#endif
-
-
 #if ORTHANC_ENABLE_PKCS11 == 1
 #  include "Pkcs11.h"
 #endif
@@ -812,34 +802,4 @@
     throw OrthancException(ErrorCode_InternalError);
 #endif
   }
-
-
-  void HttpClient::InitializeOpenSsl()
-  {
-#if ORTHANC_ENABLE_SSL == 1
-    // https://wiki.openssl.org/index.php/Library_Initialization
-    SSL_library_init();
-    SSL_load_error_strings();
-    OpenSSL_add_all_algorithms();
-    ERR_load_crypto_strings();
-#endif
-  }
-
-
-  void HttpClient::FinalizeOpenSsl()
-  {
-#if ORTHANC_ENABLE_SSL == 1
-    // Finalize OpenSSL
-    // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup
-#ifdef FIPS_mode_set
-    FIPS_mode_set(0);
-#endif
-    ENGINE_cleanup();
-    CONF_modules_unload(1);
-    EVP_cleanup();
-    CRYPTO_cleanup_all_ex_data();
-    ERR_remove_state(0);
-    ERR_free_strings();
-#endif
-  }
 }
--- a/Core/HttpClient.h	Tue Jun 12 16:22:07 2018 +0200
+++ b/Core/HttpClient.h	Fri Jun 15 11:16:37 2018 +0200
@@ -268,10 +268,6 @@
   
     static void GlobalFinalize();
 
-    static void InitializeOpenSsl();
-
-    static void FinalizeOpenSsl();
-
     static void InitializePkcs11(const std::string& module,
                                  const std::string& pin,
                                  bool verbose);
--- a/Core/Toolbox.cpp	Tue Jun 12 16:22:07 2018 +0200
+++ b/Core/Toolbox.cpp	Fri Jun 15 11:16:37 2018 +0200
@@ -62,6 +62,15 @@
 #  include <boost/locale.hpp>
 #endif
 
+#if ORTHANC_ENABLE_SSL == 1
+// For OpenSSL initialization and finalization
+#  include <openssl/conf.h>
+#  include <openssl/engine.h>
+#  include <openssl/err.h>
+#  include <openssl/evp.h>
+#  include <openssl/ssl.h>
+#endif
+
 
 #if defined(_MSC_VER) && (_MSC_VER < 1800)
 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013
@@ -1421,7 +1430,37 @@
     globalLocale_.reset();
   }
 
-  
+
+  void Toolbox::InitializeOpenSsl()
+  {
+#if ORTHANC_ENABLE_SSL == 1
+    // https://wiki.openssl.org/index.php/Library_Initialization
+    SSL_library_init();
+    SSL_load_error_strings();
+    OpenSSL_add_all_algorithms();
+    ERR_load_crypto_strings();
+#endif
+  }
+
+
+  void Toolbox::FinalizeOpenSsl()
+  {
+#if ORTHANC_ENABLE_SSL == 1
+    // Finalize OpenSSL
+    // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup
+#ifdef FIPS_mode_set
+    FIPS_mode_set(0);
+#endif
+    ENGINE_cleanup();
+    CONF_modules_unload(1);
+    EVP_cleanup();
+    CRYPTO_cleanup_all_ex_data();
+    ERR_remove_state(0);
+    ERR_free_strings();
+#endif
+  }
+
+
   std::string Toolbox::ToUpperCaseWithAccents(const std::string& source)
   {
     if (globalLocale_.get() == NULL)
--- a/Core/Toolbox.h	Tue Jun 12 16:22:07 2018 +0200
+++ b/Core/Toolbox.h	Fri Jun 15 11:16:37 2018 +0200
@@ -233,6 +233,10 @@
     std::string ToUpperCaseWithAccents(const std::string& source);
 #endif
 
+    void InitializeOpenSsl();
+    
+    void FinalizeOpenSsl();
+
     std::string GenerateUuid();
   }
 }
--- a/OrthancServer/OrthancInitialization.cpp	Tue Jun 12 16:22:07 2018 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Fri Jun 15 11:16:37 2018 +0200
@@ -458,7 +458,7 @@
   {
     boost::recursive_mutex::scoped_lock lock(globalMutex_);
 
-    HttpClient::InitializeOpenSsl();
+    Toolbox::InitializeOpenSsl();
 
     InitializeServerEnumerations();
 
@@ -514,7 +514,7 @@
     boost::recursive_mutex::scoped_lock lock(globalMutex_);
     HttpClient::GlobalFinalize();
     FromDcmtkBridge::FinalizeCodecs();
-    HttpClient::FinalizeOpenSsl();
+    Toolbox::FinalizeOpenSsl();
     Toolbox::FinalizeGlobalLocale();
   }