Replace std::string with CKM::Password
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 24 Jul 2014 16:53:55 +0000 (18:53 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 12 Sep 2014 12:59:26 +0000 (14:59 +0200)
Change-Id: I695f3beb018d8a2b0a1fe4b17b99cd9cbd60c226

packaging/key-manager.spec
src/CMakeLists.txt
src/include/ckm/ckm-password.h [new file with mode: 0644]
src/include/ckm/ckm-type.h
src/manager/client-capi/ckmc-manager.cpp
src/manager/dpl/core/include/dpl/serialization.h
tests/test-key-provider.cpp

index 51a2b22..8c115aa 100755 (executable)
@@ -171,6 +171,7 @@ fi
 %{_includedir}/ckm/ckm/ckm-error.h
 %{_includedir}/ckm/ckm/ckm-echo.h
 %{_includedir}/ckm/ckm/ckm-key.h
+%{_includedir}/ckm/ckm/ckm-password.h
 %{_includedir}/ckm/ckm/ckm-raw-buffer.h
 %{_includedir}/ckm/ckm/ckm-type.h
 %{_includedir}/ckm/ckmc/ckmc-manager.h
index 625481e..526525b 100644 (file)
@@ -149,6 +149,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-password.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
diff --git a/src/include/ckm/ckm-password.h b/src/include/ckm/ckm-password.h
new file mode 100644 (file)
index 0000000..b12e218
--- /dev/null
@@ -0,0 +1,34 @@
+/* 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      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version     1.0
+ * @brief       Custom allocator for std
+ */
+
+#ifndef _SAFE_PASSWORD_H_
+#define _SAFE_PASSWORD_H_
+
+#include <ckm/ckm-raw-buffer.h>
+#include <boost/container/string.hpp>
+
+namespace CKM {
+
+typedef boost::container::basic_string<char, std::char_traits<char>, erase_on_dealloc<char>> Password;
+
+} // namespace CKM
+
+#endif //_ERASE_ON_DEALLOC_H_
index cc241d5..75a5338 100644 (file)
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include <ckm/ckm-raw-buffer.h>
+#include <ckm/ckm-password.h>
 
 namespace CKM {
 
@@ -32,7 +33,6 @@ namespace CKM {
 typedef std::vector<RawBuffer> RawBufferVector;
 typedef std::string Alias;
 typedef std::vector<Alias> AliasVector;
-typedef std::string Password;
 
 enum class KeyType : int {
     KEY_NONE,
index ddefbbd..d2a9de1 100644 (file)
 #include <iostream>
 #include <string.h>
 
-std::string _tostring(const char *str)
+CKM::Password _tostring(const char *str)
 {
        if(str == NULL)
-               return std::string();
-       return std::string(str);
+               return CKM::Password();
+       return CKM::Password(str);
 }
 
 CKM::CertificateShPtr _toCkmCertificate(const ckmc_cert_s *cert)
index 5140acf..4cda53e 100644 (file)
@@ -29,6 +29,8 @@
 #include <memory>
 
 #include <dpl/raw-buffer.h>
+// temporary fix for tizen 2.3
+#include <ckm/ckm-password.h>
 
 namespace CKM {
 // Abstract data stream buffer
@@ -139,6 +141,20 @@ struct Serialization {
         stream.Write(length, str->c_str());
     }
 
+    // Password
+    static void Serialize(IStream& stream, const Password& str)
+    {
+        int length = str.size();
+        stream.Write(sizeof(length), &length);
+        stream.Write(length, str.c_str());
+    }
+    static void Serialize(IStream& stream, const Password* const str)
+    {
+        int length = str->size();
+        stream.Write(sizeof(length), &length);
+        stream.Write(length, str->c_str());
+    }
+
     // STL templates
 
     // std::list
@@ -334,6 +350,28 @@ struct Deserialization {
         delete[] buf;
     }
 
+    // Password
+    static void Deserialize(IStream& stream, Password& str)
+    {
+        int length;
+        stream.Read(sizeof(length), &length);
+        char * buf = new char[length + 1];
+        stream.Read(length, buf);
+        buf[length] = 0;
+        str = Password(buf);
+        delete[] buf;
+    }
+    static void Deserialize(IStream& stream, Password*& str)
+    {
+        int length;
+        stream.Read(sizeof(length), &length);
+        char * buf = new char[length + 1];
+        stream.Read(length, buf);
+        buf[length] = 0;
+        str = new Password(buf);
+        delete[] buf;
+    }
+
     // STL templates
 
     // std::list
index 04c0d9c..3058e69 100644 (file)
@@ -4,9 +4,9 @@
 #include <test_common.h>
 #include <iostream>
 
-const std::string PASSWORD = "12345TIZEN12345AAAAAAAAA";
-const std::string INCORRECT_PASSWORD = "AAAAAAAAAAAAAAAAAAAAA";
-const std::string NEW_PASSWORD = "NEW12345TIZEN12345NEW";
+const CKM::Password PASSWORD = "12345TIZEN12345AAAAAAAAA";
+const CKM::Password INCORRECT_PASSWORD = "AAAAAAAAAAAAAAAAAAAAA";
+const CKM::Password NEW_PASSWORD = "NEW12345TIZEN12345NEW";
 
 const std::string USERNAME_SHORT = "AB";
 const std::string USERNAME_LONG = "SOFTWARE_CENTER_SYSTEM_SW_LAB_SECURITY_PART";
@@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(KeygetPureDomainKEK){
     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)));
+    BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
     BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
             "KeyProvider created, but uninitialized");
     BOOST_REQUIRE_NO_THROW(rb_test = keyProvider.getPureDomainKEK());