Use SafeBuffer in C++ api. Rename SafeBuffer to RawBuffer.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 23 Jul 2014 08:53:20 +0000 (10:53 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 12 Sep 2014 12:59:15 +0000 (14:59 +0200)
Change-Id: I99a880490552ab8ed3cc50b9a60adca8a8b62d97

54 files changed:
packaging/key-manager.spec
src/CMakeLists.txt
src/include/ckm/ckm-raw-buffer.h [moved from src/manager/common/safe-buffer.h with 90% similarity]
src/include/ckm/ckm-type.h
src/manager/client/client-certificate.cpp [deleted file]
src/manager/client/client-common.cpp
src/manager/client/client-common.h
src/manager/client/client-key.cpp [deleted file]
src/manager/client/client-manager-impl.cpp
src/manager/client/client-manager-impl.h
src/manager/client/client-manager.cpp [deleted file]
src/manager/common/base64.cpp
src/manager/common/base64.h
src/manager/common/buffer-conversion.h [deleted file]
src/manager/common/certificate-impl.cpp
src/manager/common/certificate-impl.h
src/manager/common/crypto.h
src/manager/common/digest.cpp
src/manager/common/digest.h
src/manager/common/generic-key.cpp
src/manager/common/generic-key.h
src/manager/common/message-buffer.cpp
src/manager/common/message-buffer.h
src/manager/dpl/core/include/dpl/raw-buffer.h [new file with mode: 0644]
src/manager/dpl/core/include/dpl/serialization.h
src/manager/dpl/db/include/dpl/db/sql_connection.h
src/manager/dpl/db/src/sql_connection.cpp
src/manager/main/generic-socket-manager.h
src/manager/main/key-manager-util.cpp
src/manager/main/key-manager-util.h
src/manager/main/socket-manager.cpp
src/manager/main/socket-manager.h
src/manager/service/CryptoService.cpp
src/manager/service/CryptoService.h
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-logic.h
src/manager/service/ckm-service.cpp
src/manager/service/ckm-service.h
src/manager/service/crypto-logic.cpp
src/manager/service/crypto-logic.h
src/manager/service/db-crypto.cpp
src/manager/service/db-crypto.h
src/manager/service/db-row.h
src/manager/service/file-system.cpp
src/manager/service/file-system.h
src/manager/service/key-provider.h
src/manager/service/ocsp-logic.cpp
src/manager/service/ocsp-logic.h
src/manager/service/ocsp-service.cpp
tests/test-key-provider.cpp
tests/test_common.cpp
tests/test_common.h
tests/test_db_crypto.cpp
tests/test_sql.cpp

index 8d8828e..a76b398 100755 (executable)
@@ -169,6 +169,7 @@ fi
 %{_includedir}/ckm/ckm/ckm-error.h
 %{_includedir}/ckm/ckm/ckm-echo.h
 %{_includedir}/ckm/ckm/ckm-key.h
+%{_includedir}/ckm/ckm/ckm-raw-buffer.h
 %{_includedir}/ckm/ckm/ckm-type.h
 %{_includedir}/ckm/ckmc/ckmc-manager.h
 %{_includedir}/ckm/ckmc/ckmc-control.h
index 1aedb90..48e9a63 100644 (file)
@@ -147,6 +147,7 @@ INSTALL(FILES
     ${KEY_MANAGER_SRC_PATH}/include/ckm/ckm-error.h
     ${KEY_MANAGER_SRC_PATH}/include/ckm/ckm-echo.h
     ${KEY_MANAGER_SRC_PATH}/include/ckm/ckm-key.h
+    ${KEY_MANAGER_SRC_PATH}/include/ckm/ckm-raw-buffer.h
     ${KEY_MANAGER_SRC_PATH}/include/ckm/ckm-type.h
     DESTINATION /usr/include/ckm/ckm
     )
similarity index 90%
rename from src/manager/common/safe-buffer.h
rename to src/include/ckm/ckm-raw-buffer.h
index 720012d..75335c8 100644 (file)
 #ifndef _SAFE_BUFFER_H_
 #define _SAFE_BUFFER_H_
 
-#include <string.h>
-
-#include <vector>
-
 #include <boost/container/vector.hpp>
 
 namespace CKM {
@@ -70,19 +66,18 @@ constexpr bool operator!= (const erase_on_dealloc<T>&, const erase_on_dealloc<U>
  *  template <typename T>
  *  using SafeBuffer = std::vector<T, erase_on_dealloc<T>>;
  *
- *  typedef SafeBuffer<unsigned char> SafeBuffer
+ *  typedef SafeBuffer<unsigned char> RawBuffer
  *
  * when gcc 4.7/4.8 is available. Also replace boost::vector with std::vector
  * in other parts of code
  */
 template <typename T>
-struct SafeBufferT {
+struct SafeBuffer {
     typedef boost::container::vector<T, erase_on_dealloc<T>> Type;
 };
 
 // used to pass password and raw key data
-typedef SafeBufferT<unsigned char>::Type SafeBuffer;
-typedef std::vector<SafeBuffer> SafeBufferVector;
+typedef SafeBuffer<unsigned char>::Type RawBuffer;
 
 } // namespace CKM
 
index 90d59b0..f034f61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co.
+ *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 #include <string>
 #include <vector>
 
+#include <ckm/ckm-raw-buffer.h>
+
 namespace CKM {
 
 // used to pass password and raw key data
-typedef std::vector<unsigned char> RawBuffer;
 typedef std::vector<RawBuffer> RawBufferVector;
 typedef std::string Alias;
 typedef std::vector<Alias> AliasVector;
diff --git a/src/manager/client/client-certificate.cpp b/src/manager/client/client-certificate.cpp
deleted file mode 100644 (file)
index 187c772..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- *
- *
- * @file        client-certificate.h
- * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @version     1.0
- * @brief       Certificate class implementation.
- */
-
-#include <ckm/ckm-manager.h>
-
-#include <buffer-conversion.h>
-#include <certificate-impl.h>
-
-namespace CKM {
-
-Certificate::Certificate(){}
-
-Certificate::Certificate(const RawBuffer &rawData, DataFormat format)
-  : m_impl(new CertificateImpl(toSafeBuffer(rawData), format))
-{}
-
-Certificate::Certificate(const Certificate &second) {
-    m_impl = second.m_impl;
-}
-
-Certificate& Certificate::operator=(const Certificate &second) {
-    m_impl = second.m_impl;
-    return *this;
-}
-
-bool Certificate::empty() const {
-    if (m_impl)
-        return m_impl->empty();
-    return true;
-}
-
-RawBuffer Certificate::getDER() const {
-    if (m_impl)
-        return toRawBuffer(m_impl->getDER());
-    return RawBuffer();
-}
-
-void* Certificate::getX509() const {
-    if (m_impl)
-        return m_impl->getX509();
-    return NULL;
-}
-
-CertificateImpl* Certificate::getImpl() const {
-    return m_impl.get();
-}
-
-} // namespace CKM
-
index 3c137cb..1679923 100644 (file)
@@ -166,7 +166,7 @@ private:
 namespace CKM {
 
 
-int sendToServer(char const * const interface, const SafeBuffer &send, MessageBuffer &recv) {
+int sendToServer(char const * const interface, const RawBuffer &send, MessageBuffer &recv) {
     int ret;
     SockRAII sock;
     ssize_t done = 0;
@@ -208,7 +208,7 @@ int sendToServer(char const * const interface, const SafeBuffer &send, MessageBu
             return CKM_API_ERROR_SOCKET;
         }
 
-        SafeBuffer raw(buffer, buffer+temp);
+        RawBuffer raw(buffer, buffer+temp);
         recv.Push(raw);
     } while(!recv.Ready());
     return CKM_API_SUCCESS;
index 93a1ce3..b8eddd4 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 
 namespace CKM {
 
-int sendToServer(char const * const interface, const SafeBuffer &send, MessageBuffer &recv);
+int sendToServer(char const * const interface, const RawBuffer &send, MessageBuffer &recv);
 
 /*
  * Decorator function that performs frequently repeated exception handling in
diff --git a/src/manager/client/client-key.cpp b/src/manager/client/client-key.cpp
deleted file mode 100644 (file)
index 269667e..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- *
- *
- * @file        client-key.cpp
- * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @version     1.0
- * @brief       Key - api implementation.
- */
-#include <ckm/ckm-type.h>
-#include <ckm/ckm-manager.h>
-
-#include <dpl/log/log.h>
-
-#include <buffer-conversion.h>
-
-#include <generic-key.h>
-
-namespace CKM {
-
-Key::Key()
-  : m_impl(NULL)
-{}
-
-Key::Key(
-    const RawBuffer &rawData,
-    const std::string &password,
-    KeyType type)
-{
-    (void)type;
-    m_impl.reset(new GenericKey(toSafeBuffer(rawData), password));
-}
-
-Key::Key(const Key &second) {
-    m_impl = second.m_impl;
-}
-
-Key& Key::operator=(const Key &second) {
-    m_impl = second.m_impl;
-    return *this;
-}
-
-Key::~Key(){}
-
-bool Key::empty() const {
-    if (m_impl)
-        return m_impl->empty();
-    return true;
-}
-
-KeyType Key::getType() const {
-    if (m_impl)
-        return m_impl->getType();
-    return KeyType::KEY_NONE;
-}
-
-RawBuffer Key::getDER() const {
-    if (m_impl)
-        return toRawBuffer(m_impl->getDER());
-    return RawBuffer();
-}
-
-GenericKey* Key::getImpl() const {
-    if (m_impl)
-        return m_impl.get();
-    return NULL;
-};
-
-} // namespace CKM
-
index b393d5f..ffd08ab 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <client-manager-impl.h>
 #include <client-common.h>
-#include <buffer-conversion.h>
 #include <message-buffer.h>
 #include <protocols.h>
 #include <generic-key.h>
@@ -60,7 +59,7 @@ ManagerImpl::ManagerImpl()
 int ManagerImpl::saveBinaryData(
     const Alias &alias,
     DBDataType dataType,
-    const SafeBuffer &rawData,
+    const RawBuffer &rawData,
     const Policy &policy)
 {
     m_counter++;
@@ -105,7 +104,7 @@ int ManagerImpl::saveBinaryData(
 int ManagerImpl::saveKey(const Alias &alias, const KeyShPtr &key, const Policy &policy) {
     if (key.get() == NULL)
         return CKM_API_ERROR_INPUT_PARAM;
-    return saveBinaryData(alias, toDBDataType(key->getType()), toSafeBuffer(key->getDER()), policy);
+    return saveBinaryData(alias, toDBDataType(key->getType()), key->getDER(), policy);
 }
 
 int ManagerImpl::saveCertificate(
@@ -115,13 +114,13 @@ int ManagerImpl::saveCertificate(
 {
     if (cert.get() == NULL)
         return CKM_API_ERROR_INPUT_PARAM;
-    return saveBinaryData(alias, DBDataType::CERTIFICATE, toSafeBuffer(cert->getDER()), policy);
+    return saveBinaryData(alias, DBDataType::CERTIFICATE, cert->getDER(), policy);
 }
 
 int ManagerImpl::saveData(const Alias &alias, const RawBuffer &rawData, const Policy &policy) {
     if (!policy.extractable)
         return CKM_API_ERROR_INPUT_PARAM;
-    return saveBinaryData(alias, DBDataType::BINARY_DATA, toSafeBuffer(rawData), policy);
+    return saveBinaryData(alias, DBDataType::BINARY_DATA, rawData, policy);
 }
 
 int ManagerImpl::removeBinaryData(const Alias &alias, DBDataType dataType)
@@ -178,7 +177,7 @@ int ManagerImpl::getBinaryData(
     DBDataType sendDataType,
     const std::string &password,
     DBDataType &recvDataType,
-    SafeBuffer &rawData)
+    RawBuffer &rawData)
 {
     return try_catch([&] {
         if (alias.empty())
@@ -220,7 +219,7 @@ int ManagerImpl::getBinaryData(
 
 int ManagerImpl::getKey(const Alias &alias, const std::string &password, KeyShPtr &key) {
     DBDataType recvDataType;
-    SafeBuffer rawData;
+    RawBuffer rawData;
 
     int retCode = getBinaryData(
         alias,
@@ -247,7 +246,7 @@ int ManagerImpl::getKey(const Alias &alias, const std::string &password, KeyShPt
 int ManagerImpl::getCertificate(const Alias &alias, const std::string &password, CertificateShPtr &cert)
 {
     DBDataType recvDataType;
-    SafeBuffer rawData;
+    RawBuffer rawData;
 
     int retCode = getBinaryData(
         alias,
@@ -275,16 +274,13 @@ int ManagerImpl::getCertificate(const Alias &alias, const std::string &password,
 int ManagerImpl::getData(const Alias &alias, const std::string &password, RawBuffer &rawData)
 {
     DBDataType recvDataType;
-    SafeBuffer safeData;
 
     int retCode = getBinaryData(
         alias,
         DBDataType::BINARY_DATA,
         password,
         recvDataType,
-        safeData);
-
-    rawData = toRawBuffer(safeData);
+        rawData);
 
     if (retCode != CKM_API_SUCCESS)
         return retCode;
@@ -455,7 +451,7 @@ int getCertChain(
 
         int retCommand;
         int retCounter;
-        SafeBufferVector rawBufferVector;
+        RawBufferVector rawBufferVector;
 
         Deserialization::Deserialize(recv, retCommand);
         Deserialization::Deserialize(recv, retCounter);
@@ -487,10 +483,10 @@ int ManagerImpl::getCertificateChain(
     const CertificateShPtrVector &untrustedCertificates,
     CertificateShPtrVector &certificateChainVector)
 {
-    SafeBufferVector rawBufferVector;
+    RawBufferVector rawBufferVector;
 
     for (auto &e: untrustedCertificates) {
-        rawBufferVector.push_back(toSafeBuffer(e->getDER()));
+        rawBufferVector.push_back(e->getDER());
     }
 
     return getCertChain(
@@ -531,7 +527,7 @@ int ManagerImpl::createSignature(
         Serialization::Serialize(send, my_counter);
         Serialization::Serialize(send, privateKeyAlias);
         Serialization::Serialize(send, password);
-        Serialization::Serialize(send, toSafeBuffer(message));
+        Serialization::Serialize(send, message);
         Serialization::Serialize(send, static_cast<int>(hash));
         Serialization::Serialize(send, static_cast<int>(padding));
 
@@ -546,14 +542,11 @@ int ManagerImpl::createSignature(
 
         int command;
         int counter;
-        SafeBuffer safeData;
 
         Deserialization::Deserialize(recv, command);
         Deserialization::Deserialize(recv, counter);
         Deserialization::Deserialize(recv, retCode);
-        Deserialization::Deserialize(recv, safeData);
-
-        signature = toRawBuffer(safeData);
+        Deserialization::Deserialize(recv, signature);
 
         if ((command != static_cast<int>(LogicCommand::CREATE_SIGNATURE))
             || (counter != my_counter))
@@ -582,8 +575,8 @@ int ManagerImpl::verifySignature(
         Serialization::Serialize(send, my_counter);
         Serialization::Serialize(send, publicKeyOrCertAlias);
         Serialization::Serialize(send, password);
-        Serialization::Serialize(send, toSafeBuffer(message));
-        Serialization::Serialize(send, toSafeBuffer(signature));
+        Serialization::Serialize(send, message);
+        Serialization::Serialize(send, signature);
         Serialization::Serialize(send, static_cast<int>(hash));
         Serialization::Serialize(send, static_cast<int>(padding));
 
@@ -619,9 +612,9 @@ int ManagerImpl::ocspCheck(const CertificateShPtrVector &certChain, int &ocspSta
         int my_counter = ++m_counter;
         MessageBuffer send, recv;
 
-        SafeBufferVector rawCertChain;
+        RawBufferVector rawCertChain;
         for (auto &e: certChain) {
-            rawCertChain.push_back(toSafeBuffer(e->getDER()));
+            rawCertChain.push_back(e->getDER());
         }
 
         Serialization::Serialize(send, my_counter);
index dfec4b1..9e8d638 100644 (file)
@@ -21,7 +21,6 @@
 #pragma once
 
 #include <protocols.h>
-#include <safe-buffer.h>
 
 #include <ckm/ckm-type.h>
 #include <ckm/ckm-key.h>
@@ -95,7 +94,7 @@ protected:
     int saveBinaryData(
         const Alias &alias,
         DBDataType dataType,
-        const SafeBuffer &rawData,
+        const RawBuffer &rawData,
         const Policy &policy);
 
     int removeBinaryData(
@@ -107,7 +106,7 @@ protected:
         DBDataType sendDataType,
         const std::string &password,
         DBDataType &recvDataType,
-        SafeBuffer &rawData);
+        RawBuffer &rawData);
 
     int getBinaryDataAliasVector(
         DBDataType sendDataType,
diff --git a/src/manager/client/client-manager.cpp b/src/manager/client/client-manager.cpp
deleted file mode 100644 (file)
index e1cc443..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- *
- *
- * @file        client-manager.cpp
- * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @version     1.0
- * @brief       Client Manager implementation.
- */
-#include <ckm/ckm-manager.h>
-
-#include <safe-buffer.h>
-#include <buffer-conversion.h>
-#include <client-manager-impl.h>
-
-namespace CKM {
-
-Manager::Manager()
-  : m_impl(new ManagerImpl)
-{}
-
-Manager::~Manager(){}
-
-int Manager::saveKey(const Alias &alias, const Key &key, const Policy &policy) {
-    return m_impl->saveKey(alias, key, policy);
-}
-
-int Manager::removeKey(const Alias &alias) {
-    return m_impl->removeKey(alias);
-}
-
-int Manager::getKey(const Alias &alias, const std::string &password, Key &key) {
-    return m_impl->getKey(alias, password, key);
-}
-
-int Manager::saveCertificate(const Alias &alias, const Certificate &cert, const Policy &policy) {
-    if (cert.empty() || alias.empty())
-        return CKM_API_ERROR_INPUT_PARAM;
-    return m_impl->saveCertificate(alias, cert, policy);
-}
-
-int Manager::removeCertificate(const Alias &alias) {
-    if (alias.empty())
-        return CKM_API_ERROR_INPUT_PARAM;
-    return m_impl->removeCertificate(alias);
-}
-
-int Manager::getCertificate(const Alias &alias, const std::string &password, Certificate &cert) {
-    return m_impl->getCertificate(alias, password, cert);
-}
-
-int Manager::saveData(const Alias &alias, const RawBuffer &data, const Policy &policy) {
-    return m_impl->saveData(alias, toSafeBuffer(data), policy);
-}
-
-int Manager::removeData(const Alias &alias) {
-    return m_impl->removeData(alias);
-}
-
-int Manager::getData(const Alias &alias, const std::string &password, RawBuffer &data) {
-    SafeBuffer safeBuffer;
-    int status = m_impl->getData(alias, password, safeBuffer);
-    data = toRawBuffer(safeBuffer);
-    return status;
-}
-
-int Manager::getKeyAliasVector(AliasVector &av) {
-    return m_impl->getKeyAliasVector(av);
-}
-
-int Manager::getCertificateAliasVector(AliasVector &av) {
-    return m_impl->getCertificateAliasVector(av);
-}
-
-int Manager::getDataAliasVector(AliasVector &av) {
-    return m_impl->getDataAliasVector(av);
-}
-
-int Manager::createKeyPairRSA(
-    const int size,              // size in bits [1024, 2048, 4096]
-    const Alias &privateKeyAlias,
-    const Alias &publicKeyAlias,
-    const Policy &policyPrivateKey,
-    const Policy &policyPublicKey)
-{
-    return m_impl->createKeyPairRSA(size, privateKeyAlias, publicKeyAlias, policyPrivateKey, policyPublicKey);
-}
-
-int Manager::createKeyPairECDSA(
-    ElipticCurve type,
-    const Alias &privateKeyAlias,
-    const Alias &publicKeyAlias,
-    const Policy &policyPrivateKey,
-    const Policy &policyPublicKey) 
-{
-    return m_impl->createKeyPairECDSA(type, privateKeyAlias, publicKeyAlias, policyPrivateKey, policyPublicKey);
-}
-
-int Manager::getCertificateChain(
-    const Certificate &certificate,
-    const CertificateVector &untrustedCertificates,
-    CertificateVector &certificateChainVector)
-{
-    return m_impl->getCertificateChain(certificate, untrustedCertificates, certificateChainVector);
-}
-
-int Manager::getCertificateChain(
-    const Certificate &certificate,
-    const AliasVector &untrustedCertificates,
-    CertificateVector &certificateChainVector)
-{
-    return m_impl->getCertificateChain(certificate, untrustedCertificates, certificateChainVector);
-}
-
-int Manager::createSignature(
-    const Alias &privateKeyAlias,
-    const std::string &password,           // password for private_key
-    const RawBuffer &message,
-    const HashAlgorithm hash,
-    const RSAPaddingAlgorithm padding,
-    RawBuffer &signature)
-{
-    SafeBuffer safeBuffer;
-    int status = m_impl->createSignature(privateKeyAlias, password, toSafeBuffer(message), hash, padding, safeBuffer);
-    signature = toRawBuffer(safeBuffer);
-    return status;
-}
-
-int Manager::verifySignature(
-    const Alias &publicKeyOrCertAlias,
-    const std::string &password,           // password for public_key (optional)
-    const RawBuffer &message,
-    const RawBuffer &signature,
-    const HashAlgorithm hash,
-    const RSAPaddingAlgorithm padding)
-{
-    return m_impl->verifySignature(publicKeyOrCertAlias, password, toSafeBuffer(message), toSafeBuffer(signature), hash, padding);
-}
-
-int Manager::ocspCheck(const CertificateVector &certificateChainVector, int &ocspStatus)
-{
-    return m_impl->ocspCheck(certificateChainVector, ocspStatus);
-}
-
-} // namespace CKM
-
index 9ca17b9..1be549b 100644 (file)
@@ -34,7 +34,7 @@ Base64Encoder::Base64Encoder() :
 {
 }
 
-void Base64Encoder::append(const SafeBuffer &data)
+void Base64Encoder::append(const RawBuffer &data)
 {
     if (m_finalized) {
         LogWarning("Already finalized.");
@@ -57,7 +57,7 @@ void Base64Encoder::finalize()
     BIO_flush(m_b64);
 }
 
-SafeBuffer Base64Encoder::get()
+RawBuffer Base64Encoder::get()
 {
     if (!m_finalized) {
         LogWarning("Not finalized");
@@ -71,9 +71,9 @@ SafeBuffer Base64Encoder::get()
     }
 
     if (bptr->length > 0) {
-        return SafeBuffer(bptr->data, bptr->data + bptr->length);
+        return RawBuffer(bptr->data, bptr->data + bptr->length);
     }
-    return SafeBuffer();
+    return RawBuffer();
 }
 
 void Base64Encoder::reset()
@@ -101,7 +101,7 @@ Base64Decoder::Base64Decoder() :
 {
 }
 
-void Base64Decoder::append(const SafeBuffer &data)
+void Base64Decoder::append(const RawBuffer &data)
 {
     if (m_finalized) {
         LogWarning("Already finalized.");
@@ -144,7 +144,7 @@ bool Base64Decoder::finalize()
     BIO *b64, *bmem;
     size_t len = m_input.size();
 
-    SafeBuffer buffer(len);
+    RawBuffer buffer(len);
 
     if (!buffer.data()) {
         LogError("Error in malloc.");
@@ -158,7 +158,7 @@ bool Base64Decoder::finalize()
         ThrowMsg(Exception::InternalError, "Couldn't create BIO object.");
     }
     BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
-    SafeBuffer tmp(m_input);
+    RawBuffer tmp(m_input);
     m_input.clear();
 
     bmem = BIO_new_mem_buf(tmp.data(), len);
@@ -193,7 +193,7 @@ bool Base64Decoder::finalize()
     return status;
 }
 
-SafeBuffer Base64Decoder::get() const
+RawBuffer Base64Decoder::get() const
 {
     if (!m_finalized) {
         LogWarning("Not finalized.");
index fd48349..70169cb 100644 (file)
@@ -19,7 +19,8 @@
 #include <string>
 #include <dpl/noncopyable.h>
 #include <dpl/exception.h>
-#include <safe-buffer.h>
+
+#include <ckm/ckm-type.h>
 
 struct bio_st;
 typedef bio_st BIO;
@@ -38,9 +39,9 @@ class Base64Encoder : public CKM::Noncopyable
         DECLARE_EXCEPTION_TYPE(Base, AlreadyFinalized)
     };
     Base64Encoder();
-    void append(const SafeBuffer &data);
+    void append(const RawBuffer &data);
     void finalize();
-    SafeBuffer get();
+    RawBuffer get();
     void reset();
     ~Base64Encoder();
 
@@ -62,22 +63,22 @@ class Base64Decoder : public CKM::Noncopyable
         DECLARE_EXCEPTION_TYPE(Base, AlreadyFinalized)
     };
     Base64Decoder();
-    void append(const SafeBuffer &data);
+    void append(const RawBuffer &data);
 
     /*
      *  Function will return false when BIO_read fails
      *  (for example: when string was not in base64 format).
      */
     bool finalize();
-    SafeBuffer get() const;
+    RawBuffer get() const;
     void reset();
     ~Base64Decoder()
     {
     }
 
   private:
-    SafeBuffer m_input;
-    SafeBuffer m_output;
+    RawBuffer m_input;
+    RawBuffer m_output;
     bool m_finalized;
 };
 } // namespace CKM
diff --git a/src/manager/common/buffer-conversion.h b/src/manager/common/buffer-conversion.h
deleted file mode 100644 (file)
index ba97d4d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include <string.h>
-
-#include <ckm/ckm-type.h>
-#include <safe-buffer.h>
-
-namespace CKM {
-
-inline RawBuffer toRawBuffer(const SafeBuffer &safe) {
-    RawBuffer output(safe.size());
-    memcpy(output.data(), safe.data(), safe.size());
-    return output;
-}
-
-inline SafeBuffer toSafeBuffer(const RawBuffer &raw) {
-    SafeBuffer output(raw.size());
-    memcpy(output.data(), raw.data(), raw.size());
-    return output;
-}
-
-} // namespace CKM
-
index ef20d4f..10d818a 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <dpl/log/log.h>
 
-#include <buffer-conversion.h>
 #include <generic-key.h>
 #include <certificate-impl.h>
 #include <base64.h>
@@ -36,47 +35,7 @@ CertificateImpl::CertificateImpl(const RawBuffer &der, DataFormat format)
 {
     int size;
     const unsigned char *ptr;
-    SafeBuffer tmp;
-
-    LogDebug("Certificate to parse. Size: " << der.size());
-
-    if (DataFormat::FORM_DER_BASE64 == format) {
-        Base64Decoder base64;
-        base64.reset();
-        base64.append(toSafeBuffer(der));
-        base64.finalize();
-        tmp = base64.get();
-        ptr = reinterpret_cast<const unsigned char*>(tmp.data());
-        size = static_cast<int>(tmp.size());
-        m_x509 = d2i_X509(NULL, &ptr, size);
-    } else if (DataFormat::FORM_DER == format) {
-        ptr = reinterpret_cast<const unsigned char*>(der.data());
-        size = static_cast<int>(der.size());
-        m_x509 = d2i_X509(NULL, &ptr, size);
-    } else if (DataFormat::FORM_PEM == format) {
-        BIO *buff = BIO_new(BIO_s_mem());
-        BIO_write(buff, der.data(), der.size());
-        m_x509 = PEM_read_bio_X509(buff, NULL, NULL, NULL);
-        BIO_free_all(buff);
-    } else {
-        // TODO
-        LogError("Unknown certificate format");
-    }
-
-    if (!m_x509) {
-        // TODO
-        LogError("Certificate could not be parsed.");
-//        ThrowMsg(Exception::OpensslInternalError,
-//          "Internal Openssl error in d2i_X509 function.");
-    }
-}
-
-CertificateImpl::CertificateImpl(const SafeBuffer &der, DataFormat format)
-  : m_x509(NULL)
-{
-    int size;
-    const unsigned char *ptr;
-    SafeBuffer tmp;
+    RawBuffer tmp;
 
     LogDebug("Certificate to parse. Size: " << der.size());
 
@@ -162,21 +121,6 @@ RawBuffer CertificateImpl::getDER(void) const {
     return output;
 }
 
-SafeBuffer CertificateImpl::getDERSB(void) const {
-    unsigned char *rawDer = NULL;
-    int size = i2d_X509(m_x509, &rawDer);
-    if (!rawDer || size <= 0) {
-        LogError("i2d_X509 failed");
-        return SafeBuffer();
-    }
-
-    SafeBuffer output(
-        reinterpret_cast<char*>(rawDer),
-        reinterpret_cast<char*>(rawDer) + size);
-    OPENSSL_free(rawDer);
-    return output;
-}
-
 bool CertificateImpl::empty() const {
     return m_x509 == NULL;
 }
index fb20b0e..4dc6fc1 100644 (file)
@@ -34,7 +34,6 @@ class CertificateImpl : public Certificate {
 public:
     CertificateImpl(){}
     CertificateImpl(X509* x509);
-    CertificateImpl(const SafeBuffer &data, DataFormat format);
     CertificateImpl(const RawBuffer &data, DataFormat format);
     CertificateImpl(const CertificateImpl &);
     CertificateImpl(CertificateImpl &&);
@@ -45,8 +44,6 @@ public:
     virtual bool empty() const;
     virtual X509* getX509() const;
 
-    SafeBuffer getDERSB() const;
-
     GenericKey::EvpShPtr getEvpShPtr() const;
     GenericKey getGenericKey() const;
 
index 7103250..0a5e22b 100644 (file)
@@ -24,7 +24,8 @@
 
 #include <openssl/evp.h>
 
-#include <safe-buffer.h>
+#include <vector>
+#include <dpl/raw-buffer.h>
 
 namespace CKM {
 
@@ -121,8 +122,8 @@ public:                                                               \
     {}                                                                \
 }
 
-DEFINE_CIPHER(AesCbcEncryption, SafeBuffer, EVP_aes_256_cbc(), true);
-DEFINE_CIPHER(AesCbcDecryption, SafeBuffer, EVP_aes_256_cbc(), false);
+DEFINE_CIPHER(AesCbcEncryption, RawBuffer, EVP_aes_256_cbc(), true);
+DEFINE_CIPHER(AesCbcDecryption, RawBuffer, EVP_aes_256_cbc(), false);
 
 #undef DEFINE_CIPHER
 
index 9e4847f..0bec6fc 100644 (file)
@@ -61,7 +61,7 @@ void Digest::reset()
     m_initialized = true;
 }
 
-void Digest::append(const SafeBuffer &data, std::size_t len)
+void Digest::append(const RawBuffer &data, std::size_t len)
 {
     int ret = -1;
 
@@ -82,7 +82,7 @@ void Digest::append(const SafeBuffer &data, std::size_t len)
     }
 }
 
-SafeBuffer Digest::finalize()
+RawBuffer Digest::finalize()
 {
     int ret = -1;
     unsigned int dlen;
@@ -104,12 +104,12 @@ SafeBuffer Digest::finalize()
     return m_digest;
 }
 
-SafeBuffer Digest::get()
+RawBuffer Digest::get()
 {
     if (m_finalized)
         return m_digest;
     else
-        return SafeBuffer();
+        return RawBuffer();
 }
 
 unsigned int Digest::length()
index bd3fc11..e890329 100644 (file)
@@ -16,7 +16,6 @@
 
 #pragma once
 
-#include <safe-buffer.h>
 #include <dpl/noncopyable.h>
 #include <dpl/exception.h>
 #include <ckm/ckm-type.h>
@@ -42,16 +41,16 @@ class Digest : public CKM::Noncopyable
         };
         Digest();
         ~Digest();
-        void append(const SafeBuffer &data, std::size_t len = 0);
-        SafeBuffer finalize(void);
-        SafeBuffer get(void);
+        void append(const RawBuffer &data, std::size_t len = 0);
+        RawBuffer finalize(void);
+        RawBuffer get(void);
         void reset(void);
         unsigned int length(void);
 
     private:
         EVP_MD_CTX *m_ctx;
         const EVP_MD *m_md;
-        SafeBuffer m_digest;
+        RawBuffer m_digest;
         bool m_initialized;
         bool m_finalized;
 };
index 368dcb9..b4931c4 100644 (file)
 
 #include <ckm/ckm-type.h>
 #include <generic-key.h>
-#include <buffer-conversion.h>
 
 namespace CKM {
 namespace {
 
-//void printDER(const SafeBuffer &key) {
-//    std::stringstream ss;
-//    for (auto &e : key) {
-//        ss << std::hex << " " << (int)e;
-//    }
-//    ss << std::dec;
-//    LogError(ss.str());
-//}
-
 typedef std::unique_ptr<BIO, std::function<void(BIO*)>> BioUniquePtr;
 
 int passcb(char *buff, int size, int rwflag, void *userdata) {
@@ -65,31 +55,31 @@ int passcb(char *buff, int size, int rwflag, void *userdata) {
 
 typedef int(*I2D_CONV)(BIO*, EVP_PKEY*);
 
-CKM::SafeBuffer i2d(I2D_CONV fun, EVP_PKEY* pkey) {
+CKM::RawBuffer i2d(I2D_CONV fun, EVP_PKEY* pkey) {
     BioUniquePtr bio(BIO_new(BIO_s_mem()), BIO_free_all);
 
     if (NULL == pkey) {
         LogDebug("You are trying to read empty key!");
-        return SafeBuffer();
+        return RawBuffer();
     }
 
     if (NULL == bio.get()) {
         LogError("Error in memory allocation! Function: BIO_new.");
-        return SafeBuffer();
+        return RawBuffer();
     }
 
     if (1 != fun(bio.get(), pkey)) {
         LogError("Error in conversion EVP_PKEY to der");
-        return SafeBuffer();
+        return RawBuffer();
     }
 
-    CKM::SafeBuffer output(8196);
+    CKM::RawBuffer output(8196);
 
     int size = BIO_read(bio.get(), output.data(), output.size());
 
     if (size <= 0) {
         LogError("Error in BIO_read: " << size);
-        return SafeBuffer();
+        return RawBuffer();
     }
 
     output.resize(size);
@@ -108,7 +98,7 @@ GenericKey::GenericKey(const GenericKey &second) {
     m_type = second.m_type;
 }
 
-GenericKey::GenericKey(const SafeBuffer &buf, const std::string &pass)
+GenericKey::GenericKey(const RawBuffer &buf, const std::string &pass)
   : m_pkey(NULL, EVP_PKEY_free)
   , m_type(KeyType::KEY_NONE)
 {
@@ -197,29 +187,25 @@ KeyType GenericKey::getType() const {
     return m_type;
 }
 
-SafeBuffer GenericKey::getDERPRV() const {
+RawBuffer GenericKey::getDERPRV() const {
     return i2d(i2d_PrivateKey_bio, m_pkey.get());
 }
 
-SafeBuffer GenericKey::getDERPUB() const {
+RawBuffer GenericKey::getDERPUB() const {
     return i2d(i2d_PUBKEY_bio, m_pkey.get());
 }
 
-SafeBuffer GenericKey::getDERSB() const {
+RawBuffer GenericKey::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) {
         return getDERPUB();
     }
-    return SafeBuffer();
-}
-
-RawBuffer GenericKey::getDER() const {
-    return toRawBuffer(getDERSB());
+    return RawBuffer();
 }
 
 KeyShPtr Key::create(const RawBuffer &raw, const std::string &password) {
-    KeyShPtr output(new GenericKey(toSafeBuffer(raw), password));
+    KeyShPtr output(new GenericKey(raw, password));
     if (output->empty())
         output.reset();
     return output;
index 4f1cd5b..69526c0 100644 (file)
@@ -22,8 +22,6 @@
 
 #include <memory>
 
-#include <safe-buffer.h>
-
 #include <ckm/ckm-type.h>
 #include <ckm/ckm-key.h>
 #include <openssl/evp.h>
@@ -36,17 +34,14 @@ public:
 
     GenericKey();
     GenericKey(const GenericKey &second);
-    GenericKey(const SafeBuffer& buffer, const std::string &pass = std::string());
+    GenericKey(const RawBuffer& buffer, const std::string &pass = std::string());
     GenericKey(EvpShPtr pkey, KeyType type);
 
     virtual KeyType getType() const;
     virtual RawBuffer getDER() const;
-
-    SafeBuffer getDERSB() const;
-    SafeBuffer getDERPUB() const;
-    SafeBuffer getDERPRV() const;
-    EvpShPtr getEvpShPtr() const;
-
+    virtual RawBuffer getDERPUB() const;
+    virtual RawBuffer getDERPRV() const;
+    virtual EvpShPtr getEvpShPtr() const;
     virtual ElipticCurve getCurve() const {
         // TODO
         return ElipticCurve::prime192v1;
index d756f34..bfecf37 100644 (file)
 
 namespace CKM {
 
-void MessageBuffer::Push(const SafeBuffer &data) {
+void MessageBuffer::Push(const RawBuffer &data) {
     m_buffer.AppendCopy(&data[0], data.size());
 }
 
-SafeBuffer MessageBuffer::Pop() {
+RawBuffer MessageBuffer::Pop() {
     size_t size = m_buffer.Size();
-    SafeBuffer buffer;
+    RawBuffer buffer;
     buffer.resize(size + sizeof(size_t));
     memcpy(&buffer[0], &size, sizeof(size_t));
     m_buffer.FlattenConsume(&buffer[sizeof(size_t)], size);
index 47f3326..6fc459c 100644 (file)
 #ifndef _CENT_KEY_MNG_SOCKET_BUFFER_
 #define _CENT_KEY_MNG_SOCKET_BUFFER_
 
-#include <safe-buffer.h>
+#include <vector>
 
 #include <dpl/binary_queue.h>
 #include <dpl/exception.h>
 #include <dpl/serialization.h>
 
+#include <dpl/raw-buffer.h>
+
 namespace CKM {
 
 class MessageBuffer : public CKM::IStream {
@@ -47,9 +49,9 @@ public:
       : m_bytesLeft(0)
     {}
 
-    void Push(const SafeBuffer &data);
+    void Push(const RawBuffer &data);
 
-    SafeBuffer Pop();
+    RawBuffer Pop();
 
     bool Ready();
 
diff --git a/src/manager/dpl/core/include/dpl/raw-buffer.h b/src/manager/dpl/core/include/dpl/raw-buffer.h
new file mode 100644 (file)
index 0000000..5eb1391
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2014 Samsung Electronics Co.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ *
+ *
+ * @file        safe-buffer.h
+ * @author      Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version     1.0
+ * @brief       Custom allocator for std
+ */
+#pragma once
+#include <ckm/ckm-raw-buffer.h>
+
index 5c120f3..5140acf 100644 (file)
@@ -28,7 +28,7 @@
 #include <map>
 #include <memory>
 
-#include <safe-buffer.h>
+#include <dpl/raw-buffer.h>
 
 namespace CKM {
 // Abstract data stream buffer
@@ -215,14 +215,14 @@ struct Serialization {
         Serialize(stream, *p);
     }
 
-    static void Serialize(IStream& stream, const SafeBuffer& vec)
+    static void Serialize(IStream& stream, const RawBuffer& vec)
     {
         int length = vec.size();
         stream.Write(sizeof(length), &length);
         stream.Write(length, vec.data());
     }
 
-    static void Serialize(IStream& stream, const SafeBuffer* const vec)
+    static void Serialize(IStream& stream, const RawBuffer* const vec)
     {
         Serialize(stream, *vec);
     }
@@ -409,7 +409,7 @@ struct Deserialization {
         Deserialize(stream, *map);
     }
 
-    static void Deserialize(IStream& stream, SafeBuffer& vec)
+    static void Deserialize(IStream& stream, RawBuffer& vec)
     {
         int length;
         stream.Read(sizeof(length), &length);
@@ -417,9 +417,9 @@ struct Deserialization {
         stream.Read(length, vec.data());
     }
 
-    static void Deserialize(IStream& stream, SafeBuffer*& vec)
+    static void Deserialize(IStream& stream, RawBuffer*& vec)
     {
-        vec = new SafeBuffer;
+        vec = new RawBuffer;
         Deserialize(stream, *vec);
     }
 
index 561879b..513137a 100644 (file)
@@ -33,9 +33,7 @@
 #include <string>
 #include <dpl/assert.h>
 #include <stdint.h>
-#include <vector>
-
-#include <safe-buffer.h>
+#include <dpl/raw-buffer.h>
 
 namespace CKM {
 namespace DB {
@@ -167,7 +165,7 @@ class SqlConnection
          * @param position Index of argument to bind value to
          * @param value Value to bind
          */
-        void BindBlob(ArgumentIndex position, const SafeBuffer &value);
+        void BindBlob(ArgumentIndex position, const RawBuffer &value);
 
         /**
          * Bind optional int to the prepared statement argument.
@@ -248,8 +246,7 @@ class SqlConnection
          * @param position Index of argument to bind value to
          * @param value Value to bind
          */
-        void BindBlob(ArgumentIndex position,
-                const boost::optional<SafeBuffer> &value);
+        void BindBlob(ArgumentIndex position, const boost::optional<RawBuffer> &value);
 
         /**
          * Execute the prepared statement and/or move
@@ -332,7 +329,7 @@ class SqlConnection
          *
          * @throw Exception::InvalidColumn
          */
-        SafeBuffer GetColumnBlob(ColumnIndex column);
+        RawBuffer GetColumnBlob(ColumnIndex column);
 
         /**
          * Get optional integer value from column in current row.
@@ -395,7 +392,7 @@ class SqlConnection
          *
          * @throw Exception::InvalidColumn
          */
-        boost::optional<SafeBuffer> GetColumnOptionalBlob(ColumnIndex column);
+        boost::optional<RawBuffer> GetColumnOptionalBlob(ColumnIndex column);
     };
 
     // Move on copy constructor. No copy semantics
@@ -492,7 +489,7 @@ class SqlConnection
      *
      * @param rawPass password given in raw binary format
      */
-    void SetKey(const SafeBuffer &rawPass);
+    void SetKey(const RawBuffer &rawPass);
 
     /**
      * ResetKey is used for changing key used for database encryption.
@@ -506,8 +503,8 @@ class SqlConnection
      * @param rawPassNew new password for encryption in raw binary format
      *
      */
-    void ResetKey(const SafeBuffer &rawPassOld,
-                  const SafeBuffer &rawPassNew);
+    void ResetKey(const RawBuffer &rawPassOld,
+                  const RawBuffer &rawPassNew);
 
     /**
      * Execute SQL command without result
index edd9aab..d9bf3a4 100644 (file)
@@ -35,8 +35,6 @@
 #include <cstdarg>
 #include <memory>
 
-#include <safe-buffer.h>
-
 namespace CKM {
 namespace DB {
 namespace // anonymous
@@ -233,7 +231,7 @@ void SqlConnection::DataCommand::BindString(
 
 void SqlConnection::DataCommand::BindBlob(
     SqlConnection::ArgumentIndex position,
-    const SafeBuffer &raw)
+    const RawBuffer &raw)
 {
     if (raw.size() == 0) {
         BindNull(position);
@@ -345,7 +343,7 @@ void SqlConnection::DataCommand::BindString(
 
 void SqlConnection::DataCommand::BindBlob(
     SqlConnection::ArgumentIndex position,
-    const boost::optional<SafeBuffer> &value)
+    const boost::optional<RawBuffer> &value)
 {
     if (!!value) {
         BindBlob(position, *value);
@@ -514,7 +512,7 @@ std::string SqlConnection::DataCommand::GetColumnString(
     return std::string(value);
 }
 
-SafeBuffer SqlConnection::DataCommand::GetColumnBlob(
+RawBuffer SqlConnection::DataCommand::GetColumnBlob(
     SqlConnection::ColumnIndex column)
 {
     LogPedantic("SQL data command get column blog: [" << column << "]");
@@ -524,13 +522,13 @@ SafeBuffer SqlConnection::DataCommand::GetColumnBlob(
             sqlcipher3_column_blob(m_stmt, column));
 
     if (value == NULL) {
-        return SafeBuffer();
+        return RawBuffer();
     }
 
     int length = sqlcipher3_column_bytes(m_stmt, column);
     LogPedantic("Got blob of length: " << length);
 
-    return SafeBuffer(value, value + length);
+    return RawBuffer(value, value + length);
 }
 
 boost::optional<int> SqlConnection::DataCommand::GetColumnOptionalInteger(
@@ -647,14 +645,14 @@ boost::optional<String> SqlConnection::DataCommand::GetColumnOptionalString(
     return boost::optional<String>(s);
 }
 
-boost::optional<SafeBuffer> SqlConnection::DataCommand::GetColumnOptionalBlob(
+boost::optional<RawBuffer> SqlConnection::DataCommand::GetColumnOptionalBlob(
     SqlConnection::ColumnIndex column)
 {
     LogPedantic("SQL data command get column blog: [" << column << "]");
     CheckColumnIndex(column);
 
     if (sqlcipher3_column_type(m_stmt, column) == SQLCIPHER_NULL) {
-        return boost::optional<SafeBuffer>();
+        return boost::optional<RawBuffer>();
     }
     const unsigned char *value = reinterpret_cast<const unsigned char*>(
             sqlcipher3_column_blob(m_stmt, column));
@@ -662,8 +660,8 @@ boost::optional<SafeBuffer> SqlConnection::DataCommand::GetColumnOptionalBlob(
     int length = sqlcipher3_column_bytes(m_stmt, column);
     LogPedantic("Got blob of length: " << length);
 
-    SafeBuffer temp(value, value + length);
-    return boost::optional<SafeBuffer>(temp);
+    RawBuffer temp(value, value + length);
+    return boost::optional<RawBuffer>(temp);
 }
 
 void SqlConnection::Connect(const std::string &address,
@@ -700,12 +698,12 @@ const std::size_t SQLCIPHER_RAW_DATA_SIZE = 32;
 
 void rawToHexString(TransitoryString& str,
                     std::size_t offset,
-                    const SafeBuffer &raw) {
+                    const RawBuffer &raw) {
     for (std::size_t i = 0; i < raw.size(); i++)
         sprintf(&str[offset + i*2], "%02X", raw[i]);
 }
 
-TransitoryString createHexPass(const SafeBuffer &rawPass){
+TransitoryString createHexPass(const RawBuffer &rawPass){
     TransitoryString pass = TransitoryString('0', SQLCIPHER_RAW_PREFIX.length() +
                                              //We are required to pass 64byte
                                              //long hex password made out of
@@ -722,7 +720,7 @@ TransitoryString createHexPass(const SafeBuffer &rawPass){
 
 }
 
-void SqlConnection::SetKey(const SafeBuffer &rawPass){
+void SqlConnection::SetKey(const RawBuffer &rawPass){
     if (m_connection == NULL) {
         LogPedantic("Cannot set key. No connection to DB!");
         return;
@@ -744,9 +742,8 @@ void SqlConnection::SetKey(const SafeBuffer &rawPass){
     m_isKeySet = true;
 };
 
-void SqlConnection::ResetKey(const SafeBuffer &rawPassOld,
-                             const SafeBuffer &rawPassNew)
-{
+void SqlConnection::ResetKey(const RawBuffer &rawPassOld,
+                             const RawBuffer &rawPassNew) {
     if (m_connection == NULL) {
         LogPedantic("Cannot reset key. No connection to DB!");
         return;
index d24c397..6066ccb 100644 (file)
 
 #include <sys/types.h>
 
-#include <safe-buffer.h>
-
 #include <dpl/exception.h>
 
 #include <generic-event.h>
+#include <dpl/raw-buffer.h>
 
 extern "C" {
 struct msghdr;
@@ -96,7 +95,7 @@ struct GenericSocketService {
 
     struct ReadEvent : public GenericEvent {
         ConnectionID connectionID;
-        SafeBuffer rawBuffer;
+        RawBuffer rawBuffer;
     };
 
     struct CloseEvent : public GenericEvent {
@@ -123,7 +122,7 @@ struct GenericSocketManager {
     virtual void MainLoop() = 0;
     virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
     virtual void Close(ConnectionID connectionID) = 0;
-    virtual void Write(ConnectionID connectionID, const SafeBuffer &rawBuffer) = 0;
+    virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
     virtual ~GenericSocketManager(){}
 };
 
index 3fb3fa4..04f424d 100644 (file)
@@ -117,14 +117,14 @@ char *read_exe_path_from_proc(pid_t pid)
     return exe;
 }
 
-void rawBufferToX509(X509 **ppCert, SafeBuffer rawCert) {
+void rawBufferToX509(X509 **ppCert, RawBuffer rawCert) {
   BIO *bio = BIO_new(BIO_s_mem());
   BIO_write(bio, rawCert.data(), rawCert.size());
   d2i_X509_bio(bio, ppCert);
   BIO_free_all(bio);
 }
 
-void x509ToSafeBuffer(SafeBuffer &buf, X509 *cert) {
+void x509ToRawBuffer(RawBuffer &buf, X509 *cert) {
   int len = i2d_X509(cert, NULL);
   unsigned char tmpBuff[len];
   unsigned char *p = tmpBuff;
index f0ceb93..b43b3fa 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef CENT_KEY_MNG_UTIL_H
 #define CENT_KEY_MNG_UTIL_H
 
-#include <safe-buffer.h>
 #include <sys/types.h>
 #include <ckm/ckm-type.h>
 #include <openssl/x509v3.h>
@@ -34,8 +33,8 @@ namespace CKM {
 int util_smack_label_is_valid(const char *smack_label);
 char *read_exe_path_from_proc(pid_t pid);
 
-void rawBufferToX509(X509 **ppCert, SafeBuffer rawCert);
-void x509ToSafeBuffer(SafeBuffer &buf, X509 *cert);
+void rawBufferToX509(X509 **ppCert, RawBuffer rawCert);
+void x509ToRawBuffer(RawBuffer &buf, X509 *cert);
 
 STACK_OF(X509) *loadSystemCerts( const char * dirpath);
 X509 *loadCert(const char *file);
index 42559b8..73e90e4 100644 (file)
@@ -582,7 +582,7 @@ void SocketManager::Close(ConnectionID connectionID) {
     NotifyMe();
 }
 
-void SocketManager::Write(ConnectionID connectionID, const SafeBuffer &rawBuffer) {
+void SocketManager::Write(ConnectionID connectionID, const RawBuffer &rawBuffer) {
     WriteBuffer buffer;
     buffer.connectionID = connectionID;
     buffer.rawBuffer = rawBuffer;
index 922567d..978dbee 100644 (file)
@@ -52,7 +52,7 @@ public:
 
     virtual void RegisterSocketService(GenericSocketService *service);
     virtual void Close(ConnectionID connectionID);
-    virtual void Write(ConnectionID connectionID, const SafeBuffer &rawBuffer);
+    virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer);
 
 protected:
     void CreateDomainSocket(
@@ -79,7 +79,7 @@ protected:
         InterfaceID interfaceID;
         GenericSocketService *service;
         time_t timeout;
-        SafeBuffer rawBuffer;
+        RawBuffer rawBuffer;
         int counter;
 
         SocketDescription()
@@ -97,7 +97,7 @@ protected:
 
     struct WriteBuffer {
         ConnectionID connectionID;
-        SafeBuffer rawBuffer;
+        RawBuffer rawBuffer;
     };
 
     struct Timeout {
index 4d73ce1..39908a3 100644 (file)
@@ -274,15 +274,15 @@ int CryptoService::createKeyPairECDSA(ElipticCurve type,
 }
 
 int CryptoService::createSignature(const GenericKey &privateKey,
-               const SafeBuffer &message,
+               const RawBuffer &message,
                const HashAlgorithm hashAlgo,
                const RSAPaddingAlgorithm padAlgo,
-               SafeBuffer &signature)
+               RawBuffer &signature)
 {
        EVP_MD_CTX *mdctx = NULL;
        EVP_PKEY_CTX *pctx = NULL;
        int rsa_padding = NOT_DEFINED;
-       SafeBuffer data;
+       RawBuffer data;
        const EVP_MD *md_algo = NULL;
 
        // check the parameters of functions
@@ -403,8 +403,8 @@ int CryptoService::createSignature(const GenericKey &privateKey,
 }
 
 int CryptoService::verifySignature(const GenericKey &publicKey,
-               const SafeBuffer &message,
-               const SafeBuffer &signature,
+               const RawBuffer &message,
+               const RawBuffer &signature,
                const HashAlgorithm hashAlgo,
                const RSAPaddingAlgorithm padAlgo)
 {
@@ -515,7 +515,7 @@ int CryptoService::verifyCertificateChain(const CertificateImpl &certificate,
 
        X509 *cert = X509_new();
        X509 *tempCert;
-       rawBufferToX509(&cert, certificate.getDERSB());
+       rawBufferToX509(&cert, certificate.getDER());
 
        std::vector<X509 *> trustedCerts;
        std::vector<X509 *> userTrustedCerts;
@@ -557,7 +557,7 @@ int CryptoService::verifyCertificateChain(const CertificateImpl &certificate,
                                LogError("Error in X509_new function");
                                ThrowMsg(CryptoService::Exception::opensslError, "Error in X509_new function");
                        }
-                       rawBufferToX509(&tempCert, userTrustedCertificates[i].getDERSB());
+                       rawBufferToX509(&tempCert, userTrustedCertificates[i].getDER());
                        userTrustedCerts.push_back(tempCert);
                }
 
@@ -566,16 +566,16 @@ int CryptoService::verifyCertificateChain(const CertificateImpl &certificate,
                                LogError("Error in X509_new function");
                                ThrowMsg(CryptoService::Exception::opensslError, "Error in X509_new function");
                        }
-                       rawBufferToX509(&tempCert, untrustedCertificates[i].getDERSB());
+                       rawBufferToX509(&tempCert, untrustedCertificates[i].getDER());
                        untrustedChain.push_back(tempCert);
                }
 
                std::vector<X509 *> chain = verifyCertChain(cert, trustedCerts, userTrustedCerts, untrustedChain);
 
-               SafeBuffer tmpBuf;
+               RawBuffer tmpBuf;
                for(unsigned int i=0;i<chain.size();i++) {
-                       x509ToSafeBuffer(tmpBuf, chain[i]);
-                       CertificateImpl tmpCertImpl((const SafeBuffer)tmpBuf, DataFormat::FORM_DER);
+                       x509ToRawBuffer(tmpBuf, chain[i]);
+                       CertificateImpl tmpCertImpl((const RawBuffer)tmpBuf, DataFormat::FORM_DER);
                        certificateChainVector.push_back(tmpCertImpl);
                }
        } Catch(CryptoService::Exception::opensslError) {
index 04b8bb8..22e92fe 100644 (file)
@@ -61,14 +61,14 @@ class CryptoService {
                                         GenericKey &createdPublicKey);  // returned value
 
      int createSignature(const GenericKey &privateKey,
-                         const SafeBuffer &message,
+                         const RawBuffer &message,
                          const HashAlgorithm hashAlgo,
                          const RSAPaddingAlgorithm padAlgo,
-                         SafeBuffer &signature);
+                         RawBuffer &signature);
 
      int verifySignature(const GenericKey &publicKey,
-                         const SafeBuffer &message,
-                         const SafeBuffer &signature,
+                         const RawBuffer &message,
+                         const RawBuffer &signature,
                          const HashAlgorithm hashAlgo,
                          const RSAPaddingAlgorithm padAlgo);
 
index 3a58269..948411f 100755 (executable)
@@ -50,7 +50,7 @@ CKMLogic::CKMLogic()
 
 CKMLogic::~CKMLogic(){}
 
-SafeBuffer CKMLogic::unlockUserKey(uid_t user, const std::string &password) {
+RawBuffer CKMLogic::unlockUserKey(uid_t user, const std::string &password) {
     // TODO try catch for all errors that should be supported by error code
     int retCode = CKM_API_SUCCESS;
 
@@ -67,7 +67,7 @@ SafeBuffer CKMLogic::unlockUserKey(uid_t user, const std::string &password) {
 
             handle.keyProvider = KeyProvider(wrappedDomainKEK, password);
 
-            SafeBuffer key = handle.keyProvider.getPureDomainKEK();
+            RawBuffer key = handle.keyProvider.getPureDomainKEK();
             handle.database = DBCrypto(fs.getDBPath(), key);
             handle.crypto = CryptoLogic();
             // TODO wipe key
@@ -91,7 +91,7 @@ SafeBuffer CKMLogic::unlockUserKey(uid_t user, const std::string &password) {
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::lockUserKey(uid_t user) {
+RawBuffer CKMLogic::lockUserKey(uid_t user) {
     int retCode = CKM_API_SUCCESS;
     // TODO try catch for all errors that should be supported by error code
     m_userDataMap.erase(user);
@@ -101,7 +101,7 @@ SafeBuffer CKMLogic::lockUserKey(uid_t user) {
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::removeUserData(uid_t user) {
+RawBuffer CKMLogic::removeUserData(uid_t user) {
     int retCode = CKM_API_SUCCESS;
     // TODO try catch for all errors that should be supported by error code
     m_userDataMap.erase(user);
@@ -114,7 +114,7 @@ SafeBuffer CKMLogic::removeUserData(uid_t user) {
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::changeUserPassword(
+RawBuffer CKMLogic::changeUserPassword(
     uid_t user,
     const std::string &oldPassword,
     const std::string &newPassword)
@@ -145,7 +145,7 @@ SafeBuffer CKMLogic::changeUserPassword(
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::resetUserPassword(
+RawBuffer CKMLogic::resetUserPassword(
     uid_t user,
     const std::string &newPassword)
 {
@@ -168,7 +168,7 @@ int CKMLogic::saveDataHelper(
     Credentials &cred,
     DBDataType dataType,
     const Alias &alias,
-    const SafeBuffer &key,
+    const RawBuffer &key,
     const PolicySerializable &policy)
 {
     if (0 == m_userDataMap.count(cred.uid))
@@ -176,12 +176,12 @@ int CKMLogic::saveDataHelper(
 
     DBRow row = { alias, cred.smackLabel, policy.restricted,
          policy.extractable, dataType, DBCMAlgType::NONE,
-         0, SafeBuffer(), static_cast<int>(key.size()), key };
+         0, RawBuffer(), static_cast<int>(key.size()), key };
 
     auto &handler = m_userDataMap[cred.uid];
     DBCrypto::Transaction transaction(&handler.database);
     if (!handler.crypto.haveKey(cred.smackLabel)) {
-        SafeBuffer key;
+        RawBuffer key;
         auto key_optional = handler.database.getKey(cred.smackLabel);
         if(!key_optional) {
             LogDebug("No Key in database found. Generating new one for label: "
@@ -202,12 +202,12 @@ int CKMLogic::saveDataHelper(
     return CKM_API_SUCCESS;
 }
 
-SafeBuffer CKMLogic::saveData(
+RawBuffer CKMLogic::saveData(
     Credentials &cred,
     int commandId,
     DBDataType dataType,
     const Alias &alias,
-    const SafeBuffer &key,
+    const RawBuffer &key,
     const PolicySerializable &policy)
 {
     int retCode = CKM_API_SUCCESS;
@@ -240,7 +240,7 @@ SafeBuffer CKMLogic::saveData(
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::removeData(
+RawBuffer CKMLogic::removeData(
     Credentials &cred,
     int commandId,
     DBDataType dataType,
@@ -320,7 +320,7 @@ int CKMLogic::getDataHelper(
     }
 
     if (!handler.crypto.haveKey(row.smackLabel)) {
-        SafeBuffer key;
+        RawBuffer key;
         auto key_optional = handler.database.getKey(row.smackLabel);
         if(!key_optional) {
             LogError("No key for given label in database");
@@ -335,7 +335,7 @@ int CKMLogic::getDataHelper(
     return CKM_API_SUCCESS;
 }
 
-SafeBuffer CKMLogic::getData(
+RawBuffer CKMLogic::getData(
     Credentials &cred,
     int commandId,
     DBDataType dataType,
@@ -372,7 +372,7 @@ SafeBuffer CKMLogic::getData(
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::getDataList(
+RawBuffer CKMLogic::getDataList(
     Credentials &cred,
     int commandId,
     DBDataType dataType)
@@ -431,7 +431,7 @@ int CKMLogic::createKeyPairRSAHelper(
     retCode = saveDataHelper(cred,
                             toDBDataType(prv.getType()),
                             aliasPrivate,
-                            prv.getDERSB(),
+                            prv.getDER(),
                             policyPrivate);
 
     if (CKM_API_SUCCESS != retCode)
@@ -440,7 +440,7 @@ int CKMLogic::createKeyPairRSAHelper(
     retCode = saveDataHelper(cred,
                             toDBDataType(pub.getType()),
                             aliasPublic,
-                            pub.getDERSB(),
+                            pub.getDER(),
                             policyPublic);
 
     if (CKM_API_SUCCESS != retCode)
@@ -451,7 +451,7 @@ int CKMLogic::createKeyPairRSAHelper(
     return retCode;
 }
 
-SafeBuffer CKMLogic::createKeyPairRSA(
+RawBuffer CKMLogic::createKeyPairRSA(
     Credentials &cred,
     int commandId,
     int size,
@@ -520,7 +520,7 @@ int CKMLogic::createKeyPairECDSAHelper(
     retCode = saveDataHelper(cred,
                             toDBDataType(prv.getType()),
                             aliasPrivate,
-                            prv.getDERSB(),
+                            prv.getDER(),
                             policyPrivate);
 
     if (CKM_API_SUCCESS != retCode)
@@ -529,7 +529,7 @@ int CKMLogic::createKeyPairECDSAHelper(
     retCode = saveDataHelper(cred,
                             toDBDataType(pub.getType()),
                             aliasPublic,
-                            pub.getDERSB(),
+                            pub.getDER(),
                             policyPublic);
 
     if (CKM_API_SUCCESS != retCode)
@@ -540,7 +540,7 @@ int CKMLogic::createKeyPairECDSAHelper(
     return retCode;
 }
 
-SafeBuffer CKMLogic::createKeyPairECDSA(
+RawBuffer CKMLogic::createKeyPairECDSA(
     Credentials &cred,
     int commandId,
     int type,
@@ -581,18 +581,18 @@ SafeBuffer CKMLogic::createKeyPairECDSA(
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::getCertificateChain(
+RawBuffer CKMLogic::getCertificateChain(
     Credentials &cred,
     int commandId,
-    const SafeBuffer &certificate,
-    const SafeBufferVector &untrustedRawCertVector)
+    const RawBuffer &certificate,
+    const RawBufferVector &untrustedRawCertVector)
 {
     (void)cred;
 
     CertificateImpl cert(certificate, DataFormat::FORM_DER);
     CertificateImplVector untrustedCertVector;
     CertificateImplVector chainVector;
-    SafeBufferVector chainRawVector;
+    RawBufferVector chainRawVector;
 
     for (auto &e: untrustedRawCertVector)
         untrustedCertVector.push_back(CertificateImpl(e, DataFormat::FORM_DER));
@@ -603,7 +603,7 @@ SafeBuffer CKMLogic::getCertificateChain(
 
     if (retCode == CKM_API_SUCCESS) {
         for (auto &e : chainVector)
-            chainRawVector.push_back(e.getDERSB());
+            chainRawVector.push_back(e.getDER());
     }
 
     MessageBuffer response;
@@ -614,14 +614,14 @@ SafeBuffer CKMLogic::getCertificateChain(
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::getCertificateChain(
+RawBuffer CKMLogic::getCertificateChain(
     Credentials &cred,
     int commandId,
-    const SafeBuffer &certificate,
+    const RawBuffer &certificate,
     const AliasVector &aliasVector)
 {
     int retCode = CKM_API_SUCCESS;
-    SafeBufferVector chainRawVector;
+    RawBufferVector chainRawVector;
     try {
         CertificateImpl cert(certificate, DataFormat::FORM_DER);
         CertificateImplVector untrustedCertVector;
@@ -648,7 +648,7 @@ SafeBuffer CKMLogic::getCertificateChain(
             goto senderror;
 
         for (auto &i: chainVector)
-            chainRawVector.push_back(i.getDERSB());
+            chainRawVector.push_back(i.getDER());
 
     } catch (const CryptoLogic::Exception::Base &e) {
         LogError("DBCyptorModule failed with message: " << e.GetMessage());
@@ -669,18 +669,18 @@ senderror:
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::createSignature(
+RawBuffer CKMLogic::createSignature(
         Credentials &cred,
         int commandId,
         const Alias &privateKeyAlias,
         const std::string &password,           // password for private_key
-        const SafeBuffer &message,
+        const RawBuffer &message,
         const HashAlgorithm hash,
         const RSAPaddingAlgorithm padding)
 {
     DBRow row;
     CryptoService cs;
-    SafeBuffer signature;
+    RawBuffer signature;
 
     int retCode = CKM_API_SUCCESS;
 
@@ -720,13 +720,13 @@ SafeBuffer CKMLogic::createSignature(
     return response.Pop();
 }
 
-SafeBuffer CKMLogic::verifySignature(
+RawBuffer CKMLogic::verifySignature(
         Credentials &cred,
         int commandId,
         const Alias &publicKeyOrCertAlias,
         const std::string &password,           // password for public_key (optional)
-        const SafeBuffer &message,
-        const SafeBuffer &signature,
+        const RawBuffer &message,
+        const RawBuffer &signature,
         const HashAlgorithm hash,
         const RSAPaddingAlgorithm padding)
 {
index c42a478..661a6a7 100644 (file)
@@ -50,48 +50,48 @@ public:
     CKMLogic& operator=(CKMLogic &&) = delete;
     virtual ~CKMLogic();
 
-    SafeBuffer unlockUserKey(uid_t user, const std::string &password);
+    RawBuffer unlockUserKey(uid_t user, const std::string &password);
 
-    SafeBuffer lockUserKey(uid_t user);
+    RawBuffer lockUserKey(uid_t user);
 
-    SafeBuffer removeUserData(uid_t user);
+    RawBuffer removeUserData(uid_t user);
 
-    SafeBuffer changeUserPassword(
+    RawBuffer changeUserPassword(
         uid_t user,
         const std::string &oldPassword,
         const std::string &newPassword);
 
-    SafeBuffer resetUserPassword(
+    RawBuffer resetUserPassword(
         uid_t user,
         const std::string &newPassword);
 
-    SafeBuffer saveData(
+    RawBuffer saveData(
         Credentials &cred,
         int commandId,
         DBDataType dataType,
         const Alias &alias,
-        const SafeBuffer &key,
+        const RawBuffer &key,
         const PolicySerializable &policy);
 
-    SafeBuffer removeData(
+    RawBuffer removeData(
         Credentials &cred,
         int commandId,
         DBDataType dataType,
         const Alias &alias);
 
-    SafeBuffer getData(
+    RawBuffer getData(
         Credentials &cred,
         int commandId,
         DBDataType dataType,
         const Alias &alias,
         const std::string &password);
 
-    SafeBuffer getDataList(
+    RawBuffer getDataList(
         Credentials &cred,
         int commandId,
         DBDataType dataType);
 
-    SafeBuffer createKeyPairRSA(
+    RawBuffer createKeyPairRSA(
         Credentials &cred,
         int commandId,
         int size,
@@ -100,7 +100,7 @@ public:
         const PolicySerializable &policyPrivate,
         const PolicySerializable &policyPublic);
 
-    SafeBuffer createKeyPairECDSA(
+    RawBuffer createKeyPairECDSA(
         Credentials &cred,
         int commandId,
         int type,
@@ -109,34 +109,34 @@ public:
         const PolicySerializable &policyPrivate,
         const PolicySerializable &policyPublic);
 
-    SafeBuffer getCertificateChain(
+    RawBuffer getCertificateChain(
         Credentials &cred,
         int commandId,
-        const SafeBuffer &certificate,
-        const SafeBufferVector &untrustedCertificates);
+        const RawBuffer &certificate,
+        const RawBufferVector &untrustedCertificates);
 
-    SafeBuffer getCertificateChain(
+    RawBuffer getCertificateChain(
         Credentials &cred,
         int commandId,
-        const SafeBuffer &certificate,
+        const RawBuffer &certificate,
         const AliasVector &aliasVector);
 
-    SafeBuffer  createSignature(
+    RawBuffer  createSignature(
         Credentials &cred,
         int commandId,
         const Alias &privateKeyAlias,
         const std::string &password,           // password for private_key
-        const SafeBuffer &message,
+        const RawBuffer &message,
         const HashAlgorithm hash,
         const RSAPaddingAlgorithm padding);
 
-    SafeBuffer verifySignature(
+    RawBuffer verifySignature(
         Credentials &cred,
         int commandId,
         const Alias &publicKeyOrCertAlias,
         const std::string &password,           // password for public_key (optional)
-        const SafeBuffer &message,
-        const SafeBuffer &signature,
+        const RawBuffer &message,
+        const RawBuffer &signature,
         const HashAlgorithm hash,
         const RSAPaddingAlgorithm padding);
 
@@ -146,7 +146,7 @@ private:
         Credentials &cred,
         DBDataType dataType,
         const Alias &alias,
-        const SafeBuffer &key,
+        const RawBuffer &key,
         const PolicySerializable &policy);
 
     int getDataHelper(
index 441f767..39f8339 100644 (file)
@@ -77,7 +77,7 @@ bool CKMService::processOne(
     ConnectionInfo &info)
 {
     LogDebug ("process One");
-    SafeBuffer response;
+    RawBuffer response;
 
     Try {
         if (!info.buffer.Ready())
@@ -103,7 +103,7 @@ bool CKMService::processOne(
     return false;
 }
 
-SafeBuffer CKMService::processControl(MessageBuffer &buffer) {
+RawBuffer CKMService::processControl(MessageBuffer &buffer) {
     int command;
     uid_t user;
     ControlCommand cc;
@@ -137,7 +137,7 @@ SafeBuffer CKMService::processControl(MessageBuffer &buffer) {
     }
 }
 
-SafeBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
+RawBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
     int command;
     int commandId;
     int tmpDataType;
@@ -152,7 +152,7 @@ SafeBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
     switch(static_cast<LogicCommand>(command)) {
         case LogicCommand::SAVE:
         {
-            SafeBuffer rawData;
+            RawBuffer rawData;
             PolicySerializable policy;
             Deserialization::Deserialize(buffer, tmpDataType);
             Deserialization::Deserialize(buffer, alias);
@@ -241,8 +241,8 @@ SafeBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
         }
         case LogicCommand::GET_CHAIN_CERT:
         {
-            SafeBuffer certificate;
-            SafeBufferVector rawBufferVector;
+            RawBuffer certificate;
+            RawBufferVector rawBufferVector;
             Deserialization::Deserialize(buffer, certificate);
             Deserialization::Deserialize(buffer, rawBufferVector);
             return m_logic->getCertificateChain(
@@ -253,7 +253,7 @@ SafeBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
         }
         case LogicCommand::GET_CHAIN_ALIAS:
         {
-            SafeBuffer certificate;
+            RawBuffer certificate;
             AliasVector aliasVector;
             Deserialization::Deserialize(buffer, certificate);
             Deserialization::Deserialize(buffer, aliasVector);
@@ -267,7 +267,7 @@ SafeBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
         {
             Alias privateKeyAlias;
             std::string password;        // password for private_key
-            SafeBuffer message;
+            RawBuffer message;
             int padding, hash;
             Deserialization::Deserialize(buffer, privateKeyAlias);
             Deserialization::Deserialize(buffer, password);
@@ -288,8 +288,8 @@ SafeBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
         {
             Alias publicKeyOrCertAlias;
             std::string password;           // password for public_key (optional)
-            SafeBuffer message;
-            SafeBuffer signature;
+            RawBuffer message;
+            RawBuffer signature;
             //HashAlgorithm hash;
             //RSAPaddingAlgorithm padding;
             int padding, hash;
index 09011dd..f305a05 100644 (file)
@@ -58,10 +58,10 @@ private:
         const ConnectionID &conn,
         ConnectionInfo &info);
 
-    SafeBuffer processControl(
+    RawBuffer processControl(
         MessageBuffer &buffer);
 
-    SafeBuffer processStorage(
+    RawBuffer processStorage(
         Credentials &cred,
         MessageBuffer &buffer);
 
index a9d8d63..4b71210 100644 (file)
@@ -60,7 +60,7 @@ bool CryptoLogic::haveKey(const std::string &smackLabel)
 }
 
 void CryptoLogic::pushKey(const std::string &smackLabel,
-                            const SafeBuffer &applicationKey)
+                            const RawBuffer &applicationKey)
 {
     if (smackLabel.length() == 0) {
         ThrowMsg(Exception::InternalError, "Empty smack label.");
@@ -75,9 +75,9 @@ void CryptoLogic::pushKey(const std::string &smackLabel,
     m_keyMap[smackLabel] = applicationKey;
 }
 
-std::size_t CryptoLogic::insertDigest(SafeBuffer &data, const int dataSize)
+std::size_t CryptoLogic::insertDigest(RawBuffer &data, const int dataSize)
 {
-    SafeBuffer digest;
+    RawBuffer digest;
 
     try {
         Digest dig;
@@ -92,7 +92,7 @@ std::size_t CryptoLogic::insertDigest(SafeBuffer &data, const int dataSize)
     return digest.size();
 }
 
-void CryptoLogic::removeDigest(SafeBuffer &data, SafeBuffer &digest)
+void CryptoLogic::removeDigest(RawBuffer &data, RawBuffer &digest)
 {
     unsigned int dlen = Digest().length();
 
@@ -105,36 +105,36 @@ void CryptoLogic::removeDigest(SafeBuffer &data, SafeBuffer &digest)
     data.erase(data.begin(), data.begin() + dlen);
 }
 
-SafeBuffer CryptoLogic::encryptData(
-    const SafeBuffer &data,
-    const SafeBuffer &key,
-    const SafeBuffer &iv) const
+RawBuffer CryptoLogic::encryptData(
+    const RawBuffer &data,
+    const RawBuffer &key,
+    const RawBuffer &iv) const
 {
     Crypto::Cipher::AesCbcEncryption enc(key, iv);
-    SafeBuffer result = enc.Append(data);
-    SafeBuffer tmp = enc.Finalize();
+    RawBuffer result = enc.Append(data);
+    RawBuffer tmp = enc.Finalize();
     std::copy(tmp.begin(), tmp.end(), std::back_inserter(result));
     return result;
 }
 
-SafeBuffer CryptoLogic::decryptData(
-    const SafeBuffer &data,
-    const SafeBuffer &key,
-    const SafeBuffer &iv) const
+RawBuffer CryptoLogic::decryptData(
+    const RawBuffer &data,
+    const RawBuffer &key,
+    const RawBuffer &iv) const
 {
     Crypto::Cipher::AesCbcDecryption dec(key, iv);
-    SafeBuffer result = dec.Append(data);
-    SafeBuffer tmp = dec.Finalize();
+    RawBuffer result = dec.Append(data);
+    RawBuffer tmp = dec.Finalize();
     std::copy(tmp.begin(), tmp.end(), std::back_inserter(result));
     return result;
 }
 
-SafeBuffer CryptoLogic::passwordToKey(
+RawBuffer CryptoLogic::passwordToKey(
     const std::string &password,
-    const SafeBuffer &salt,
+    const RawBuffer &salt,
     size_t keySize) const
 {
-    SafeBuffer result(keySize);
+    RawBuffer result(keySize);
 
     if (1 != PKCS5_PBKDF2_HMAC_SHA1(
                 password.c_str(),
@@ -150,8 +150,8 @@ SafeBuffer CryptoLogic::passwordToKey(
     return result;
 }
 
-SafeBuffer CryptoLogic::generateRandIV() const {
-    SafeBuffer civ(EVP_MAX_IV_LENGTH);
+RawBuffer CryptoLogic::generateRandIV() const {
+    RawBuffer civ(EVP_MAX_IV_LENGTH);
 
     if (1 != RAND_bytes(civ.data(), civ.size())) {
         ThrowMsg(Exception::InternalError,
@@ -165,9 +165,9 @@ void CryptoLogic::encryptRow(const std::string &password, DBRow &row)
 {
     try {
         DBRow crow = row;
-        SafeBuffer key;
-        SafeBuffer result1;
-        SafeBuffer result2;
+        RawBuffer key;
+        RawBuffer result1;
+        RawBuffer result2;
 
         crow.algorithmType = DBCMAlgType::AES_CBC_256;
 
@@ -217,8 +217,8 @@ void CryptoLogic::decryptRow(const std::string &password, DBRow &row)
 {
     try {
         DBRow crow = row;
-        SafeBuffer key;
-        SafeBuffer digest, dataDigest;
+        RawBuffer key;
+        RawBuffer digest, dataDigest;
 
         if (row.algorithmType != DBCMAlgType::AES_CBC_256) {
             ThrowMsg(Exception::DecryptDBRowError, "Invalid algorithm type.");
@@ -278,10 +278,10 @@ void CryptoLogic::decryptRow(const std::string &password, DBRow &row)
     }
 }
 
-void CryptoLogic::encBase64(SafeBuffer &data)
+void CryptoLogic::encBase64(RawBuffer &data)
 {
     Base64Encoder benc;
-    SafeBuffer encdata;
+    RawBuffer encdata;
 
     benc.append(data);
     benc.finalize();
@@ -294,10 +294,10 @@ void CryptoLogic::encBase64(SafeBuffer &data)
     data = std::move(encdata);
 }
 
-void CryptoLogic::decBase64(SafeBuffer &data)
+void CryptoLogic::decBase64(RawBuffer &data)
 {
     Base64Decoder bdec;
-    SafeBuffer decdata;
+    RawBuffer decdata;
 
     bdec.reset();
     bdec.append(data);
@@ -315,7 +315,7 @@ void CryptoLogic::decBase64(SafeBuffer &data)
     data = std::move(decdata);
 }
 
-bool CryptoLogic::equalDigests(SafeBuffer &dig1, SafeBuffer &dig2)
+bool CryptoLogic::equalDigests(RawBuffer &dig1, RawBuffer &dig2)
 {
     unsigned int dlen = Digest().length();
 
index 12aa0e1..00eed7f 100644 (file)
@@ -53,35 +53,35 @@ public:
 
     bool haveKey(const std::string &smackLabel);
     void pushKey(const std::string &smackLabel,
-                 const SafeBuffer &applicationKey);
+                 const RawBuffer &applicationKey);
 
 private:
        static const int ENCR_BASE64 =   1 << 0;
        static const int ENCR_APPKEY =   1 << 1;
        static const int ENCR_PASSWORD = 1 << 2;
 
-       std::map<std::string, SafeBuffer> m_keyMap;
+       std::map<std::string, RawBuffer> m_keyMap;
 
-    SafeBuffer generateRandIV() const;
-    SafeBuffer passwordToKey(const std::string &password,
-                            const SafeBuffer &salt,
+    RawBuffer generateRandIV() const;
+    RawBuffer passwordToKey(const std::string &password,
+                            const RawBuffer &salt,
                             size_t keySize) const;
 
-    SafeBuffer encryptData(
-        const SafeBuffer &data,
-        const SafeBuffer &key,
-        const SafeBuffer &iv) const;
+    RawBuffer encryptData(
+        const RawBuffer &data,
+        const RawBuffer &key,
+        const RawBuffer &iv) const;
 
-    SafeBuffer decryptData(
-        const SafeBuffer &data,
-        const SafeBuffer &key,
-        const SafeBuffer &iv) const;
+    RawBuffer decryptData(
+        const RawBuffer &data,
+        const RawBuffer &key,
+        const RawBuffer &iv) const;
 
-    void decBase64(SafeBuffer &data);
-    void encBase64(SafeBuffer &data);
-    bool equalDigests(SafeBuffer &dig1, SafeBuffer &dig2);
-    std::size_t insertDigest(SafeBuffer &data, const int dataSize);
-    void removeDigest(SafeBuffer &data, SafeBuffer &digest);
+    void decBase64(RawBuffer &data);
+    void encBase64(RawBuffer &data);
+    bool equalDigests(RawBuffer &dig1, RawBuffer &dig2);
+    std::size_t insertDigest(RawBuffer &data, const int dataSize);
+    void removeDigest(RawBuffer &data, RawBuffer &digest);
 };
 
 } // namespace CKM
index 984d5af..daced42 100644 (file)
@@ -25,8 +25,6 @@
 #include <dpl/log/log.h>
 #include <ckm/ckm-error.h>
 
-#include <buffer-conversion.h>
-
 #pragma GCC diagnostic push
 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
 
@@ -127,7 +125,7 @@ namespace {
 namespace CKM {
 using namespace DB;
     DBCrypto::DBCrypto(const std::string& path,
-                         const SafeBuffer &rawPass) {
+                         const RawBuffer &rawPass) {
         m_connection = NULL;
         m_inUserTransaction = false;
         Try {
@@ -436,7 +434,7 @@ using namespace DB;
 
     void DBCrypto::saveKey(
             const std::string& label,
-            const SafeBuffer &key)
+            const RawBuffer &key)
     {
         Try {
             Transaction transaction(this);
@@ -456,7 +454,7 @@ using namespace DB;
                 "Couldn't save key for label " << label);
     }
 
-    DBCrypto::SafeBufferOptional DBCrypto::getKey(
+    DBCrypto::RawBufferOptional DBCrypto::getKey(
             const std::string& label)
     {
         Try {
@@ -467,11 +465,11 @@ using namespace DB;
 
             if (selectCommand->Step()) {
                 transaction.commit();
-                return SafeBufferOptional(
+                return RawBufferOptional(
                         selectCommand->GetColumnBlob(0));
             } else {
                 transaction.commit();
-                return SafeBufferOptional();
+                return RawBufferOptional();
             }
 
         } Catch (SqlConnection::Exception::InvalidColumn) {
index 5a72c57..9ff5c10 100644 (file)
@@ -39,7 +39,7 @@ namespace CKM {
     class DBCrypto {
          public:
             typedef boost::optional<DBRow> DBRowOptional;
-            typedef boost::optional<SafeBuffer> SafeBufferOptional;
+            typedef boost::optional<RawBuffer> RawBufferOptional;
             class Exception
             {
               public:
@@ -53,7 +53,7 @@ namespace CKM {
                 m_inUserTransaction(false)
               {};
             //user name instead of path?
-            DBCrypto(const std::string &path, const SafeBuffer &rawPass);
+            DBCrypto(const std::string &path, const RawBuffer &rawPass);
             DBCrypto(const DBCrypto &other) = delete;
             DBCrypto(DBCrypto &&other);
 
@@ -81,8 +81,8 @@ namespace CKM {
                     const Alias& alias,
                     const std::string &label);
 
-            void saveKey(const std::string& label, const SafeBuffer &key);
-            SafeBufferOptional getKey(
+            void saveKey(const std::string& label, const RawBuffer &key);
+            RawBufferOptional getKey(
                     const std::string& label);
             void deleteKey(const std::string& label);
 
index 1de73a0..0a03e25 100644 (file)
@@ -2,8 +2,6 @@
 
 #include <string>
 
-#include <safe-buffer.h>
-
 #include <ckm/ckm-type.h>
 #include <protocols.h>
 
@@ -16,9 +14,9 @@ namespace CKM {
         DBDataType dataType;        // cert/key/data
         DBCMAlgType algorithmType;  // Algorithm type used for row data encryption
         int encryptionScheme;       // for example: (ENCR_BASE64 | ENCR_PASSWORD)
-        SafeBuffer iv;               // encoded in base64
+        RawBuffer iv;               // encoded in base64
         int dataSize;               // size of information without hash and padding
-        SafeBuffer data;
+        RawBuffer data;
     };
 } // namespace CKM
 
index 47a3b7e..c77da10 100644 (file)
@@ -28,9 +28,6 @@
 #include <sstream>
 #include <fstream>
 
-#include <safe-buffer.h>
-#include <buffer-conversion.h>
-
 #include <dpl/log/log.h>
 
 #include <file-system.h>
@@ -62,15 +59,18 @@ std::string FileSystem::getDKEKPath() const {
     return ss.str();
 }
 
-SafeBuffer FileSystem::getDomainKEK() const
+RawBuffer FileSystem::getDomainKEK() const
 {
     std::ifstream is(getDKEKPath());
     std::istreambuf_iterator<char> begin(is),end;
-    RawBuffer buffer(begin, end);
-    return toSafeBuffer(buffer);
+    std::vector<char> buff(begin,end); // This trick does not work with boost vector
+
+    RawBuffer buffer(buff.size());
+    memcpy(buffer.data(), buff.data(), buff.size());
+    return buffer;
 }
 
-bool FileSystem::saveDomainKEK(const SafeBuffer &buffer) const
+bool FileSystem::saveDomainKEK(const RawBuffer &buffer) const
 {
     std::ofstream os(getDKEKPath(), std::ios::out | std::ofstream::binary);
     std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator<char>(os));
index 847aa5e..197cc96 100644 (file)
@@ -31,8 +31,8 @@ public:
     FileSystem(uid_t uid);
 
     std::string getDBPath() const;
-    SafeBuffer getDomainKEK() const;
-    bool saveDomainKEK(const SafeBuffer &buffer) const;
+    RawBuffer getDomainKEK() const;
+    bool saveDomainKEK(const RawBuffer &buffer) const;
     int removeUserData() const;
 
     static int init();
index 77f5a3e..3c8285c 100644 (file)
@@ -1,7 +1,5 @@
 #pragma once
 
-#include <safe-buffer.h>
-
 #include <ckm-key-provider.h>
 #include <ckm/ckm-type.h>
 #include <dpl/exception.h>
@@ -54,7 +52,7 @@ public:
        // if (keyInWrapForm.size() != sizeof(WrappedKeyMaterial))
        //       throw exception; // buffer does not have proper size to store WrappedKeyMaterial
        // WrappedKeyMaterial *wkm = static_cast<WrappedKeyMaterial>(keyInWrapForm.data());
-       KeyProvider(const SafeBuffer &domainKEKInWrapForm, const std::string &password);
+       KeyProvider(const RawBuffer &domainKEKInWrapForm, const std::string &password);
 
        KeyProvider(KeyProvider &&);
        KeyProvider(const KeyProvider &) = delete;
@@ -64,31 +62,31 @@ public:
        bool isInitialized();
 
        // Returns Key used to decrypt database.
-       SafeBuffer getPureDomainKEK();
+       RawBuffer getPureDomainKEK();
 
        // Returns Key in form used to store key in file
-       // Requied by Control::resetPassword(const SafeBuffer &newPassword);
+       // Requied by Control::resetPassword(const RawBuffer &newPassword);
        // This api should be used only on Tizen 2.2.1
-       SafeBuffer getWrappedDomainKEK(const std::string &password);
+       RawBuffer getWrappedDomainKEK(const std::string &password);
 
        // EncryptedKey key extracted from database. Used to encrypt application data.
        // This key will be used to decrypt/encrypt data in ROW
-       SafeBuffer getPureDEK(const SafeBuffer &DEKInWrapForm);
+       RawBuffer getPureDEK(const RawBuffer &DEKInWrapForm);
 
        // Returns WRAPPED DEK. This will be written to datbase.
        // This key will be used to encrypt all application information.
        // All application are identified by smackLabel.
-       SafeBuffer generateDEK(const std::string &smackLabel);
+       RawBuffer generateDEK(const std::string &smackLabel);
 
        // used by change user password. On error -> exception
-       static SafeBuffer reencrypt(
-               const SafeBuffer &domainKEKInWrapForm,
+       static RawBuffer reencrypt(
+               const RawBuffer &domainKEKInWrapForm,
                const std::string &oldPass,
                const std::string &newPass);
 
        // First run of application for some user. DomainKEK was not created yet. We must create one.
        // This key will be used to encrypt user database.
-       static SafeBuffer generateDomainKEK(const std::string &user, const std::string &userPassword);
+       static RawBuffer generateDomainKEK(const std::string &user, const std::string &userPassword);
 
        // This will be called by framework at the begin of the program
        static int initializeLibrary();
index 814acb2..a12867f 100644 (file)
@@ -31,7 +31,7 @@
 
 namespace CKM {
 
-SafeBuffer OCSPLogic::ocspCheck(int commandId, const SafeBufferVector &rawChain) {
+RawBuffer OCSPLogic::ocspCheck(int commandId, const RawBufferVector &rawChain) {
     CertificateImplVector certChain;
     OCSPModule ocsp;
     int retCode = CKM_API_SUCCESS;
index dded072..f0dcab4 100644 (file)
@@ -33,7 +33,7 @@ public:
     OCSPLogic& operator=(const OCSPLogic &) = delete;
     OCSPLogic& operator=(OCSPLogic &&) = delete;
 
-    SafeBuffer ocspCheck(int commandId, const SafeBufferVector &rawChain);
+    RawBuffer ocspCheck(int commandId, const RawBufferVector &rawChain);
     virtual ~OCSPLogic(){}
 };
 
index 3e7f0c2..4a3884a 100644 (file)
@@ -83,11 +83,11 @@ bool OCSPService::processOne(
         auto &buffer = info.buffer;
 
         int commandId;
-        SafeBufferVector chainVector;
+        RawBufferVector chainVector;
         Deserialization::Deserialize(buffer, commandId);
         Deserialization::Deserialize(buffer, chainVector);
 
-        SafeBuffer response = m_logic->ocspCheck(commandId, chainVector);
+        RawBuffer response = m_logic->ocspCheck(commandId, chainVector);
         m_serviceManager->Write(conn, response);
 
         return true;
index 590907d..04c0d9c 100644 (file)
@@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(KeyDomainKEK){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(KeyDomainKekInvalidPassword){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_THROW(keyProvider = CKM::KeyProvider(rb_test, INCORRECT_PASSWORD),
@@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(KeygetPureDomainKEK){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, std::string(PASSWORD)));
@@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(KeyGetWrappedDomainKEK){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
@@ -92,8 +92,8 @@ BOOST_AUTO_TEST_CASE(KeyGenerateDEK){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_test;
-    CKM::SafeBuffer rb_DEK1;
+    CKM::RawBuffer rb_test;
+    CKM::RawBuffer rb_DEK1;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
@@ -106,9 +106,9 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_pureDEK1;
-    CKM::SafeBuffer rb_DEK1;
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_pureDEK1;
+    CKM::RawBuffer rb_DEK1;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
@@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK){
 BOOST_AUTO_TEST_CASE(KeyReencrypt){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(CKM::KeyProvider::reencrypt(rb_test, PASSWORD,
@@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(KeyReencrypt){
 BOOST_AUTO_TEST_CASE(KeyReencrypt_incorrect_password){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_THROW((rb_test = CKM::KeyProvider::reencrypt(rb_test, INCORRECT_PASSWORD,
@@ -142,8 +142,8 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK_after_reencrypt){
     BOOST_REQUIRE_MESSAGE(isLibInitialized,
             "Library is not initialized!");
     CKM::KeyProvider keyProvider;
-    CKM::SafeBuffer rb_DEK1;
-    CKM::SafeBuffer rb_test;
+    CKM::RawBuffer rb_DEK1;
+    CKM::RawBuffer rb_test;
     BOOST_REQUIRE_NO_THROW(rb_test =
             CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
     BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
index 999f608..f1727a3 100644 (file)
@@ -3,18 +3,27 @@
 
 using namespace CKM;
 
-SafeBuffer createDefaultPass() {
-    SafeBuffer raw;
+RawBuffer createDefaultPass() {
+    RawBuffer raw;
     for(unsigned char i =0; i < RAW_PASS_SIZE; i++)
         raw.push_back(i);
     return raw;
 }
 
-SafeBuffer createBigBlob(std::size_t size) {
-    SafeBuffer raw;
+RawBuffer createBigBlob(std::size_t size) {
+    RawBuffer raw;
     for(std::size_t i = 0; i < size; i++) {
         raw.push_back(static_cast<unsigned char>(i));
     }
     return raw;
 }
 
+//raw to hex string conversion from SqlConnection
+std::string rawToHexString(const RawBuffer &raw) {
+    std::string dump(raw.size()*2, '0');
+    for(std::size_t i = 0; i < raw.size(); i++){
+        sprintf(&dump[2*i], "%02x", raw[i]);
+    }
+    return dump;
+}
+
index 8f2b33e..681bd4d 100644 (file)
@@ -1,6 +1,5 @@
 #pragma once
 #include <string>
-#include <safe-buffer.h>
 #include <ckm/ckm-type.h>
 #include <boost/test/unit_test_log.hpp>
 #include <boost/test/results_reporter.hpp>
@@ -17,22 +16,15 @@ struct TestConfig {
 private:
 };
 
-CKM::SafeBuffer createDefaultPass();
-CKM::SafeBuffer createBigBlob(std::size_t size);
+CKM::RawBuffer createDefaultPass();
+CKM::RawBuffer createBigBlob(std::size_t size);
 
-const CKM::SafeBuffer defaultPass = createDefaultPass();
+const CKM::RawBuffer defaultPass = createDefaultPass();
 const std::string pattern =
     "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
 
 const std::size_t RAW_PASS_SIZE = 32;
 const std::size_t HEX_PASS_SIZE = RAW_PASS_SIZE * 2;
 
-template <class T>
-std::string rawToHexString(const T &raw) {
-    std::string dump(raw.size()*2, '0');
-    for(std::size_t i = 0; i < raw.size(); i++) {
-        sprintf(&dump[2*i], "%02x", static_cast<int>(raw[i]));
-    }
-    return dump;
-}
 
+std::string rawToHexString(const CKM::RawBuffer &raw);
index 215e691..4933e6a 100644 (file)
@@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(DBtestSimple) {
     BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass));
 
     DBRow rowPattern = createDefaultRow();
-    rowPattern.data = SafeBuffer(32, 1);
+    rowPattern.data = RawBuffer(32, 1);
     rowPattern.dataSize = rowPattern.data.size();
 
     checkDBIntegrity(rowPattern, db);
@@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(DBtestGlobal) {
     BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass));
 
     DBRow rowPattern = createDefaultRow(restricted_global);
-    rowPattern.data = SafeBuffer(1024, 2);
+    rowPattern.data = RawBuffer(1024, 2);
     rowPattern.dataSize = rowPattern.data.size();
 
     BOOST_REQUIRE_NO_THROW(db.saveDBRow(rowPattern));
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(DBtestTransaction) {
     BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass));
 
     DBRow rowPattern = createDefaultRow(0);
-    rowPattern.data = SafeBuffer(100, 20);
+    rowPattern.data = RawBuffer(100, 20);
     rowPattern.dataSize = rowPattern.data.size();
     DBCrypto::Transaction transaction(&db);
 
index d1f5f12..984504c 100644 (file)
@@ -25,7 +25,7 @@ const char *insert_table = "INSERT INTO t1(a,b) VALUES ("
                                        " 'two for the show');";
 const char *select_table = "SELECT * FROM t1";
 
-CKM::SafeBuffer raw_password = createDefaultPass();
+CKM::RawBuffer raw_password = createDefaultPass();
 
 BOOST_AUTO_TEST_SUITE(SQL_TEST)
 BOOST_AUTO_TEST_CASE(sqlTestConversion){
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(sqlTestSetKeyTooShort) {
     BOOST_CHECK(unlink(encrypt_me_not) == 0 || errno == ENOENT);
     SqlConnection connection(encrypt_me_not,
                                SqlConnection::Flag::CRW);
-    CKM::SafeBuffer wrong_key(RAW_PASS_SIZE - 1, 1);
+    CKM::RawBuffer wrong_key(RAW_PASS_SIZE - 1, 1);
     BOOST_REQUIRE_THROW(connection.SetKey(wrong_key),
             SqlConnection::Exception::InvalidArguments);
 }
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(sqlTestSetKeyTooLong) {
     BOOST_CHECK(unlink(encrypt_me_not) == 0 || errno == ENOENT);
     SqlConnection connection(encrypt_me_not,
                                SqlConnection::Flag::CRW);
-    CKM::SafeBuffer wrong_key(RAW_PASS_SIZE + 1, 1);
+    CKM::RawBuffer wrong_key(RAW_PASS_SIZE + 1, 1);
     BOOST_REQUIRE_THROW(connection.SetKey(wrong_key),
             SqlConnection::Exception::InvalidArguments);
 }
@@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(sqlTestConnectionEncryptedNegative) {
     {
         SqlConnection encrypting_you(encrypt_me,
                                      SqlConnection::Flag::RW);
-        CKM::SafeBuffer wrong_password;
+        CKM::RawBuffer wrong_password;
         for(std::size_t i = 0; i < RAW_PASS_SIZE; i++) {
             wrong_password.push_back(raw_password[i] + 1);
         }