SW Backend initialization refactoring. 11/39611/3
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Tue, 19 May 2015 14:41:11 +0000 (16:41 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 20 May 2015 05:15:28 +0000 (07:15 +0200)
Random initialization from CryptoService was moved to
CKM::Crypto::SW::Internals namespace.

Change-Id: I47ff24a9af908a9856158ec32a402e09d9b163b2

src/manager/crypto/sw-backend/crypto-service.cpp
src/manager/crypto/sw-backend/crypto-service.h
src/manager/crypto/sw-backend/internals.h
src/manager/crypto/sw-backend/store.cpp
src/manager/crypto/sw-backend/store.h
src/manager/main/key-manager-main.cpp

index 9959cce..73b8029 100644 (file)
@@ -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
index fb8ce4d..ca5b14b 100644 (file)
@@ -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
index 49ce47f..a53b3b4 100644 (file)
@@ -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,
index 24d890d..2b59a53 100644 (file)
 #include <generic-backend/exception.h>
 #include <sw-backend/key.h>
 #include <sw-backend/store.h>
+#include <sw-backend/internals.h>
 
 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!");
index dc7a78c..0eb86cc 100644 (file)
@@ -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);
index 5e17a3a..a6af572 100644 (file)
@@ -38,9 +38,6 @@
 #include <key-provider.h>
 #include <file-system.h>
 
-/* TODO remove this include */
-#include <sw-backend/crypto-service.h>
-
 #define REGISTER_SOCKET_SERVICE(manager, service) \
     registerSocketService<service>(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;