From 3a073f6b62e84a3740143490f8fff3f738b78aef Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Tue, 19 May 2015 16:41:11 +0200 Subject: [PATCH] SW Backend initialization refactoring. Random initialization from CryptoService was moved to CKM::Crypto::SW::Internals namespace. Change-Id: I47ff24a9af908a9856158ec32a402e09d9b163b2 --- src/manager/crypto/sw-backend/crypto-service.cpp | 26 ------------------------ src/manager/crypto/sw-backend/crypto-service.h | 6 ------ src/manager/crypto/sw-backend/internals.h | 4 ++++ src/manager/crypto/sw-backend/store.cpp | 8 ++++++++ src/manager/crypto/sw-backend/store.h | 2 +- src/manager/main/key-manager-main.cpp | 6 ------ 6 files changed, 13 insertions(+), 39 deletions(-) diff --git a/src/manager/crypto/sw-backend/crypto-service.cpp b/src/manager/crypto/sw-backend/crypto-service.cpp index 9959cce..73b8029 100644 --- a/src/manager/crypto/sw-backend/crypto-service.cpp +++ b/src/manager/crypto/sw-backend/crypto-service.cpp @@ -38,32 +38,6 @@ CryptoService::CryptoService(){ CryptoService::~CryptoService(){ } -int CryptoService::initialize() { - int hw_rand_ret = 0; - int u_rand_ret = 0; - - // try to initialize using ERR_load_crypto_strings and OpenSSL_add_all_algorithms - ERR_load_crypto_strings(); - OpenSSL_add_all_algorithms(); - - // initialize entropy - std::ifstream ifile(DEV_HW_RANDOM_FILE); - if(ifile.is_open()) { - u_rand_ret= RAND_load_file(DEV_HW_RANDOM_FILE, 32); - } - if(u_rand_ret != 32 ){ - LogError("Error in HW_RAND file load"); - hw_rand_ret = RAND_load_file(DEV_URANDOM_FILE, 32); - - if(hw_rand_ret != 32) { - LogError("Error in U_RAND_file_load"); - ThrowMsg(CryptoService::Exception::Crypto_internal, "Error in U_RAND_file_load"); - } - } - - return CKM_CRYPTO_INIT_SUCCESS; -} - int CryptoService::createKeyPairRSA(const int size, // size in bits [1024, 2048, 4096] KeyImpl &createdPrivateKey, // returned value KeyImpl &createdPublicKey) // returned value diff --git a/src/manager/crypto/sw-backend/crypto-service.h b/src/manager/crypto/sw-backend/crypto-service.h index fb8ce4d..ca5b14b 100644 --- a/src/manager/crypto/sw-backend/crypto-service.h +++ b/src/manager/crypto/sw-backend/crypto-service.h @@ -46,12 +46,6 @@ public: DECLARE_EXCEPTION_TYPE(Base, opensslError); }; - // During initialization, FIPS_MODE and the antropy source are set. - // And system certificates are loaded in the memory during initialization. - // FIPS_MODE - ON, OFF(Default) - // antropy source - /dev/random,/dev/urandom(Default) - static int initialize(); - static int createKeyPairRSA(const int size, // size in bits [1024, 2048, 4096] KeyImpl &createdPrivateKey, // returned value ==> Key &createdPrivateKey, KeyImpl &createdPublicKey); // returned value ==> Key &createdPublicKey diff --git a/src/manager/crypto/sw-backend/internals.h b/src/manager/crypto/sw-backend/internals.h index 49ce47f..a53b3b4 100644 --- a/src/manager/crypto/sw-backend/internals.h +++ b/src/manager/crypto/sw-backend/internals.h @@ -38,6 +38,10 @@ namespace Crypto { namespace SW { namespace Internals { +// During initialization, FIPS_MODE and the entropy source are set +// and system certificates are loaded to memory. +// FIPS_MODE - ON, OFF(Default) +// entropy source - /dev/random,/dev/urandom(Default) int initialize(); void createKeyPairRSA(const int size, diff --git a/src/manager/crypto/sw-backend/store.cpp b/src/manager/crypto/sw-backend/store.cpp index 24d890d..2b59a53 100644 --- a/src/manager/crypto/sw-backend/store.cpp +++ b/src/manager/crypto/sw-backend/store.cpp @@ -25,11 +25,19 @@ #include #include #include +#include namespace CKM { namespace Crypto { namespace SW { +Store::Store(CryptoBackend backendId) + : GStore(backendId) +{ + // initialize openssl internals + Internals::initialize(); +} + GKeyShPtr Store::getKey(const Token &token) { if (token.backendId != m_backendId) { LogError("Decider choose wrong backend!"); diff --git a/src/manager/crypto/sw-backend/store.h b/src/manager/crypto/sw-backend/store.h index dc7a78c..0eb86cc 100644 --- a/src/manager/crypto/sw-backend/store.h +++ b/src/manager/crypto/sw-backend/store.h @@ -29,7 +29,7 @@ namespace SW { class Store : public GStore { public: - explicit Store(CryptoBackend backendId) : GStore(backendId) {} + explicit Store(CryptoBackend backendId); virtual GKeyShPtr getKey(const Token &token); virtual Token import(DataType dataType, const RawBuffer &buffer); diff --git a/src/manager/main/key-manager-main.cpp b/src/manager/main/key-manager-main.cpp index 5e17a3a..a6af572 100644 --- a/src/manager/main/key-manager-main.cpp +++ b/src/manager/main/key-manager-main.cpp @@ -38,9 +38,6 @@ #include #include -/* TODO remove this include */ -#include - #define REGISTER_SOCKET_SERVICE(manager, service) \ registerSocketService(manager, #service) @@ -97,9 +94,6 @@ int main(void) { CKM::KeyProvider::initializeLibrary(); - /* ToDO remove it */ - CKM::Crypto::SW::CryptoService::initialize(); - { LogInfo("Start!"); CKM::SocketManager manager; -- 2.7.4