comparison Core/Toolbox.cpp @ 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 97a74f0eac7a
children e0476e8cb73d
comparison
equal deleted inserted replaced
2676:d2f70c8f8bfd 2677:0196d07a900f
60 60
61 #if ORTHANC_ENABLE_LOCALE == 1 61 #if ORTHANC_ENABLE_LOCALE == 1
62 # include <boost/locale.hpp> 62 # include <boost/locale.hpp>
63 #endif 63 #endif
64 64
65 #if ORTHANC_ENABLE_SSL == 1
66 // For OpenSSL initialization and finalization
67 # include <openssl/conf.h>
68 # include <openssl/engine.h>
69 # include <openssl/err.h>
70 # include <openssl/evp.h>
71 # include <openssl/ssl.h>
72 #endif
73
65 74
66 #if defined(_MSC_VER) && (_MSC_VER < 1800) 75 #if defined(_MSC_VER) && (_MSC_VER < 1800)
67 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013 76 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013
68 extern "C" 77 extern "C"
69 { 78 {
1419 void Toolbox::FinalizeGlobalLocale() 1428 void Toolbox::FinalizeGlobalLocale()
1420 { 1429 {
1421 globalLocale_.reset(); 1430 globalLocale_.reset();
1422 } 1431 }
1423 1432
1424 1433
1434 void Toolbox::InitializeOpenSsl()
1435 {
1436 #if ORTHANC_ENABLE_SSL == 1
1437 // https://wiki.openssl.org/index.php/Library_Initialization
1438 SSL_library_init();
1439 SSL_load_error_strings();
1440 OpenSSL_add_all_algorithms();
1441 ERR_load_crypto_strings();
1442 #endif
1443 }
1444
1445
1446 void Toolbox::FinalizeOpenSsl()
1447 {
1448 #if ORTHANC_ENABLE_SSL == 1
1449 // Finalize OpenSSL
1450 // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup
1451 #ifdef FIPS_mode_set
1452 FIPS_mode_set(0);
1453 #endif
1454 ENGINE_cleanup();
1455 CONF_modules_unload(1);
1456 EVP_cleanup();
1457 CRYPTO_cleanup_all_ex_data();
1458 ERR_remove_state(0);
1459 ERR_free_strings();
1460 #endif
1461 }
1462
1463
1425 std::string Toolbox::ToUpperCaseWithAccents(const std::string& source) 1464 std::string Toolbox::ToUpperCaseWithAccents(const std::string& source)
1426 { 1465 {
1427 if (globalLocale_.get() == NULL) 1466 if (globalLocale_.get() == NULL)
1428 { 1467 {
1429 LOG(ERROR) << "No global locale was set, call Toolbox::InitializeGlobalLocale()"; 1468 LOG(ERROR) << "No global locale was set, call Toolbox::InitializeGlobalLocale()";