Class naming scheme re-factoring: move towards better consistency. 78/27678/1 accepted/tizen/common/20140925.172038 submit/tizen/20140925.122603
authorMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Wed, 17 Sep 2014 11:34:14 +0000 (13:34 +0200)
committerMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Wed, 17 Sep 2014 11:34:14 +0000 (13:34 +0200)
Change-Id: I8ad4d19991c92f5268ef1f0a411258c848c83c64

12 files changed:
src/CMakeLists.txt
src/manager/CMakeLists.txt
src/manager/client/client-manager-impl.cpp
src/manager/common/certificate-impl.cpp
src/manager/common/certificate-impl.h
src/manager/common/key-impl.cpp [moved from src/manager/common/generic-key.cpp with 89% similarity]
src/manager/common/key-impl.h [moved from src/manager/common/generic-key.h with 84% similarity]
src/manager/common/pkcs12-impl.cpp
src/manager/service/CryptoService.cpp
src/manager/service/CryptoService.h
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-logic.h

index bb2d60a..fdcc3aa 100644 (file)
@@ -89,7 +89,7 @@ SET(KEY_MANAGER_CLIENT_SOURCES
     ${KEY_MANAGER_PATH}/common/smack-check.cpp
     ${KEY_MANAGER_PATH}/common/certificate-impl.cpp
     ${KEY_MANAGER_PATH}/common/certificate-store.cpp
-    ${KEY_MANAGER_PATH}/common/generic-key.cpp
+    ${KEY_MANAGER_PATH}/common/key-impl.cpp
     ${KEY_MANAGER_PATH}/common/pkcs12-impl.cpp
     ${KEY_MANAGER_PATH}/dpl/log/src/abstract_log_provider.cpp
     ${KEY_MANAGER_PATH}/dpl/log/src/dlog_log_provider.cpp
@@ -148,7 +148,7 @@ SET(KEY_MANAGER_CONTROL_CLIENT_SOURCES
     ${KEY_MANAGER_PATH}/common/smack-check.cpp
     ${KEY_MANAGER_PATH}/common/certificate-impl.cpp
     ${KEY_MANAGER_PATH}/common/certificate-store.cpp
-    ${KEY_MANAGER_PATH}/common/generic-key.cpp
+    ${KEY_MANAGER_PATH}/common/key-impl.cpp
     ${KEY_MANAGER_PATH}/dpl/log/src/abstract_log_provider.cpp
     ${KEY_MANAGER_PATH}/dpl/log/src/dlog_log_provider.cpp
     ${KEY_MANAGER_PATH}/dpl/log/src/log.cpp
index f5e2330..5dfbc78 100644 (file)
@@ -20,7 +20,7 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/common/smack-check.cpp
     ${COMMON_PATH}/common/certificate-impl.cpp
     ${COMMON_PATH}/common/certificate-store.cpp
-    ${COMMON_PATH}/common/generic-key.cpp
+    ${COMMON_PATH}/common/key-impl.cpp
     ${COMMON_PATH}/dpl/log/src/abstract_log_provider.cpp
     ${COMMON_PATH}/dpl/log/src/dlog_log_provider.cpp
     ${COMMON_PATH}/dpl/log/src/log.cpp
index a838b8a..6e82722 100644 (file)
@@ -27,7 +27,7 @@
 #include <client-common.h>
 #include <message-buffer.h>
 #include <protocols.h>
-#include <generic-key.h>
+#include <key-impl.h>
 #include <certificate-impl.h>
 
 namespace {
@@ -231,7 +231,7 @@ int ManagerImpl::getKey(const Alias &alias, const Password &password, KeyShPtr &
     if (retCode != CKM_API_SUCCESS)
         return retCode;
 
-    KeyShPtr keyParsed(new GenericKey(rawData));
+    KeyShPtr keyParsed(new KeyImpl(rawData));
 
     if (keyParsed->empty()) {
         LogDebug("Key empty - failed to parse!");
index f8adbf3..51af437 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <dpl/log/log.h>
 
-#include <generic-key.h>
+#include <key-impl.h>
 #include <certificate-impl.h>
 #include <base64.h>
 
@@ -129,18 +129,18 @@ bool CertificateImpl::empty() const {
     return m_x509 == NULL;
 }
 
-GenericKey::EvpShPtr CertificateImpl::getEvpShPtr() const {
-    return GenericKey::EvpShPtr(X509_get_pubkey(m_x509), EVP_PKEY_free);
+KeyImpl::EvpShPtr CertificateImpl::getEvpShPtr() const {
+    return KeyImpl::EvpShPtr(X509_get_pubkey(m_x509), EVP_PKEY_free);
 }
 
-GenericKey CertificateImpl::getGenericKey() const {
-    GenericKey::EvpShPtr evp(X509_get_pubkey(m_x509), EVP_PKEY_free);
+KeyImpl CertificateImpl::getKeyImpl() const {
+    KeyImpl::EvpShPtr evp(X509_get_pubkey(m_x509), EVP_PKEY_free);
     if (EVP_PKEY_type(evp->type) == EVP_PKEY_RSA)
-        return GenericKey(evp, KeyType::KEY_RSA_PUBLIC);
+        return KeyImpl(evp, KeyType::KEY_RSA_PUBLIC);
     if (EVP_PKEY_type(evp->type) == EVP_PKEY_EC)
-        return GenericKey(evp, KeyType::KEY_ECDSA_PUBLIC);
+        return KeyImpl(evp, KeyType::KEY_ECDSA_PUBLIC);
     LogError("Unsupported key type in certificate.");
-    return GenericKey();
+    return KeyImpl();
 }
 
 X509_NAME *getX509Name(X509 *x509, CertificateFieldId type) {
index 62ebfbb..679de86 100644 (file)
@@ -26,7 +26,7 @@
 #include <ckm/ckm-type.h>
 #include <ckm/ckm-certificate.h>
 
-#include <generic-key.h>
+#include <key-impl.h>
 
 namespace CKM {
 
@@ -44,8 +44,8 @@ public:
     virtual bool empty() const;
     virtual X509* getX509() const;
 
-    GenericKey::EvpShPtr getEvpShPtr() const;
-    GenericKey getGenericKey() const;
+    KeyImpl::EvpShPtr getEvpShPtr() const;
+    KeyImpl getKeyImpl() const;
 
     std::string getOneLine(CertificateFieldId type) const;
     std::string getField(CertificateFieldId type, int fieldNid) const;
similarity index 89%
rename from src/manager/common/generic-key.cpp
rename to src/manager/common/key-impl.cpp
index 6835b8e..ceb6ef0 100644 (file)
@@ -13,7 +13,7 @@
  *  limitations under the License
  *
  *
- * @file        generic-key.cpp
+ * @file        key-impl.cpp
  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
  * @version     1.0
  * @brief       Key implementation.
@@ -33,7 +33,7 @@
 #include <dpl/log/log.h>
 
 #include <ckm/ckm-type.h>
-#include <generic-key.h>
+#include <key-impl.h>
 
 namespace CKM {
 namespace {
@@ -88,17 +88,17 @@ CKM::RawBuffer i2d(I2D_CONV fun, EVP_PKEY* pkey) {
 
 } // anonymous namespace
 
-GenericKey::GenericKey()
+KeyImpl::KeyImpl()
   : m_pkey(NULL, EVP_PKEY_free)
   , m_type(KeyType::KEY_NONE)
 {}
 
-GenericKey::GenericKey(const GenericKey &second) {
+KeyImpl::KeyImpl(const KeyImpl &second) {
     m_pkey = second.m_pkey;
     m_type = second.m_type;
 }
 
-GenericKey::GenericKey(const RawBuffer &buf, const Password &password)
+KeyImpl::KeyImpl(const RawBuffer &buf, const Password &password)
   : m_pkey(NULL, EVP_PKEY_free)
   , m_type(KeyType::KEY_NONE)
 {
@@ -159,7 +159,7 @@ GenericKey::GenericKey(const RawBuffer &buf, const Password &password)
     LogDebug("KeyType is: " << (int)m_type << " isPrivate: " << isPrivate);
 }
 
-GenericKey::GenericKey(EvpShPtr pkey, KeyType type)
+KeyImpl::KeyImpl(EvpShPtr pkey, KeyType type)
   : m_pkey(pkey)
   , m_type(type)
 {
@@ -175,27 +175,27 @@ GenericKey::GenericKey(EvpShPtr pkey, KeyType type)
         }
 }
 
-bool GenericKey::empty() const {
+bool KeyImpl::empty() const {
     return m_pkey.get() == NULL;
 }
 
-GenericKey::EvpShPtr GenericKey::getEvpShPtr() const {
+KeyImpl::EvpShPtr KeyImpl::getEvpShPtr() const {
     return m_pkey;
 }
 
-KeyType GenericKey::getType() const {
+KeyType KeyImpl::getType() const {
     return m_type;
 }
 
-RawBuffer GenericKey::getDERPRV() const {
+RawBuffer KeyImpl::getDERPRV() const {
     return i2d(i2d_PrivateKey_bio, m_pkey.get());
 }
 
-RawBuffer GenericKey::getDERPUB() const {
+RawBuffer KeyImpl::getDERPUB() const {
     return i2d(i2d_PUBKEY_bio, m_pkey.get());
 }
 
-RawBuffer GenericKey::getDER() const {
+RawBuffer KeyImpl::getDER() const {
     if (m_type == KeyType::KEY_ECDSA_PRIVATE || m_type == KeyType::KEY_RSA_PRIVATE) {
         return getDERPRV();
     } else if (m_type == KeyType::KEY_RSA_PUBLIC || m_type == KeyType::KEY_ECDSA_PUBLIC) {
@@ -206,14 +206,14 @@ RawBuffer GenericKey::getDER() const {
 
 KeyShPtr Key::create(const RawBuffer &raw, const Password &password) {
     try {
-        KeyShPtr output = std::make_shared<GenericKey>(raw, password);
+        KeyShPtr output = std::make_shared<KeyImpl>(raw, password);
         if (output->empty())
             output.reset();
         return output;
     } catch (const std::bad_alloc &) {
-        LogDebug("Bad alloc was catch during GenericKey creation");
+        LogDebug("Bad alloc was catch during KeyImpl creation");
     } catch (...) {
-        LogError("Critical error: Unknown exception was caught during GenericKey creation");
+        LogError("Critical error: Unknown exception was caught during KeyImpl creation");
     }
     return KeyShPtr();
 }
similarity index 84%
rename from src/manager/common/generic-key.h
rename to src/manager/common/key-impl.h
index ac1918c..9d7831a 100644 (file)
@@ -13,7 +13,7 @@
  *  limitations under the License
  *
  *
- * @file        generic-key.h
+ * @file        key-impl.h
  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
  * @version     1.0
  * @brief       Key implementation.
 
 namespace CKM {
 
-class GenericKey : public Key {
+class KeyImpl : public Key {
 public:
     typedef std::shared_ptr<EVP_PKEY> EvpShPtr;
 
-    GenericKey();
-    GenericKey(const GenericKey &second);
-    GenericKey(const RawBuffer& buffer, const Password &password = Password());
-    GenericKey(EvpShPtr pkey, KeyType type);
+    KeyImpl();
+    KeyImpl(const KeyImpl &second);
+    KeyImpl(const RawBuffer& buffer, const Password &password = Password());
+    KeyImpl(EvpShPtr pkey, KeyType type);
 
     virtual KeyType getType() const;
     virtual RawBuffer getDER() const;
@@ -52,7 +52,7 @@ public:
     }
 
     virtual bool empty() const;
-    virtual ~GenericKey(){}
+    virtual ~KeyImpl(){}
 protected:
     EvpShPtr m_pkey;
     KeyType m_type;
index 255a752..394b649 100644 (file)
@@ -28,7 +28,7 @@
 #include <pkcs12-impl.h>
 
 #include <certificate-impl.h>
-#include <generic-key.h>
+#include <key-impl.h>
 
 namespace CKM {
 namespace {
@@ -71,11 +71,11 @@ PKCS12Impl::PKCS12Impl(const RawBuffer &buffer, const Password &password)
     }
 
     if (pkey) {
-        GenericKey::EvpShPtr ptr(pkey, EVP_PKEY_free);
+        KeyImpl::EvpShPtr ptr(pkey, EVP_PKEY_free);
         if (EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA) {
-            m_pkey = std::make_shared<GenericKey>(ptr, KeyType::KEY_RSA_PRIVATE);
+            m_pkey = std::make_shared<KeyImpl>(ptr, KeyType::KEY_RSA_PRIVATE);
         } else if (EVP_PKEY_type(pkey->type) == EVP_PKEY_EC) {
-            m_pkey = std::make_shared<GenericKey>(ptr, KeyType::KEY_ECDSA_PRIVATE);
+            m_pkey = std::make_shared<KeyImpl>(ptr, KeyType::KEY_ECDSA_PRIVATE);
         } else {
             LogError("Unsupported private key type.");
             EVP_PKEY_free(pkey);
index 39908a3..b705a93 100644 (file)
@@ -20,7 +20,7 @@
 #include <openssl/obj_mac.h>
 #include <ckm/ckm-error.h>
 #include <ckm/ckm-type.h>
-#include <generic-key.h>
+#include <key-impl.h>
 #include <CryptoService.h>
 #include <key-manager-util.h>
 #include <assert.h>
@@ -80,8 +80,8 @@ int CryptoService::initialize() {
 
 
 int CryptoService::createKeyPairRSA(const int size, // size in bits [1024, 2048, 4096]
-               GenericKey &createdPrivateKey,  // returned value
-               GenericKey &createdPublicKey)  // returned value
+               KeyImpl &createdPrivateKey,  // returned value
+               KeyImpl &createdPublicKey)  // returned value
 {
        EVP_PKEY_CTX *ctx = NULL;
        EVP_PKEY *pkey = NULL;
@@ -141,10 +141,10 @@ int CryptoService::createKeyPairRSA(const int size, // size in bits [1024, 2048,
                ReThrowMsg(CryptoService::Exception::opensslError,"Error in opensslError function !!");
        }
 
-       GenericKey::EvpShPtr ptr(pkey, EVP_PKEY_free); // shared ptr will free pkey
+       KeyImpl::EvpShPtr ptr(pkey, EVP_PKEY_free); // shared ptr will free pkey
 
-       createdPrivateKey = GenericKey(ptr, KeyType::KEY_RSA_PRIVATE);
-       createdPublicKey = GenericKey(ptr, KeyType::KEY_RSA_PUBLIC);
+       createdPrivateKey = KeyImpl(ptr, KeyType::KEY_RSA_PRIVATE);
+       createdPublicKey = KeyImpl(ptr, KeyType::KEY_RSA_PUBLIC);
 
        if(pparam) {
                EVP_PKEY_free(pparam);
@@ -158,8 +158,8 @@ int CryptoService::createKeyPairRSA(const int size, // size in bits [1024, 2048,
 }
 
 int CryptoService::createKeyPairECDSA(ElipticCurve type,
-               GenericKey &createdPrivateKey,  // returned value
-               GenericKey &createdPublicKey)  // returned value
+               KeyImpl &createdPrivateKey,  // returned value
+               KeyImpl &createdPublicKey)  // returned value
 {
        int ecCurve = NOT_DEFINED;
        EVP_PKEY_CTX *pctx = NULL;
@@ -253,10 +253,10 @@ int CryptoService::createKeyPairECDSA(ElipticCurve type,
                ReThrowMsg(CryptoService::Exception::opensslError,"Error in openssl function !!");
        }
 
-       GenericKey::EvpShPtr ptr(pkey, EVP_PKEY_free); // shared ptr will free pkey
+       KeyImpl::EvpShPtr ptr(pkey, EVP_PKEY_free); // shared ptr will free pkey
 
-       createdPrivateKey = GenericKey(ptr, KeyType::KEY_ECDSA_PRIVATE);
-       createdPublicKey = GenericKey(ptr, KeyType::KEY_ECDSA_PUBLIC);
+       createdPrivateKey = KeyImpl(ptr, KeyType::KEY_ECDSA_PRIVATE);
+       createdPublicKey = KeyImpl(ptr, KeyType::KEY_ECDSA_PUBLIC);
 
        if(pparam) {
                EVP_PKEY_free(pparam);
@@ -273,7 +273,7 @@ int CryptoService::createKeyPairECDSA(ElipticCurve type,
        return CKM_CRYPTO_CREATEKEY_SUCCESS;
 }
 
-int CryptoService::createSignature(const GenericKey &privateKey,
+int CryptoService::createSignature(const KeyImpl &privateKey,
                const RawBuffer &message,
                const HashAlgorithm hashAlgo,
                const RSAPaddingAlgorithm padAlgo,
@@ -402,7 +402,7 @@ int CryptoService::createSignature(const GenericKey &privateKey,
        return CKM_CREATE_SIGNATURE_SUCCESS;
 }
 
-int CryptoService::verifySignature(const GenericKey &publicKey,
+int CryptoService::verifySignature(const KeyImpl &publicKey,
                const RawBuffer &message,
                const RawBuffer &signature,
                const HashAlgorithm hashAlgo,
index 22e92fe..44eff2f 100644 (file)
@@ -1,7 +1,7 @@
 #pragma once
 
 #include <iostream>
-#include <generic-key.h>
+#include <key-impl.h>
 #include <certificate-impl.h>
 #include <ckm/ckm-type.h>
 #include <vector>
@@ -53,20 +53,20 @@ class CryptoService {
      static int initialize();
 
      static int createKeyPairRSA(const int size,      // size in bits [1024, 2048, 4096]
-                         GenericKey &createdPrivateKey,  // returned value ==> Key &createdPrivateKey,
-                         GenericKey &createdPublicKey);  // returned value ==> Key &createdPublicKey
+                         KeyImpl &createdPrivateKey,  // returned value ==> Key &createdPrivateKey,
+                         KeyImpl &createdPublicKey);  // returned value ==> Key &createdPublicKey
 
      static int createKeyPairECDSA(ElipticCurve type1,
-                                        GenericKey &createdPrivateKey,  // returned value
-                                        GenericKey &createdPublicKey);  // returned value
+                                        KeyImpl &createdPrivateKey,  // returned value
+                                        KeyImpl &createdPublicKey);  // returned value
 
-     int createSignature(const GenericKey &privateKey,
+     int createSignature(const KeyImpl &privateKey,
                          const RawBuffer &message,
                          const HashAlgorithm hashAlgo,
                          const RSAPaddingAlgorithm padAlgo,
                          RawBuffer &signature);
 
-     int verifySignature(const GenericKey &publicKey,
+     int verifySignature(const KeyImpl &publicKey,
                          const RawBuffer &message,
                          const RawBuffer &signature,
                          const HashAlgorithm hashAlgo,
@@ -75,7 +75,7 @@ class CryptoService {
      int verifyCertificateChain(const CertificateImpl &certificate,
                            const CertificateImplVector &untrustedCertificates,
                            const CertificateImplVector &userTrustedCertificates,
-                          CertificateImplVector &certificateChainVector);
+                           CertificateImplVector &certificateChainVector);
 
  private:
      std::vector<X509 *> verifyCertChain(X509 *cert,
index 587d9bb..f74ea05 100644 (file)
@@ -27,7 +27,7 @@
 #include <file-system.h>
 #include <CryptoService.h>
 #include <ckm-logic.h>
-#include <generic-key.h>
+#include <key-impl.h>
 
 namespace {
 const char * const CERT_SYSTEM_DIR = "/etc/ssl/certs";
@@ -446,7 +446,7 @@ int CKMLogic::createKeyPairRSAHelper(
         return CKM_API_ERROR_DB_LOCKED;
 
     auto &handler = m_userDataMap[cred.uid];
-    GenericKey prv, pub;
+    KeyImpl prv, pub;
     int retCode;
 
     if (CKM_CRYPTO_CREATEKEY_SUCCESS !=
@@ -534,7 +534,7 @@ int CKMLogic::createKeyPairECDSAHelper(
         return CKM_API_ERROR_DB_LOCKED;
 
     auto &handler = m_userDataMap[cred.uid];
-    GenericKey prv, pub;
+    KeyImpl prv, pub;
     int retCode;
 
     if (CKM_CRYPTO_CREATEKEY_SUCCESS !=
@@ -721,7 +721,7 @@ RawBuffer CKMLogic::createSignature(
                 break;
             }
 
-            GenericKey keyParsed(row.data, Password());
+            KeyImpl keyParsed(row.data, Password());
             if (keyParsed.empty())
                 retCode = CKM_API_ERROR_SERVER_ERROR;
             else
@@ -765,18 +765,18 @@ RawBuffer CKMLogic::verifySignature(
         do {
             CryptoService cs;
             DBRow row;
-            GenericKey key;
+            KeyImpl key;
 
             retCode = getDataHelper(cred, DBDataType::DB_KEY_FIRST, publicKeyOrCertAlias, password, row);
 
             if (retCode == CKM_API_SUCCESS) {
-                key = GenericKey(row.data);
+                key = KeyImpl(row.data);
             } else if (retCode == CKM_API_ERROR_DB_ALIAS_UNKNOWN) {
                 retCode = getDataHelper(cred, DBDataType::CERTIFICATE, publicKeyOrCertAlias, password, row);
                 if (retCode != CKM_API_SUCCESS)
                     break;
                 CertificateImpl cert(row.data, DataFormat::FORM_DER);
-                key = cert.getGenericKey();
+                key = cert.getKeyImpl();
             } else {
                 break;
             }
index 9ed10c1..1a6971f 100644 (file)
@@ -178,7 +178,7 @@ private:
         Credentials &cred,
         const Alias &publicKeyOrCertAlias,
         const Password &password,           // password for public_key (optional)
-        const GenericKey &genericKey);
+        const KeyImpl &genericKey);
 
     std::map<uid_t, UserData> m_userDataMap;
     CertificateStore m_certStore;