From 3c39dc62f2757e8edf55cf792f559b30a2558d48 Mon Sep 17 00:00:00 2001 From: Konrad Lipinski Date: Wed, 5 Jun 2019 14:41:20 +0200 Subject: [PATCH] Turn backends into Decider members Change-Id: If42fff63e2946f299cac23e81d2edb4b663db644 --- src/manager/crypto/platform/decider.cpp | 18 ++++++++---------- src/manager/crypto/platform/decider.h | 27 ++++++++++++++++----------- src/manager/service/ckm-logic.cpp | 4 ++-- src/manager/service/ckm-logic.h | 4 ++-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/manager/crypto/platform/decider.cpp b/src/manager/crypto/platform/decider.cpp index 4ffe83a..9540509 100644 --- a/src/manager/crypto/platform/decider.cpp +++ b/src/manager/crypto/platform/decider.cpp @@ -26,10 +26,8 @@ #include #include -#include #ifdef TZ_BACKEND_ENABLED -#include #include #include @@ -122,27 +120,27 @@ CryptoBackend chooseCryptoBackend(const DataParams& params) } // namespace Decider::Decider() - : m_swStore(new SW::Store(CryptoBackend::OpenSSL)) + : m_swStore(CryptoBackend::OpenSSL) #ifdef TZ_BACKEND_ENABLED - , m_tzStore(new TZ::Store(CryptoBackend::TrustZone)) + , m_tzStore(CryptoBackend::TrustZone) #endif { } -GStore &Decider::getStore(const Token &token) const +GStore &Decider::getStore(const Token &token) { return getStore(token.backendId); }; -GStore &Decider::getStore(CryptoBackend cryptoBackend) const +GStore &Decider::getStore(CryptoBackend cryptoBackend) { GStore *gStore = NULL; if (cryptoBackend == CryptoBackend::OpenSSL) - gStore = m_swStore.get(); + gStore = &m_swStore; #ifdef TZ_BACKEND_ENABLED if (cryptoBackend == CryptoBackend::TrustZone) - gStore = m_tzStore.get(); + gStore = &m_tzStore; #endif if (gStore) return *gStore; @@ -151,7 +149,7 @@ GStore &Decider::getStore(CryptoBackend cryptoBackend) const "Backend not available. BackendId: ", (int)cryptoBackend); } -GStore &Decider::getStore(DataType data, const Policy &policy, bool encrypted) const +GStore &Decider::getStore(DataType data, const Policy &policy, bool encrypted) { DataParams params{ DataParam(data, policy, encrypted) @@ -160,7 +158,7 @@ GStore &Decider::getStore(DataType data, const Policy &policy, bool encrypted) c return getStore(chooseCryptoBackend(params)); } -GStore &Decider::getStore(const DataParams& params) const +GStore &Decider::getStore(const DataParams& params) { return getStore(chooseCryptoBackend(params)); } diff --git a/src/manager/crypto/platform/decider.h b/src/manager/crypto/platform/decider.h index 14d1071..59bc9ef 100644 --- a/src/manager/crypto/platform/decider.h +++ b/src/manager/crypto/platform/decider.h @@ -20,7 +20,6 @@ */ #pragma once -#include #include #include @@ -28,6 +27,12 @@ #include #include + +#include +#ifdef TZ_BACKEND_ENABLED +#include +#endif + #include namespace CKM { @@ -49,20 +54,20 @@ struct DataParam { using DataParams = std::vector; -class Decider { +class Decider final { public: Decider(); - GStore &getStore(const Token &token) const; - GStore &getStore(DataType data, const Policy &policy, bool encrypted = false) const; - GStore &getStore(const DataParams& params) const; - - virtual ~Decider() {} + GStore &getStore(const Token &token); + GStore &getStore(DataType data, const Policy &policy, bool encrypted = false); + GStore &getStore(const DataParams& params); -protected: - GStore &getStore(CryptoBackend id) const; +private: + GStore &getStore(CryptoBackend id); - std::unique_ptr m_swStore; - std::unique_ptr m_tzStore; + SW::Store m_swStore; +#ifdef TZ_BACKEND_ENABLED + TZ::Store m_tzStore; +#endif }; } // Crypto diff --git a/src/manager/service/ckm-logic.cpp b/src/manager/service/ckm-logic.cpp index aedf064..5616b7e 100644 --- a/src/manager/service/ckm-logic.cpp +++ b/src/manager/service/ckm-logic.cpp @@ -408,7 +408,7 @@ DB::Row CKMLogic::createEncryptedRow( const Name &name, const ClientId &owner, const Crypto::Data &data, - const Policy &policy) const + const Policy &policy) { Crypto::GStore &store = m_decider.getStore(data.type, policy); @@ -538,7 +538,7 @@ int CKMLogic::extractPKCS12Data( const PKCS12Serializable &pkcs, const PolicySerializable &keyPolicy, const PolicySerializable &certPolicy, - DB::RowVector &output) const + DB::RowVector &output) { // private key is mandatory auto key = pkcs.getKey(); diff --git a/src/manager/service/ckm-logic.h b/src/manager/service/ckm-logic.h index 8a849f8..67c6519 100644 --- a/src/manager/service/ckm-logic.h +++ b/src/manager/service/ckm-logic.h @@ -270,7 +270,7 @@ private: const Name &name, const ClientId &owner, const Crypto::Data &data, - const Policy &policy) const; + const Policy &policy); int getPKCS12Helper( const Credentials &cred, @@ -289,7 +289,7 @@ private: const PKCS12Serializable &pkcs, const PolicySerializable &keyPolicy, const PolicySerializable &certPolicy, - DB::RowVector &output) const; + DB::RowVector &output); int removeDataHelper( const Credentials &cred, -- 2.7.4